]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/tr1/3_function_objects/function/8.cc
1 // 2005-01-15 Douglas Gregor <dgregor@cs.indiana.edu>
3 // Copyright (C) 2005-2014 Free Software Foundation, Inc.
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
8 // Free Software Foundation; either version 3, or (at your option)
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.
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING3. If not see
18 // <http://www.gnu.org/licenses/>.
20 // 3.7.2 polymorphic function object wrapper
21 #include <tr1/functional>
22 #include <testsuite_hooks.h>
23 #include <testsuite_tr1.h>
25 using namespace __gnu_test
;
27 bool test
__attribute__((unused
)) = true;
29 // Put reference_wrappers to member pointers
32 using std::tr1::function
;
36 int X::* X_bar
= &X::bar
;
37 int (X::* X_foo
)() = &X::foo
;
38 int (X::* X_foo_c
)() const = &X::foo_c
;
39 int (X::* X_foo_v
)() volatile = &X::foo_v
;
40 int (X::* X_foo_cv
)() const volatile = &X::foo_cv
;
45 function
<int(X
&)> frm(ref(X_bar
));
47 VERIFY( frm(x
) == 17 );
48 VERIFY( typeid(int X::*) == frm
.target_type() );
49 VERIFY( frm
.target
<int X::*>() == &X_bar
);
51 function
<int(X
&)> fr(ref(X_foo
));
54 VERIFY( typeid(int (X::*)()) == fr
.target_type() );
55 VERIFY( fr
.target
<int (X::*)()>() == &X_foo
);
57 function
<int(const X
&)> frc(ref(X_foo_c
));
59 VERIFY( frc(x
) == 2 );
60 VERIFY( typeid(int (X::*)() const) == frc
.target_type() );
61 VERIFY( frc
.target
<int (X::*)() const >() == &X_foo_c
);
63 function
<int(volatile X
&)> frv(ref(X_foo_v
));
65 VERIFY( frv(x
) == 3 );
66 VERIFY( typeid(int (X::*)() volatile) == frv
.target_type() );
67 VERIFY( *frv
.target
<int (X::*)() volatile >() == X_foo_v
);
68 VERIFY( frv
.target
<int (X::*)() const volatile>() == 0 );
70 function
<int(const volatile X
&)> frcv(ref(X_foo_cv
));
72 VERIFY( frcv(x
) == 4 );
73 VERIFY( typeid(int (X::*)() const volatile) == frcv
.target_type() );
74 VERIFY( *frcv
.target
<int (X::*)() const volatile >() == X_foo_cv
);
75 VERIFY( frcv
.target
<int (X::*)() const>() == 0 );
77 function
<int(X
*)> grm(ref(X_bar
));
79 VERIFY( grm(&x
) == 17 );
80 VERIFY( typeid(int X::*) == grm
.target_type() );
81 VERIFY( *grm
.target
<int X::*>() == X_bar
);
83 function
<int(X
*)> gr(ref(X_foo
));
85 VERIFY( gr(&x
) == 1 );
86 VERIFY( typeid(int (X::*)()) == gr
.target_type() );
87 VERIFY( *gr
.target
<int (X::*)()>() == X_foo
);
89 function
<int(const X
*)> grc(ref(X_foo_c
));
91 VERIFY( grc(&x
) == 2 );
92 VERIFY( typeid(int (X::*)() const) == grc
.target_type() );
93 VERIFY( *grc
.target
<int (X::*)() const >() == X_foo_c
);
95 function
<int(volatile X
*)> grv(ref(X_foo_v
));
97 VERIFY( grv(&x
) == 3 );
98 VERIFY( typeid(int (X::*)() volatile) == grv
.target_type() );
99 VERIFY( *grv
.target
<int (X::*)() volatile >() == X_foo_v
);
100 VERIFY( grv
.target
<int (X::*)() const volatile>() == 0 );
102 function
<int(const volatile X
*)> grcv(ref(X_foo_cv
));
104 VERIFY( grcv(&x
) == 4 );
105 VERIFY( typeid(int (X::*)() const volatile) == grcv
.target_type() );
106 VERIFY( *grcv
.target
<int (X::*)() const volatile >() == X_foo_cv
);
107 VERIFY( grcv
.target
<int (X::*)() const>() == 0 );
109 function
<int(X
&)> hrm(cref(X_bar
));
111 VERIFY( hrm(x
) == 17 );
112 VERIFY( typeid(int X::*) == hrm
.target_type() );
113 VERIFY( hrm
.target
<int X::*>() == 0 );
114 VERIFY( hrm
.target
<int X::* const>() == &X_bar
);
116 function
<int(X
&)> hr(cref(X_foo
));
118 VERIFY( hr(x
) == 1 );
119 VERIFY( typeid(int (X::*)()) == hr
.target_type() );
120 VERIFY( hr
.target
<int (X::* const)()>() == &X_foo
);
122 function
<int(const X
&)> hrc(cref(X_foo_c
));
124 VERIFY( hrc(x
) == 2 );
125 VERIFY( typeid(int (X::*)() const) == hrc
.target_type() );
126 VERIFY( hrc
.target
<int (X::* const)() const >() == &X_foo_c
);
128 function
<int(volatile X
&)> hrv(cref(X_foo_v
));
130 VERIFY( hrv(x
) == 3 );
131 VERIFY( typeid(int (X::*)() volatile) == hrv
.target_type() );
132 VERIFY( hrv
.target
<int (X::* const)() volatile >() == &X_foo_v
);
133 VERIFY( hrv
.target
<int (X::* const)() const volatile>() == 0 );
135 function
<int(const volatile X
&)> hrcv(cref(X_foo_cv
));
137 VERIFY( hrcv(x
) == 4 );
138 VERIFY( typeid(int (X::*)() const volatile) == hrcv
.target_type() );
139 VERIFY( hrcv
.target
<int (X::* const)() const volatile >() == &X_foo_cv
);
140 VERIFY( hrcv
.target
<int (X::* const)() const>() == 0 );