]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/tr1/3_function_objects/function/5.cc
Update copyright years in libstdc++-v3/
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / tr1 / 3_function_objects / function / 5.cc
CommitLineData
0179f2c6
DG
1// 2005-01-15 Douglas Gregor <dgregor@cs.indiana.edu>
2//
aa118a03 3// Copyright (C) 2005-2014 Free Software Foundation, Inc.
0179f2c6
DG
4//
5// This file is part of the GNU ISO C++ Library. This library is free
6// software; you can redistribute it and/or modify it under the
7// terms of the GNU General Public License as published by the
748086b7 8// Free Software Foundation; either version 3, or (at your option)
0179f2c6
DG
9// any later version.
10//
11// This library is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details.
15//
16// You should have received a copy of the GNU General Public License along
748086b7
JJ
17// with this library; see the file COPYING3. If not see
18// <http://www.gnu.org/licenses/>.
0179f2c6
DG
19
20// 3.7.2 polymorphic function object wrapper
21#include <tr1/functional>
22#include <testsuite_hooks.h>
23#include <testsuite_tr1.h>
24
25using namespace __gnu_test;
26
27bool test __attribute__((unused)) = true;
28
29// Put member pointers into function<> wrappers
30void test05()
31{
32 using std::tr1::function;
33
34 X x;
35 x.bar = 17;
36
37 function<int(X&)> frm(&X::bar);
38 VERIFY( frm );
39 VERIFY( frm(x) == 17 );
40 VERIFY( typeid(int X::*) == frm.target_type() );
41 VERIFY( *frm.target<int X::*>() == &X::bar );
42
43 function<int(X&)> fr(&X::foo);
44 VERIFY( fr );
45 VERIFY( fr(x) == 1 );
46 VERIFY( typeid(int (X::*)()) == fr.target_type() );
47 VERIFY( *fr.target<int (X::*)()>() == &X::foo );
48
49 function<int(const X&)> frc(&X::foo_c);
50 VERIFY( frc );
51 VERIFY( frc(x) == 2 );
52 VERIFY( typeid(int (X::*)() const) == frc.target_type() );
53 VERIFY( *frc.target<int (X::*)() const >() == &X::foo_c );
54
55 function<int(volatile X&)> frv(&X::foo_v);
56 VERIFY( frv );
57 VERIFY( frv(x) == 3 );
58 VERIFY( typeid(int (X::*)() volatile) == frv.target_type() );
59 VERIFY( *frv.target<int (X::*)() volatile >() == &X::foo_v );
60 VERIFY( frv.target<int (X::*)() const volatile>() == 0 );
61
62 function<int(const volatile X&)> frcv(&X::foo_cv);
63 VERIFY( frcv );
64 VERIFY( frcv(x) == 4 );
65 VERIFY( typeid(int (X::*)() const volatile) == frcv.target_type() );
66 VERIFY( *frcv.target<int (X::*)() const volatile >() == &X::foo_cv );
67 VERIFY( frcv.target<int (X::*)() const>() == 0 );
68
69 function<int(X*)> grm(&X::bar);
70 VERIFY( grm );
71 VERIFY( grm(&x) == 17 );
72 VERIFY( typeid(int X::*) == grm.target_type() );
73 VERIFY( *grm.target<int X::*>() == &X::bar );
74
75 function<int(X*)> gr(&X::foo);
76 VERIFY( gr );
77 VERIFY( gr(&x) == 1 );
78 VERIFY( typeid(int (X::*)()) == gr.target_type() );
79 VERIFY( *gr.target<int (X::*)()>() == &X::foo );
80
81 function<int(const X*)> grc(&X::foo_c);
82 VERIFY( grc );
83 VERIFY( grc(&x) == 2 );
84 VERIFY( typeid(int (X::*)() const) == grc.target_type() );
85 VERIFY( *grc.target<int (X::*)() const >() == &X::foo_c );
86
87 function<int(volatile X*)> grv(&X::foo_v);
88 VERIFY( grv );
89 VERIFY( grv(&x) == 3 );
90 VERIFY( typeid(int (X::*)() volatile) == grv.target_type() );
91 VERIFY( *grv.target<int (X::*)() volatile >() == &X::foo_v );
92 VERIFY( grv.target<int (X::*)() const volatile>() == 0 );
93
94 function<int(const volatile X*)> grcv(&X::foo_cv);
95 VERIFY( grcv );
96 VERIFY( grcv(&x) == 4 );
97 VERIFY( typeid(int (X::*)() const volatile) == grcv.target_type() );
98 VERIFY( *grcv.target<int (X::*)() const volatile >() == &X::foo_cv );
99 VERIFY( grcv.target<int (X::*)() const>() == 0 );
100}
101
102int main()
103{
104 test05();
105 return 0;
106}