]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | |
2 | // (C) Copyright John Maddock & Thorsten Ottosen 2005. | |
3 | // Use, modification and distribution are subject to the | |
4 | // Boost Software License, Version 1.0. (See accompanying file | |
5 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | |
6 | ||
7c673cae FG |
7 | #ifdef TEST_STD |
8 | # include <type_traits> | |
9 | #else | |
10 | # include <boost/type_traits/decay.hpp> | |
11 | # include <boost/type_traits/is_same.hpp> | |
12 | #endif | |
11fdf7f2 TL |
13 | #include "test.hpp" |
14 | #include "check_type.hpp" | |
15 | #include "check_integral_constant.hpp" | |
7c673cae FG |
16 | #include <iostream> |
17 | #include <string> | |
18 | #include <utility> | |
19 | ||
20 | #ifdef BOOST_INTEL | |
21 | // remark #383: value copied to temporary, reference to temporary used | |
22 | // std::pair<std::string, int> p2 = boost::make_pair( "foo", 1 ); | |
23 | // ^ | |
24 | #pragma warning(disable:383) | |
25 | #endif | |
26 | ||
27 | namespace boost | |
28 | { | |
29 | ||
30 | int proc1() | |
31 | { | |
32 | return 0; | |
33 | } | |
34 | int proc2(int c) | |
35 | { | |
36 | return c; | |
37 | } | |
38 | ||
39 | // | |
40 | // An almost optimal version of std::make_pair() | |
41 | // | |
42 | template< class F, class S > | |
43 | inline std::pair< BOOST_DEDUCED_TYPENAME tt::decay<const F>::type, | |
44 | BOOST_DEDUCED_TYPENAME tt::decay<const S>::type > | |
45 | make_pair( const F& f, const S& s ) | |
46 | { | |
47 | return std::pair< BOOST_DEDUCED_TYPENAME tt::decay<const F>::type, | |
48 | BOOST_DEDUCED_TYPENAME tt::decay<const S>::type >( f, s ); | |
49 | } | |
50 | ||
51 | /* | |
52 | This overload will mess up vc7.1 | |
53 | ||
54 | template< class F, class S > | |
55 | inline std::pair< BOOST_DEDUCED_TYPENAME ::tt::decay<F>::type, | |
56 | BOOST_DEDUCED_TYPENAME ::tt::decay<S>::type > | |
57 | make_pair( F& f, S& s ) | |
58 | { | |
59 | return std::pair< BOOST_DEDUCED_TYPENAME ::tt::decay<F>::type, | |
60 | BOOST_DEDUCED_TYPENAME ::tt::decay<S>::type >( f, s ); | |
61 | } | |
62 | */ | |
63 | } | |
64 | ||
65 | BOOST_DECL_TRANSFORM_TEST3(decay_test_1, ::tt::decay, const) | |
66 | BOOST_DECL_TRANSFORM_TEST3(decay_test_2, ::tt::decay, volatile) | |
67 | BOOST_DECL_TRANSFORM_TEST3(decay_test_3, ::tt::decay, const volatile) | |
68 | BOOST_DECL_TRANSFORM_TEST3(decay_test_4, ::tt::decay, const&) | |
69 | BOOST_DECL_TRANSFORM_TEST3(decay_test_5, ::tt::decay, volatile&) | |
70 | BOOST_DECL_TRANSFORM_TEST3(decay_test_6, ::tt::decay, const volatile&) | |
71 | BOOST_DECL_TRANSFORM_TEST(decay_test_7, ::tt::decay, const*, const*) | |
72 | BOOST_DECL_TRANSFORM_TEST(decay_test_8, ::tt::decay, [], *) | |
73 | BOOST_DECL_TRANSFORM_TEST(decay_test_9, ::tt::decay, [2], *) | |
74 | BOOST_DECL_TRANSFORM_TEST(decay_test_10, ::tt::decay, [2][3], (*)[3]) | |
75 | BOOST_DECL_TRANSFORM_TEST(decay_test_11, ::tt::decay, const[], const*) | |
76 | BOOST_DECL_TRANSFORM_TEST(decay_test_12, ::tt::decay, const[2], const*) | |
77 | BOOST_DECL_TRANSFORM_TEST(decay_test_13, ::tt::decay, const[2][3], const(*)[3]) | |
78 | BOOST_DECL_TRANSFORM_TEST(decay_test_14, ::tt::decay, (int), (*)(int)) | |
79 | ||
80 | ||
81 | TT_TEST_BEGIN(decay) | |
82 | ||
83 | decay_test_1(); | |
84 | decay_test_2(); | |
85 | decay_test_3(); | |
86 | decay_test_4(); | |
87 | decay_test_5(); | |
88 | decay_test_6(); | |
89 | decay_test_7(); | |
90 | decay_test_8(); | |
91 | decay_test_9(); | |
92 | decay_test_10(); | |
93 | decay_test_11(); | |
94 | decay_test_12(); | |
95 | decay_test_13(); | |
96 | decay_test_14(); | |
97 | ||
98 | BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_same< | |
99 | ::tt::decay<int>::type,int>::value), | |
100 | true ); | |
101 | BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_same< | |
102 | ::tt::decay<char[2]>::type,char*>::value), | |
103 | true ); | |
104 | BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_same< | |
105 | ::tt::decay<char[2][3]>::type,char(*)[3]>::value), | |
106 | true ); | |
107 | BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_same< | |
108 | ::tt::decay<const char[2]>::type,const char*>::value), | |
109 | true ); | |
110 | BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_same< | |
111 | ::tt::decay<wchar_t[2]>::type,wchar_t*>::value), | |
112 | true ); | |
113 | BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_same< | |
114 | ::tt::decay<const wchar_t[2]>::type,const wchar_t*>::value), | |
115 | true ); | |
116 | BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_same< | |
117 | ::tt::decay<const wchar_t[2]>::type,const wchar_t*>::value), | |
118 | true ); | |
119 | ||
120 | typedef int f1_type(void); | |
121 | typedef int f2_type(int); | |
122 | ||
123 | BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_same< | |
124 | ::tt::decay<f1_type>::type,int (*)(void)>::value), | |
125 | true ); | |
126 | BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_same< | |
127 | ::tt::decay<f2_type>::type,int (*)(int)>::value), | |
128 | true ); | |
129 | ||
130 | #ifndef BOOST_NO_TEMPLATED_ITERATOR_CONSTRUCTORS | |
131 | // | |
132 | // Don't test this if the std lib has no templated constructors (Oracle+STLPort): | |
133 | // | |
134 | std::pair<std::string,std::string> p = boost::make_pair( "foo", "bar" ); | |
135 | std::pair<std::string, int> p2 = boost::make_pair( "foo", 1 ); | |
136 | #ifndef BOOST_NO_STD_WSTRING | |
137 | std::pair<std::wstring,std::string> p3 = boost::make_pair( L"foo", "bar" ); | |
138 | std::pair<std::wstring, int> p4 = boost::make_pair( L"foo", 1 ); | |
139 | #endif | |
140 | #endif | |
141 | // | |
142 | // Todo: make these work sometime. The test id not directly | |
143 | // related to decay<T>::type and can be avoided for now. | |
144 | // | |
145 | /* | |
146 | int array[10]; | |
147 | std::pair<int*,int*> p5 = boost::make_pair( array, array ); | |
20effc67 | 148 | #ifndef BOOST_BORLANDC |
7c673cae FG |
149 | std::pair<int(*)(void), int(*)(int)> p6 = boost::make_pair(boost::proc1, boost::proc2); |
150 | p6.first(); | |
151 | p6.second(1); | |
152 | #endif | |
153 | */ | |
154 | ||
155 | TT_TEST_END | |
156 | ||
157 | ||
158 | ||
159 | ||
160 | ||
161 | ||
162 | ||
163 |