]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/experimental/functional/not_fn.cc
1 // Copyright (C) 2014-2016 Free Software Foundation, Inc.
3 // This file is part of the GNU ISO C++ Library. This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 3, or (at your option)
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING3. If not see
16 // <http://www.gnu.org/licenses/>.
18 // { dg-options "-std=gnu++14" }
20 #include <experimental/functional>
21 #include <testsuite_hooks.h>
23 using std::experimental::not_fn
;
25 int func(int, char) { return 0; }
29 bool operator()() { return false; }
30 bool operator()() const { return true; }
31 bool operator()(int) { return false; }
32 bool operator()(int) volatile { return true; }
38 auto f1
= not_fn(func
);
39 VERIFY( f1(1, '2') == true );
41 auto f2
= not_fn( [] { return true; } );
42 VERIFY( f2() == false );
44 auto f3
= not_fn( F
{} );
45 VERIFY( f3() == true );
46 VERIFY( f3(1) == true );
48 VERIFY( f4() == false );
49 volatile auto f5
= f3
;
50 VERIFY( f5(1) == false );
53 template<typename F
, typename Arg
>
54 auto foo(F f
, Arg arg
) -> decltype(not_fn(f
)(arg
)) { return not_fn(f
)(arg
); }
56 template<typename F
, typename Arg
>
57 auto foo(F f
, Arg arg
) -> decltype(not_fn(f
)()) { return not_fn(f
)(); }
61 bool operator()(int) const { return false; }
62 void operator()() const {}
68 foo(negator
{}, 1); // PR libstdc++/66998
76 VERIFY( not_fn(&X::b
)(x
) );