]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/20_util/function/5.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 20_util / function / 5.cc
1 // { dg-do run { target c++11 } }
2 // 2005-01-15 Douglas Gregor <dgregor@cs.indiana.edu>
3 //
4 // Copyright (C) 2005-2019 Free Software Foundation, Inc.
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 // 20.7.15 polymorphic function object wrapper
22 #include <functional>
23 #include <testsuite_hooks.h>
24 #include <testsuite_tr1.h>
25
26 using namespace __gnu_test;
27
28 // Put member pointers into function<> wrappers
29 void test05()
30 {
31 using std::function;
32
33 X x;
34 x.bar = 17;
35
36 function<int(X&)> frm(&X::bar);
37 VERIFY( frm );
38 VERIFY( frm(x) == 17 );
39 VERIFY( typeid(int X::*) == frm.target_type() );
40 VERIFY( *frm.target<int X::*>() == &X::bar );
41
42 function<int(X&)> fr(&X::foo);
43 VERIFY( fr );
44 VERIFY( fr(x) == 1 );
45 VERIFY( typeid(int (X::*)()) == fr.target_type() );
46 VERIFY( *fr.target<int (X::*)()>() == &X::foo );
47
48 function<int(const X&)> frc(&X::foo_c);
49 VERIFY( frc );
50 VERIFY( frc(x) == 2 );
51 VERIFY( typeid(int (X::*)() const) == frc.target_type() );
52 VERIFY( *frc.target<int (X::*)() const >() == &X::foo_c );
53
54 function<int(volatile X&)> frv(&X::foo_v);
55 VERIFY( frv );
56 VERIFY( frv(x) == 3 );
57 VERIFY( typeid(int (X::*)() volatile) == frv.target_type() );
58 VERIFY( *frv.target<int (X::*)() volatile >() == &X::foo_v );
59 VERIFY( frv.target<int (X::*)() const volatile>() == 0 );
60
61 function<int(const volatile X&)> frcv(&X::foo_cv);
62 VERIFY( frcv );
63 VERIFY( frcv(x) == 4 );
64 VERIFY( typeid(int (X::*)() const volatile) == frcv.target_type() );
65 VERIFY( *frcv.target<int (X::*)() const volatile >() == &X::foo_cv );
66 VERIFY( frcv.target<int (X::*)() const>() == 0 );
67
68 function<int(X*)> grm(&X::bar);
69 VERIFY( grm );
70 VERIFY( grm(&x) == 17 );
71 VERIFY( typeid(int X::*) == grm.target_type() );
72 VERIFY( *grm.target<int X::*>() == &X::bar );
73
74 function<int(X*)> gr(&X::foo);
75 VERIFY( gr );
76 VERIFY( gr(&x) == 1 );
77 VERIFY( typeid(int (X::*)()) == gr.target_type() );
78 VERIFY( *gr.target<int (X::*)()>() == &X::foo );
79
80 function<int(const X*)> grc(&X::foo_c);
81 VERIFY( grc );
82 VERIFY( grc(&x) == 2 );
83 VERIFY( typeid(int (X::*)() const) == grc.target_type() );
84 VERIFY( *grc.target<int (X::*)() const >() == &X::foo_c );
85
86 function<int(volatile X*)> grv(&X::foo_v);
87 VERIFY( grv );
88 VERIFY( grv(&x) == 3 );
89 VERIFY( typeid(int (X::*)() volatile) == grv.target_type() );
90 VERIFY( *grv.target<int (X::*)() volatile >() == &X::foo_v );
91 VERIFY( grv.target<int (X::*)() const volatile>() == 0 );
92
93 function<int(const volatile X*)> grcv(&X::foo_cv);
94 VERIFY( grcv );
95 VERIFY( grcv(&x) == 4 );
96 VERIFY( typeid(int (X::*)() const volatile) == grcv.target_type() );
97 VERIFY( *grcv.target<int (X::*)() const volatile >() == &X::foo_cv );
98 VERIFY( grcv.target<int (X::*)() const>() == 0 );
99 }
100
101 int main()
102 {
103 test05();
104 return 0;
105 }