]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/20_util/result_of/sfinae_friendly_2.cc
Update copyright years in libstdc++-v3/
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 20_util / result_of / sfinae_friendly_2.cc
CommitLineData
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 26struct eat { template<typename T> eat(T const &) {} };
83ddb39f
DK
27struct not_incrementable {};
28
29struct inc {
b3618b71 30 template<typename T>
83ddb39f
DK
31 auto operator()(T t) const -> decltype(t++)
32 { return t++; }
33};
34
b3618b71 35template<typename A>
83ddb39f
DK
36typename std::result_of<inc(A)>::type // sfinae here
37try_inc(A a) {
38 return inc()(a);
39}
40
41not_incrementable
42try_inc(eat) {
43 return not_incrementable();
44}
45
b3618b71 46template<typename>
83ddb39f
DK
47struct never { static const bool value = false; };
48
b3618b71 49template<typename T>
83ddb39f
DK
50struct Fail
51{
52 static_assert(never<T>::value, "duh");
53 typedef int type;
54};
55
56struct Fun
57{
b3618b71 58 template<typename T>
83ddb39f
DK
59 typename Fail<T>::type operator()(T)
60 { return 0; }
61};
62
b3618b71 63template<typename T>
83ddb39f
DK
64typename std::result_of<Fun(T)>::type foo(T)
65{ return 0; }
66
b3618b71 67template<typename>
83ddb39f
DK
68int foo(...)
69{ return 0; }
70
71void 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}