]>
Commit | Line | Data |
---|---|---|
3c235000 DG |
1 | // 2005-02-27 Douglas Gregor <doug.gregor -at- gmail.com> |
2 | // | |
a945c346 | 3 | // Copyright (C) 2005-2024 Free Software Foundation, Inc. |
3c235000 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) |
3c235000 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/>. | |
3c235000 | 19 | |
de196e5d JW |
20 | // { dg-options "-Wno-deprecated-declarations" } |
21 | ||
3c235000 DG |
22 | // 2.1 reference wrappers |
23 | #include <tr1/functional> | |
24 | #include <tr1/type_traits> | |
25 | #include <testsuite_hooks.h> | |
26 | #include <testsuite_tr1.h> | |
27 | ||
28 | using namespace __gnu_test; | |
29 | ||
30 | struct X {}; | |
31 | ||
32 | struct int_result_type { typedef int result_type; }; | |
33 | ||
34 | struct derives_unary : std::unary_function<int, int> {}; | |
35 | ||
36 | struct derives_binary : std::binary_function<int, float, int> {}; | |
37 | ||
38 | struct derives_unary_binary | |
39 | : std::unary_function<int, int>, | |
40 | std::binary_function<int, float, int> | |
41 | { | |
42 | typedef int result_type; | |
43 | }; | |
44 | ||
45 | void test01() | |
46 | { | |
3c235000 DG |
47 | using std::tr1::reference_wrapper; |
48 | using std::tr1::is_same; | |
49 | using std::tr1::is_convertible; | |
50 | using std::unary_function; | |
51 | using std::binary_function; | |
52 | ||
53 | // Check result_type typedef | |
54 | VERIFY((is_same<reference_wrapper<int_result_type>::result_type, int>::value)); | |
55 | VERIFY((is_same<reference_wrapper<derives_unary>::result_type, int>::value)); | |
56 | VERIFY((is_same<reference_wrapper<derives_binary>::result_type, int>::value)); | |
57 | VERIFY((is_same<reference_wrapper<derives_unary_binary>::result_type, int>::value)); | |
58 | VERIFY((is_same<reference_wrapper<int(void)>::result_type, int>::value)); | |
59 | VERIFY((is_same<reference_wrapper<int(*)(void)>::result_type, int>::value)); | |
60 | VERIFY((is_same<reference_wrapper<int (::X::*)()>::result_type, int>::value)); | |
61 | VERIFY((is_same<reference_wrapper<int (::X::*)(float)>::result_type, int>::value)); | |
62 | ||
63 | // Check derivation from unary_function | |
64 | VERIFY((is_convertible<reference_wrapper<derives_unary>*, unary_function<int, int>*>::value)); | |
65 | VERIFY((is_convertible<reference_wrapper<derives_unary_binary>*, unary_function<int, int>*>::value)); | |
66 | VERIFY((is_convertible<reference_wrapper<int(int)>*, unary_function<int, int>*>::value)); | |
67 | VERIFY((is_convertible<reference_wrapper<int(*)(int)>*, unary_function<int, int>*>::value)); | |
68 | VERIFY((is_convertible<reference_wrapper<int (::X::*)()>*, unary_function< ::X*, int>*>::value)); | |
69 | VERIFY((is_convertible<reference_wrapper<int (::X::*)() const>*, unary_function<const ::X*, int>*>::value)); | |
70 | VERIFY((is_convertible<reference_wrapper<int (::X::*)() volatile>*, unary_function<volatile ::X*, int>*>::value)); | |
71 | VERIFY((is_convertible<reference_wrapper<int (::X::*)() const volatile>*, unary_function<const volatile ::X*, int>*>::value)); | |
72 | ||
73 | // Check derivation from binary_function | |
74 | VERIFY((is_convertible<reference_wrapper<derives_binary>*, binary_function<int, float, int>*>::value)); | |
75 | VERIFY((is_convertible<reference_wrapper<derives_unary_binary>*, binary_function<int, float, int>*>::value)); | |
76 | VERIFY((is_convertible<reference_wrapper<int(int, float)>*, binary_function<int, float, int>*>::value)); | |
77 | VERIFY((is_convertible<reference_wrapper<int(*)(int, float)>*, binary_function<int, float, int>*>::value)); | |
78 | VERIFY((is_convertible<reference_wrapper<int (::X::*)(float)>*, binary_function< ::X*, float, int>*>::value)); | |
79 | VERIFY((is_convertible<reference_wrapper<int (::X::*)(float) const>*, binary_function<const ::X*, float, int>*>::value)); | |
80 | VERIFY((is_convertible<reference_wrapper<int (::X::*)(float) volatile>*, binary_function<volatile ::X*, float, int>*>::value)); | |
81 | VERIFY((is_convertible<reference_wrapper<int (::X::*)(float) const volatile>*, binary_function<const volatile ::X*, float, int>*>::value)); | |
82 | } | |
83 | ||
84 | int main() | |
85 | { | |
86 | test01(); | |
87 | return 0; | |
88 | } |