]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/20_util/function/5.cc
re PR c++/59378 (Internal compiler error when using __builtin_shuffle in a template...
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 20_util / function / 5.cc
1 // { dg-options "-std=gnu++0x" }
2 // 2005-01-15 Douglas Gregor <dgregor@cs.indiana.edu>
3 //
4 // Copyright (C) 2005-2013 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 bool test __attribute__((unused)) = true;
29
30 // Put member pointers into function<> wrappers
31 void test05()
32 {
33 using std::function;
34
35 X x;
36 x.bar = 17;
37
38 function<int(X&)> frm(&X::bar);
39 VERIFY( frm );
40 VERIFY( frm(x) == 17 );
41 VERIFY( typeid(int X::*) == frm.target_type() );
42 VERIFY( *frm.target<int X::*>() == &X::bar );
43
44 function<int(X&)> fr(&X::foo);
45 VERIFY( fr );
46 VERIFY( fr(x) == 1 );
47 VERIFY( typeid(int (X::*)()) == fr.target_type() );
48 VERIFY( *fr.target<int (X::*)()>() == &X::foo );
49
50 function<int(const X&)> frc(&X::foo_c);
51 VERIFY( frc );
52 VERIFY( frc(x) == 2 );
53 VERIFY( typeid(int (X::*)() const) == frc.target_type() );
54 VERIFY( *frc.target<int (X::*)() const >() == &X::foo_c );
55
56 function<int(volatile X&)> frv(&X::foo_v);
57 VERIFY( frv );
58 VERIFY( frv(x) == 3 );
59 VERIFY( typeid(int (X::*)() volatile) == frv.target_type() );
60 VERIFY( *frv.target<int (X::*)() volatile >() == &X::foo_v );
61 VERIFY( frv.target<int (X::*)() const volatile>() == 0 );
62
63 function<int(const volatile X&)> frcv(&X::foo_cv);
64 VERIFY( frcv );
65 VERIFY( frcv(x) == 4 );
66 VERIFY( typeid(int (X::*)() const volatile) == frcv.target_type() );
67 VERIFY( *frcv.target<int (X::*)() const volatile >() == &X::foo_cv );
68 VERIFY( frcv.target<int (X::*)() const>() == 0 );
69
70 function<int(X*)> grm(&X::bar);
71 VERIFY( grm );
72 VERIFY( grm(&x) == 17 );
73 VERIFY( typeid(int X::*) == grm.target_type() );
74 VERIFY( *grm.target<int X::*>() == &X::bar );
75
76 function<int(X*)> gr(&X::foo);
77 VERIFY( gr );
78 VERIFY( gr(&x) == 1 );
79 VERIFY( typeid(int (X::*)()) == gr.target_type() );
80 VERIFY( *gr.target<int (X::*)()>() == &X::foo );
81
82 function<int(const X*)> grc(&X::foo_c);
83 VERIFY( grc );
84 VERIFY( grc(&x) == 2 );
85 VERIFY( typeid(int (X::*)() const) == grc.target_type() );
86 VERIFY( *grc.target<int (X::*)() const >() == &X::foo_c );
87
88 function<int(volatile X*)> grv(&X::foo_v);
89 VERIFY( grv );
90 VERIFY( grv(&x) == 3 );
91 VERIFY( typeid(int (X::*)() volatile) == grv.target_type() );
92 VERIFY( *grv.target<int (X::*)() volatile >() == &X::foo_v );
93 VERIFY( grv.target<int (X::*)() const volatile>() == 0 );
94
95 function<int(const volatile X*)> grcv(&X::foo_cv);
96 VERIFY( grcv );
97 VERIFY( grcv(&x) == 4 );
98 VERIFY( typeid(int (X::*)() const volatile) == grcv.target_type() );
99 VERIFY( *grcv.target<int (X::*)() const volatile >() == &X::foo_cv );
100 VERIFY( grcv.target<int (X::*)() const>() == 0 );
101 }
102
103 int main()
104 {
105 test05();
106 return 0;
107 }