]>
git.ipfire.org Git - thirdparty/gcc.git/blob - 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>
4 // Copyright (C) 2005-2019 Free Software Foundation, Inc.
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)
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.
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/>.
21 // 20.7.15 polymorphic function object wrapper
23 #include <testsuite_hooks.h>
24 #include <testsuite_tr1.h>
26 using namespace __gnu_test
;
28 // Put member pointers into function<> wrappers
36 function
<int(X
&)> frm(&X::bar
);
38 VERIFY( frm(x
) == 17 );
39 VERIFY( typeid(int X::*) == frm
.target_type() );
40 VERIFY( *frm
.target
<int X::*>() == &X::bar
);
42 function
<int(X
&)> fr(&X::foo
);
45 VERIFY( typeid(int (X::*)()) == fr
.target_type() );
46 VERIFY( *fr
.target
<int (X::*)()>() == &X::foo
);
48 function
<int(const X
&)> frc(&X::foo_c
);
50 VERIFY( frc(x
) == 2 );
51 VERIFY( typeid(int (X::*)() const) == frc
.target_type() );
52 VERIFY( *frc
.target
<int (X::*)() const >() == &X::foo_c
);
54 function
<int(volatile X
&)> frv(&X::foo_v
);
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 );
61 function
<int(const volatile X
&)> frcv(&X::foo_cv
);
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 );
68 function
<int(X
*)> grm(&X::bar
);
70 VERIFY( grm(&x
) == 17 );
71 VERIFY( typeid(int X::*) == grm
.target_type() );
72 VERIFY( *grm
.target
<int X::*>() == &X::bar
);
74 function
<int(X
*)> gr(&X::foo
);
76 VERIFY( gr(&x
) == 1 );
77 VERIFY( typeid(int (X::*)()) == gr
.target_type() );
78 VERIFY( *gr
.target
<int (X::*)()>() == &X::foo
);
80 function
<int(const X
*)> grc(&X::foo_c
);
82 VERIFY( grc(&x
) == 2 );
83 VERIFY( typeid(int (X::*)() const) == grc
.target_type() );
84 VERIFY( *grc
.target
<int (X::*)() const >() == &X::foo_c
);
86 function
<int(volatile X
*)> grv(&X::foo_v
);
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 );
93 function
<int(const volatile X
*)> grcv(&X::foo_cv
);
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 );