]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/tr1/3_function_objects/reference_wrapper/typedefs.cc
1 // 2005-02-27 Douglas Gregor <doug.gregor -at- gmail.com>
3 // Copyright (C) 2005-2016 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 // 2.1 reference wrappers
21 #include <tr1/functional>
22 #include <tr1/type_traits>
23 #include <testsuite_hooks.h>
24 #include <testsuite_tr1.h>
26 using namespace __gnu_test
;
30 struct int_result_type
{ typedef int result_type
; };
32 struct derives_unary
: std::unary_function
<int, int> {};
34 struct derives_binary
: std::binary_function
<int, float, int> {};
36 struct derives_unary_binary
37 : std::unary_function
<int, int>,
38 std::binary_function
<int, float, int>
40 typedef int result_type
;
45 using std::tr1::reference_wrapper
;
46 using std::tr1::is_same
;
47 using std::tr1::is_convertible
;
48 using std::unary_function
;
49 using std::binary_function
;
51 // Check result_type typedef
52 VERIFY((is_same
<reference_wrapper
<int_result_type
>::result_type
, int>::value
));
53 VERIFY((is_same
<reference_wrapper
<derives_unary
>::result_type
, int>::value
));
54 VERIFY((is_same
<reference_wrapper
<derives_binary
>::result_type
, int>::value
));
55 VERIFY((is_same
<reference_wrapper
<derives_unary_binary
>::result_type
, int>::value
));
56 VERIFY((is_same
<reference_wrapper
<int(void)>::result_type
, int>::value
));
57 VERIFY((is_same
<reference_wrapper
<int(*)(void)>::result_type
, int>::value
));
58 VERIFY((is_same
<reference_wrapper
<int (::X::*)()>::result_type
, int>::value
));
59 VERIFY((is_same
<reference_wrapper
<int (::X::*)(float)>::result_type
, int>::value
));
61 // Check derivation from unary_function
62 VERIFY((is_convertible
<reference_wrapper
<derives_unary
>*, unary_function
<int, int>*>::value
));
63 VERIFY((is_convertible
<reference_wrapper
<derives_unary_binary
>*, unary_function
<int, int>*>::value
));
64 VERIFY((is_convertible
<reference_wrapper
<int(int)>*, unary_function
<int, int>*>::value
));
65 VERIFY((is_convertible
<reference_wrapper
<int(*)(int)>*, unary_function
<int, int>*>::value
));
66 VERIFY((is_convertible
<reference_wrapper
<int (::X::*)()>*, unary_function
< ::X
*, int>*>::value
));
67 VERIFY((is_convertible
<reference_wrapper
<int (::X::*)() const>*, unary_function
<const ::X
*, int>*>::value
));
68 VERIFY((is_convertible
<reference_wrapper
<int (::X::*)() volatile>*, unary_function
<volatile ::X
*, int>*>::value
));
69 VERIFY((is_convertible
<reference_wrapper
<int (::X::*)() const volatile>*, unary_function
<const volatile ::X
*, int>*>::value
));
71 // Check derivation from binary_function
72 VERIFY((is_convertible
<reference_wrapper
<derives_binary
>*, binary_function
<int, float, int>*>::value
));
73 VERIFY((is_convertible
<reference_wrapper
<derives_unary_binary
>*, binary_function
<int, float, int>*>::value
));
74 VERIFY((is_convertible
<reference_wrapper
<int(int, float)>*, binary_function
<int, float, int>*>::value
));
75 VERIFY((is_convertible
<reference_wrapper
<int(*)(int, float)>*, binary_function
<int, float, int>*>::value
));
76 VERIFY((is_convertible
<reference_wrapper
<int (::X::*)(float)>*, binary_function
< ::X
*, float, int>*>::value
));
77 VERIFY((is_convertible
<reference_wrapper
<int (::X::*)(float) const>*, binary_function
<const ::X
*, float, int>*>::value
));
78 VERIFY((is_convertible
<reference_wrapper
<int (::X::*)(float) volatile>*, binary_function
<volatile ::X
*, float, int>*>::value
));
79 VERIFY((is_convertible
<reference_wrapper
<int (::X::*)(float) const volatile>*, binary_function
<const volatile ::X
*, float, int>*>::value
));