]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/20_util/function/5.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 20_util / function / 5.cc
CommitLineData
52066eae 1// { dg-do run { target c++11 } }
7cc9022f
AA
2// { dg-require-effective-target hosted }
3
7aec2c63
PC
4// 2005-01-15 Douglas Gregor <dgregor@cs.indiana.edu>
5//
83ffe9cd 6// Copyright (C) 2005-2023 Free Software Foundation, Inc.
7aec2c63
PC
7//
8// This file is part of the GNU ISO C++ Library. This library is free
9// software; you can redistribute it and/or modify it under the
10// terms of the GNU General Public License as published by the
11// Free Software Foundation; either version 3, or (at your option)
12// any later version.
13//
14// This library is distributed in the hope that it will be useful,
15// but WITHOUT ANY WARRANTY; without even the implied warranty of
16// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17// GNU General Public License for more details.
18//
19// You should have received a copy of the GNU General Public License along
20// with this library; see the file COPYING3. If not see
21// <http://www.gnu.org/licenses/>.
22
23// 20.7.15 polymorphic function object wrapper
24#include <functional>
25#include <testsuite_hooks.h>
26#include <testsuite_tr1.h>
27
28using namespace __gnu_test;
29
7aec2c63
PC
30// Put member pointers into function<> wrappers
31void 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 );
b6b66006 41#if __cpp_rtti
7aec2c63 42 VERIFY( typeid(int X::*) == frm.target_type() );
b6b66006 43#endif
7aec2c63
PC
44 VERIFY( *frm.target<int X::*>() == &X::bar );
45
46 function<int(X&)> fr(&X::foo);
47 VERIFY( fr );
48 VERIFY( fr(x) == 1 );
b6b66006 49#if __cpp_rtti
7aec2c63 50 VERIFY( typeid(int (X::*)()) == fr.target_type() );
b6b66006 51#endif
7aec2c63
PC
52 VERIFY( *fr.target<int (X::*)()>() == &X::foo );
53
54 function<int(const X&)> frc(&X::foo_c);
55 VERIFY( frc );
56 VERIFY( frc(x) == 2 );
b6b66006 57#if __cpp_rtti
7aec2c63 58 VERIFY( typeid(int (X::*)() const) == frc.target_type() );
b6b66006 59#endif
7aec2c63
PC
60 VERIFY( *frc.target<int (X::*)() const >() == &X::foo_c );
61
62 function<int(volatile X&)> frv(&X::foo_v);
63 VERIFY( frv );
64 VERIFY( frv(x) == 3 );
b6b66006 65#if __cpp_rtti
7aec2c63 66 VERIFY( typeid(int (X::*)() volatile) == frv.target_type() );
b6b66006 67#endif
7aec2c63
PC
68 VERIFY( *frv.target<int (X::*)() volatile >() == &X::foo_v );
69 VERIFY( frv.target<int (X::*)() const volatile>() == 0 );
70
71 function<int(const volatile X&)> frcv(&X::foo_cv);
72 VERIFY( frcv );
73 VERIFY( frcv(x) == 4 );
b6b66006 74#if __cpp_rtti
7aec2c63 75 VERIFY( typeid(int (X::*)() const volatile) == frcv.target_type() );
b6b66006 76#endif
7aec2c63
PC
77 VERIFY( *frcv.target<int (X::*)() const volatile >() == &X::foo_cv );
78 VERIFY( frcv.target<int (X::*)() const>() == 0 );
79
80 function<int(X*)> grm(&X::bar);
81 VERIFY( grm );
82 VERIFY( grm(&x) == 17 );
b6b66006 83#if __cpp_rtti
7aec2c63 84 VERIFY( typeid(int X::*) == grm.target_type() );
b6b66006 85#endif
7aec2c63
PC
86 VERIFY( *grm.target<int X::*>() == &X::bar );
87
88 function<int(X*)> gr(&X::foo);
89 VERIFY( gr );
90 VERIFY( gr(&x) == 1 );
b6b66006 91#if __cpp_rtti
7aec2c63 92 VERIFY( typeid(int (X::*)()) == gr.target_type() );
b6b66006 93#endif
7aec2c63
PC
94 VERIFY( *gr.target<int (X::*)()>() == &X::foo );
95
96 function<int(const X*)> grc(&X::foo_c);
97 VERIFY( grc );
98 VERIFY( grc(&x) == 2 );
b6b66006 99#if __cpp_rtti
7aec2c63 100 VERIFY( typeid(int (X::*)() const) == grc.target_type() );
b6b66006 101#endif
7aec2c63
PC
102 VERIFY( *grc.target<int (X::*)() const >() == &X::foo_c );
103
104 function<int(volatile X*)> grv(&X::foo_v);
105 VERIFY( grv );
106 VERIFY( grv(&x) == 3 );
b6b66006 107#if __cpp_rtti
7aec2c63 108 VERIFY( typeid(int (X::*)() volatile) == grv.target_type() );
b6b66006 109#endif
7aec2c63
PC
110 VERIFY( *grv.target<int (X::*)() volatile >() == &X::foo_v );
111 VERIFY( grv.target<int (X::*)() const volatile>() == 0 );
112
113 function<int(const volatile X*)> grcv(&X::foo_cv);
114 VERIFY( grcv );
115 VERIFY( grcv(&x) == 4 );
b6b66006 116#if __cpp_rtti
7aec2c63 117 VERIFY( typeid(int (X::*)() const volatile) == grcv.target_type() );
b6b66006 118#endif
7aec2c63
PC
119 VERIFY( *grcv.target<int (X::*)() const volatile >() == &X::foo_cv );
120 VERIFY( grcv.target<int (X::*)() const>() == 0 );
121}
122
123int main()
124{
125 test05();
126 return 0;
127}