]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/tr1/3_function_objects/reference_wrapper/typedefs.cc
All files: Update FSF address.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / tr1 / 3_function_objects / reference_wrapper / typedefs.cc
1 // 2005-02-27 Douglas Gregor <doug.gregor -at- gmail.com>
2 //
3 // Copyright (C) 2005 Free Software Foundation, Inc.
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
8 // Free Software Foundation; either version 2, or (at your option)
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
17 // with this library; see the file COPYING. If not, write to the Free
18 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
19 // USA.
20
21 // 2.1 reference wrappers
22 #include <tr1/functional>
23 #include <tr1/type_traits>
24 #include <testsuite_hooks.h>
25 #include <testsuite_tr1.h>
26
27 using namespace __gnu_test;
28
29 struct X {};
30
31 struct int_result_type { typedef int result_type; };
32
33 struct derives_unary : std::unary_function<int, int> {};
34
35 struct derives_binary : std::binary_function<int, float, int> {};
36
37 struct derives_unary_binary
38 : std::unary_function<int, int>,
39 std::binary_function<int, float, int>
40 {
41 typedef int result_type;
42 };
43
44 void test01()
45 {
46 bool test __attribute__((unused)) = true;
47
48 using std::tr1::reference_wrapper;
49 using std::tr1::is_same;
50 using std::tr1::is_convertible;
51 using std::unary_function;
52 using std::binary_function;
53
54 // Check result_type typedef
55 VERIFY((is_same<reference_wrapper<int_result_type>::result_type, int>::value));
56 VERIFY((is_same<reference_wrapper<derives_unary>::result_type, int>::value));
57 VERIFY((is_same<reference_wrapper<derives_binary>::result_type, int>::value));
58 VERIFY((is_same<reference_wrapper<derives_unary_binary>::result_type, int>::value));
59 VERIFY((is_same<reference_wrapper<int(void)>::result_type, int>::value));
60 VERIFY((is_same<reference_wrapper<int(*)(void)>::result_type, int>::value));
61 VERIFY((is_same<reference_wrapper<int (::X::*)()>::result_type, int>::value));
62 VERIFY((is_same<reference_wrapper<int (::X::*)(float)>::result_type, int>::value));
63
64 // Check derivation from unary_function
65 VERIFY((is_convertible<reference_wrapper<derives_unary>*, unary_function<int, int>*>::value));
66 VERIFY((is_convertible<reference_wrapper<derives_unary_binary>*, 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(*)(int)>*, unary_function<int, int>*>::value));
69 VERIFY((is_convertible<reference_wrapper<int (::X::*)()>*, unary_function< ::X*, int>*>::value));
70 VERIFY((is_convertible<reference_wrapper<int (::X::*)() const>*, unary_function<const ::X*, int>*>::value));
71 VERIFY((is_convertible<reference_wrapper<int (::X::*)() volatile>*, unary_function<volatile ::X*, int>*>::value));
72 VERIFY((is_convertible<reference_wrapper<int (::X::*)() const volatile>*, unary_function<const volatile ::X*, int>*>::value));
73
74 // Check derivation from binary_function
75 VERIFY((is_convertible<reference_wrapper<derives_binary>*, binary_function<int, float, int>*>::value));
76 VERIFY((is_convertible<reference_wrapper<derives_unary_binary>*, 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(*)(int, float)>*, binary_function<int, float, int>*>::value));
79 VERIFY((is_convertible<reference_wrapper<int (::X::*)(float)>*, binary_function< ::X*, float, int>*>::value));
80 VERIFY((is_convertible<reference_wrapper<int (::X::*)(float) const>*, binary_function<const ::X*, float, int>*>::value));
81 VERIFY((is_convertible<reference_wrapper<int (::X::*)(float) volatile>*, binary_function<volatile ::X*, float, int>*>::value));
82 VERIFY((is_convertible<reference_wrapper<int (::X::*)(float) const volatile>*, binary_function<const volatile ::X*, float, int>*>::value));
83 }
84
85 int main()
86 {
87 test01();
88 return 0;
89 }