OSDN Git Service

Licensing changes to GPLv3 resp. GPLv3 with GCC Runtime Exception.
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / testsuite / 20_util / reference_wrapper / typedefs.cc
1 // { dg-options "-std=gnu++0x" }
2
3 // Copyright (C) 2008, 2009 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 3, 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 COPYING3.  If not see
18 // <http://www.gnu.org/licenses/>.
19
20 #include <functional>
21 #include <type_traits>
22 #include <testsuite_hooks.h>
23 #include <testsuite_tr1.h>
24
25 using namespace __gnu_test;
26
27 struct X {};
28
29 struct int_result_type { typedef int result_type; };
30
31 struct derives_unary : std::unary_function<int, int> {};
32
33 struct derives_binary : std::binary_function<int, float, int> {};
34
35 struct derives_unary_binary
36   : std::unary_function<int, int>,
37     std::binary_function<int, float, int>
38 {
39   typedef int result_type;
40 };
41
42 void test01()
43 {
44   bool test __attribute__((unused)) = true;
45
46   using std::reference_wrapper;
47   using std::is_same;
48   using std::is_convertible;
49   using std::unary_function;
50   using std::binary_function;
51
52   // Check result_type typedef
53   VERIFY((is_same<reference_wrapper<int_result_type>::result_type, int>::value));
54   VERIFY((is_same<reference_wrapper<derives_unary>::result_type, int>::value));
55   VERIFY((is_same<reference_wrapper<derives_binary>::result_type, int>::value));
56   VERIFY((is_same<reference_wrapper<derives_unary_binary>::result_type, int>::value));
57   VERIFY((is_same<reference_wrapper<int(void)>::result_type, int>::value));
58   VERIFY((is_same<reference_wrapper<int(*)(void)>::result_type, int>::value));
59   VERIFY((is_same<reference_wrapper<int (::X::*)()>::result_type, int>::value));
60   VERIFY((is_same<reference_wrapper<int (::X::*)(float)>::result_type, int>::value));
61
62   // Check derivation from unary_function
63   VERIFY((is_convertible<reference_wrapper<derives_unary>*, unary_function<int, int>*>::value));
64   VERIFY((is_convertible<reference_wrapper<derives_unary_binary>*, 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(*)(int)>*, unary_function<int, int>*>::value));
67   VERIFY((is_convertible<reference_wrapper<int (::X::*)()>*, unary_function< ::X*, int>*>::value));
68   VERIFY((is_convertible<reference_wrapper<int (::X::*)() const>*, unary_function<const ::X*, int>*>::value));
69   VERIFY((is_convertible<reference_wrapper<int (::X::*)() volatile>*, unary_function<volatile ::X*, int>*>::value));
70   VERIFY((is_convertible<reference_wrapper<int (::X::*)() const volatile>*, unary_function<const volatile ::X*, int>*>::value));
71
72   // Check derivation from binary_function
73   VERIFY((is_convertible<reference_wrapper<derives_binary>*, binary_function<int, float, int>*>::value));
74   VERIFY((is_convertible<reference_wrapper<derives_unary_binary>*, 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(*)(int, float)>*, binary_function<int, float, int>*>::value));
77   VERIFY((is_convertible<reference_wrapper<int (::X::*)(float)>*, binary_function< ::X*, float, int>*>::value));
78   VERIFY((is_convertible<reference_wrapper<int (::X::*)(float) const>*, binary_function<const ::X*, float, int>*>::value));
79   VERIFY((is_convertible<reference_wrapper<int (::X::*)(float) volatile>*, binary_function<volatile ::X*, float, int>*>::value));
80   VERIFY((is_convertible<reference_wrapper<int (::X::*)(float) const volatile>*, binary_function<const volatile ::X*, float, int>*>::value));
81 }
82
83 int main()
84 {
85   test01();
86   return 0;
87 }