]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/20_util/function/5.cc
libstdc++: Enable std::bitset<N>::bitset(const char*) for freestanding
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 20_util / function / 5.cc
CommitLineData
52066eae 1// { dg-do run { target c++11 } }
7aec2c63
PC
2// 2005-01-15 Douglas Gregor <dgregor@cs.indiana.edu>
3//
7adcbafe 4// Copyright (C) 2005-2022 Free Software Foundation, Inc.
7aec2c63
PC
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
26using namespace __gnu_test;
27
7aec2c63
PC
28// Put member pointers into function<> wrappers
29void 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 );
b6b66006 39#if __cpp_rtti
7aec2c63 40 VERIFY( typeid(int X::*) == frm.target_type() );
b6b66006 41#endif
7aec2c63
PC
42 VERIFY( *frm.target<int X::*>() == &X::bar );
43
44 function<int(X&)> fr(&X::foo);
45 VERIFY( fr );
46 VERIFY( fr(x) == 1 );
b6b66006 47#if __cpp_rtti
7aec2c63 48 VERIFY( typeid(int (X::*)()) == fr.target_type() );
b6b66006 49#endif
7aec2c63
PC
50 VERIFY( *fr.target<int (X::*)()>() == &X::foo );
51
52 function<int(const X&)> frc(&X::foo_c);
53 VERIFY( frc );
54 VERIFY( frc(x) == 2 );
b6b66006 55#if __cpp_rtti
7aec2c63 56 VERIFY( typeid(int (X::*)() const) == frc.target_type() );
b6b66006 57#endif
7aec2c63
PC
58 VERIFY( *frc.target<int (X::*)() const >() == &X::foo_c );
59
60 function<int(volatile X&)> frv(&X::foo_v);
61 VERIFY( frv );
62 VERIFY( frv(x) == 3 );
b6b66006 63#if __cpp_rtti
7aec2c63 64 VERIFY( typeid(int (X::*)() volatile) == frv.target_type() );
b6b66006 65#endif
7aec2c63
PC
66 VERIFY( *frv.target<int (X::*)() volatile >() == &X::foo_v );
67 VERIFY( frv.target<int (X::*)() const volatile>() == 0 );
68
69 function<int(const volatile X&)> frcv(&X::foo_cv);
70 VERIFY( frcv );
71 VERIFY( frcv(x) == 4 );
b6b66006 72#if __cpp_rtti
7aec2c63 73 VERIFY( typeid(int (X::*)() const volatile) == frcv.target_type() );
b6b66006 74#endif
7aec2c63
PC
75 VERIFY( *frcv.target<int (X::*)() const volatile >() == &X::foo_cv );
76 VERIFY( frcv.target<int (X::*)() const>() == 0 );
77
78 function<int(X*)> grm(&X::bar);
79 VERIFY( grm );
80 VERIFY( grm(&x) == 17 );
b6b66006 81#if __cpp_rtti
7aec2c63 82 VERIFY( typeid(int X::*) == grm.target_type() );
b6b66006 83#endif
7aec2c63
PC
84 VERIFY( *grm.target<int X::*>() == &X::bar );
85
86 function<int(X*)> gr(&X::foo);
87 VERIFY( gr );
88 VERIFY( gr(&x) == 1 );
b6b66006 89#if __cpp_rtti
7aec2c63 90 VERIFY( typeid(int (X::*)()) == gr.target_type() );
b6b66006 91#endif
7aec2c63
PC
92 VERIFY( *gr.target<int (X::*)()>() == &X::foo );
93
94 function<int(const X*)> grc(&X::foo_c);
95 VERIFY( grc );
96 VERIFY( grc(&x) == 2 );
b6b66006 97#if __cpp_rtti
7aec2c63 98 VERIFY( typeid(int (X::*)() const) == grc.target_type() );
b6b66006 99#endif
7aec2c63
PC
100 VERIFY( *grc.target<int (X::*)() const >() == &X::foo_c );
101
102 function<int(volatile X*)> grv(&X::foo_v);
103 VERIFY( grv );
104 VERIFY( grv(&x) == 3 );
b6b66006 105#if __cpp_rtti
7aec2c63 106 VERIFY( typeid(int (X::*)() volatile) == grv.target_type() );
b6b66006 107#endif
7aec2c63
PC
108 VERIFY( *grv.target<int (X::*)() volatile >() == &X::foo_v );
109 VERIFY( grv.target<int (X::*)() const volatile>() == 0 );
110
111 function<int(const volatile X*)> grcv(&X::foo_cv);
112 VERIFY( grcv );
113 VERIFY( grcv(&x) == 4 );
b6b66006 114#if __cpp_rtti
7aec2c63 115 VERIFY( typeid(int (X::*)() const volatile) == grcv.target_type() );
b6b66006 116#endif
7aec2c63
PC
117 VERIFY( *grcv.target<int (X::*)() const volatile >() == &X::foo_cv );
118 VERIFY( grcv.target<int (X::*)() const>() == 0 );
119}
120
121int main()
122{
123 test05();
124 return 0;
125}