]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/experimental/functional/not_fn.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / experimental / functional / not_fn.cc
1 // Copyright (C) 2014-2016 Free Software Foundation, Inc.
2 //
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)
7 // any later version.
8
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.
13
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/>.
17
18 // { dg-options "-std=gnu++14" }
19
20 #include <experimental/functional>
21 #include <testsuite_hooks.h>
22
23 using std::experimental::not_fn;
24
25 int func(int, char) { return 0; }
26
27 struct F
28 {
29 bool operator()() { return false; }
30 bool operator()() const { return true; }
31 bool operator()(int) { return false; }
32 bool operator()(int) volatile { return true; }
33 };
34
35 void
36 test01()
37 {
38 auto f1 = not_fn(func);
39 VERIFY( f1(1, '2') == true );
40
41 auto f2 = not_fn( [] { return true; } );
42 VERIFY( f2() == false );
43
44 auto f3 = not_fn( F{} );
45 VERIFY( f3() == true );
46 VERIFY( f3(1) == true );
47 const auto f4 = f3;
48 VERIFY( f4() == false );
49 volatile auto f5 = f3;
50 VERIFY( f5(1) == false );
51 }
52
53 template<typename F, typename Arg>
54 auto foo(F f, Arg arg) -> decltype(not_fn(f)(arg)) { return not_fn(f)(arg); }
55
56 template<typename F, typename Arg>
57 auto foo(F f, Arg arg) -> decltype(not_fn(f)()) { return not_fn(f)(); }
58
59 struct negator
60 {
61 bool operator()(int) const { return false; }
62 void operator()() const {}
63 };
64
65 void
66 test02()
67 {
68 foo(negator{}, 1); // PR libstdc++/66998
69 }
70
71 void
72 test03()
73 {
74 struct X { bool b; };
75 X x{ false };
76 VERIFY( not_fn(&X::b)(x) );
77 }
78
79 int
80 main()
81 {
82 test01();
83 test02();
84 test03();
85 }