]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/20_util/result_of/sfinae_friendly_2.cc
1 // { dg-options "-std=gnu++11" }
4 // Copyright (C) 2012-2015 Free Software Foundation, Inc.
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)
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.
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/>.
23 #include <type_traits>
26 struct eat
{ template<typename T
> eat(T
const &) {} };
27 struct not_incrementable
{};
31 auto operator()(T t
) const -> decltype(t
++)
36 typename
std::result_of
<inc(A
)>::type
// sfinae here
43 return not_incrementable();
47 struct never
{ static const bool value
= false; };
52 static_assert(never
<T
>::value
, "duh");
59 typename Fail
<T
>::type
operator()(T
)
64 typename
std::result_of
<Fun(T
)>::type
foo(T
)
71 void result_of_sfinae() {
72 int x
= try_inc(1); // OK
73 not_incrementable y
= try_inc(std::string("foo")); // OK, not_incrementable