]>
Commit | Line | Data |
---|---|---|
83ddb39f DK |
1 | // { dg-options "-std=gnu++11" } |
2 | // { dg-do compile } | |
3 | ||
aa118a03 | 4 | // Copyright (C) 2012-2014 Free Software Foundation, Inc. |
83ddb39f DK |
5 | // |
6 | // This file is part of the GNU ISO C++ Library. This library is free | |
7 | // software; you can redistribute it and/or modify it under the | |
8 | // terms of the GNU General Public License as published by the | |
9 | // Free Software Foundation; either version 3, or (at your option) | |
10 | // any later version. | |
11 | ||
12 | // This library is distributed in the hope that it will be useful, | |
13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | // GNU General Public License for more details. | |
16 | ||
17 | // You should have received a copy of the GNU General Public License along | |
18 | // with this library; see the file COPYING3. If not see | |
19 | // <http://www.gnu.org/licenses/>. | |
20 | ||
21 | // Taken from N3436: | |
22 | ||
23 | #include <type_traits> | |
24 | #include <string> | |
25 | ||
b3618b71 | 26 | struct eat { template<typename T> eat(T const &) {} }; |
83ddb39f DK |
27 | struct not_incrementable {}; |
28 | ||
29 | struct inc { | |
b3618b71 | 30 | template<typename T> |
83ddb39f DK |
31 | auto operator()(T t) const -> decltype(t++) |
32 | { return t++; } | |
33 | }; | |
34 | ||
b3618b71 | 35 | template<typename A> |
83ddb39f DK |
36 | typename std::result_of<inc(A)>::type // sfinae here |
37 | try_inc(A a) { | |
38 | return inc()(a); | |
39 | } | |
40 | ||
41 | not_incrementable | |
42 | try_inc(eat) { | |
43 | return not_incrementable(); | |
44 | } | |
45 | ||
b3618b71 | 46 | template<typename> |
83ddb39f DK |
47 | struct never { static const bool value = false; }; |
48 | ||
b3618b71 | 49 | template<typename T> |
83ddb39f DK |
50 | struct Fail |
51 | { | |
52 | static_assert(never<T>::value, "duh"); | |
53 | typedef int type; | |
54 | }; | |
55 | ||
56 | struct Fun | |
57 | { | |
b3618b71 | 58 | template<typename T> |
83ddb39f DK |
59 | typename Fail<T>::type operator()(T) |
60 | { return 0; } | |
61 | }; | |
62 | ||
b3618b71 | 63 | template<typename T> |
83ddb39f DK |
64 | typename std::result_of<Fun(T)>::type foo(T) |
65 | { return 0; } | |
66 | ||
b3618b71 | 67 | template<typename> |
83ddb39f DK |
68 | int foo(...) |
69 | { return 0; } | |
70 | ||
71 | void result_of_sfinae() { | |
72 | int x = try_inc(1); // OK | |
73 | not_incrementable y = try_inc(std::string("foo")); // OK, not_incrementable | |
74 | (void) x; | |
75 | (void) y; | |
76 | } |