Imported Upstream version 1.57.0
[platform/upstream/boost.git] / libs / type_traits / test / decay_test.cpp
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
7 #include "test.hpp"
8 #include "check_integral_constant.hpp"
9 #ifdef TEST_STD
10 #  include <type_traits>
11 #else
12 #  include <boost/type_traits/decay.hpp>
13 #  include <boost/type_traits/is_same.hpp>
14 #endif
15 #include <iostream>
16 #include <string>
17 #include <utility>
18
19 #ifdef BOOST_INTEL
20 //  remark #383: value copied to temporary, reference to temporary used
21 //     std::pair<std::string, int>        p2 = boost::make_pair( "foo", 1 );
22 //                                                                      ^
23 #pragma warning(disable:383)
24 #endif
25
26 namespace boost
27 {
28
29     int proc1()
30     {
31        return 0;
32     }
33     int proc2(int c)
34     {
35        return c;
36     }
37     
38     //
39     // An almost optimal version of std::make_pair()
40     //
41     template< class F, class S >
42     inline std::pair< BOOST_DEDUCED_TYPENAME tt::decay<const F>::type, 
43                       BOOST_DEDUCED_TYPENAME tt::decay<const S>::type >
44     make_pair( const F& f, const S& s )
45     {
46         return std::pair< BOOST_DEDUCED_TYPENAME tt::decay<const F>::type, 
47                           BOOST_DEDUCED_TYPENAME tt::decay<const S>::type >( f, s ); 
48     }
49
50     /*
51     This overload will mess up vc7.1
52
53     template< class F, class S >
54     inline std::pair< BOOST_DEDUCED_TYPENAME ::tt::decay<F>::type, 
55                       BOOST_DEDUCED_TYPENAME ::tt::decay<S>::type >
56     make_pair( F& f, S& s )
57     {
58         return std::pair< BOOST_DEDUCED_TYPENAME ::tt::decay<F>::type, 
59                           BOOST_DEDUCED_TYPENAME ::tt::decay<S>::type >( f, s ); 
60     }
61     */
62 }
63
64 TT_TEST_BEGIN(is_class)
65
66    BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_same< 
67           ::tt::decay<int>::type,int>::value),
68                                   true );
69    BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_same< 
70           ::tt::decay<char[2]>::type,char*>::value),
71                                  true );
72    BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_same< 
73           ::tt::decay<char[2][3]>::type,char(*)[3]>::value),
74                                  true );
75    BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_same< 
76           ::tt::decay<const char[2]>::type,const char*>::value),
77                                   true );
78    BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_same< 
79           ::tt::decay<wchar_t[2]>::type,wchar_t*>::value),
80                                   true );
81    BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_same< 
82           ::tt::decay<const wchar_t[2]>::type,const wchar_t*>::value),
83                                   true );
84    BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_same< 
85           ::tt::decay<const wchar_t[2]>::type,const wchar_t*>::value),
86                                   true );
87
88    typedef int f1_type(void);
89    typedef int f2_type(int);
90
91    BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_same< 
92           ::tt::decay<f1_type>::type,int (*)(void)>::value),
93                                   true );
94    BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_same< 
95           ::tt::decay<f2_type>::type,int (*)(int)>::value),
96                                   true );
97
98    std::pair<std::string,std::string> p  = boost::make_pair( "foo", "bar" );
99    std::pair<std::string, int>        p2 = boost::make_pair( "foo", 1 );
100 #ifndef BOOST_NO_STD_WSTRING
101    std::pair<std::wstring,std::string> p3  = boost::make_pair( L"foo", "bar" );
102    std::pair<std::wstring, int>        p4  = boost::make_pair( L"foo", 1 );
103 #endif
104
105    //
106    // Todo: make these work sometime. The test id not directly
107    //       related to decay<T>::type and can be avoided for now.
108    // 
109    /*
110    int array[10];
111    std::pair<int*,int*> p5 = boost::make_pair( array, array );
112 #ifndef __BORLANDC__
113    std::pair<int(*)(void), int(*)(int)> p6 = boost::make_pair(boost::proc1, boost::proc2);
114    p6.first();
115    p6.second(1);
116 #endif
117    */
118    
119 TT_TEST_END
120
121
122
123
124
125
126
127