]> rtime.felk.cvut.cz Git - eurobot/public.git/blob - src/boost/boost/type_traits/common_type.hpp
Add subset of boost library headers needed for compilation on PowerPC
[eurobot/public.git] / src / boost / boost / type_traits / common_type.hpp
1 //  common_type.hpp  ---------------------------------------------------------//
2
3 //  Copyright 2008 Howard Hinnant
4 //  Copyright 2008 Beman Dawes
5
6 //  Distributed under the Boost Software License, Version 1.0.
7 //  See http://www.boost.org/LICENSE_1_0.txt
8
9 #ifndef BOOST_TYPE_TRAITS_COMMON_TYPE_HPP
10 #define BOOST_TYPE_TRAITS_COMMON_TYPE_HPP
11
12 #include <boost/config.hpp>
13
14 #if defined(__SUNPRO_CC) && !defined(BOOST_COMMON_TYPE_DONT_USE_TYPEOF)
15 #  define BOOST_COMMON_TYPE_DONT_USE_TYPEOF
16 #endif
17 #if defined(__IBMCPP__) && !defined(BOOST_COMMON_TYPE_DONT_USE_TYPEOF)
18 #  define BOOST_COMMON_TYPE_DONT_USE_TYPEOF
19 #endif
20
21 //----------------------------------------------------------------------------//
22 #if defined(BOOST_NO_VARIADIC_TEMPLATES) && !defined(BOOST_COMMON_TYPE_ARITY)
23 #define BOOST_COMMON_TYPE_ARITY 3
24 #endif
25
26 //----------------------------------------------------------------------------//
27 #if defined(BOOST_NO_DECLTYPE) && !defined(BOOST_COMMON_TYPE_DONT_USE_TYPEOF) && !defined(BOOST_TYPEOF_SILENT)
28 #define BOOST_TYPEOF_SILENT
29 #include <boost/typeof/typeof.hpp>   // boost wonders never cease!
30 #endif
31
32 //----------------------------------------------------------------------------//
33 #ifndef BOOST_NO_STATIC_ASSERT
34 #define BOOST_COMMON_TYPE_STATIC_ASSERT(CND, MSG, TYPES) static_assert(CND,MSG)
35 #elif defined(BOOST_COMMON_TYPE_USES_MPL_ASSERT)
36 #include <boost/mpl/assert.hpp>
37 #include <boost/mpl/bool.hpp>
38 #define BOOST_COMMON_TYPE_STATIC_ASSERT(CND, MSG, TYPES)                                 \
39     BOOST_MPL_ASSERT_MSG(boost::mpl::bool_< (CND) >::type::value, MSG, TYPES)
40 #else
41 #include <boost/static_assert.hpp>
42 #define BOOST_COMMON_TYPE_STATIC_ASSERT(CND, MSG, TYPES) BOOST_STATIC_ASSERT(CND)
43 #endif
44
45 #if !defined(BOOST_NO_STATIC_ASSERT) || !defined(BOOST_COMMON_TYPE_USES_MPL_ASSERT)
46 #define BOOST_COMMON_TYPE_MUST_BE_A_COMPLE_TYPE "must be complete type"
47 #endif
48
49 #if defined(BOOST_NO_DECLTYPE) && defined(BOOST_COMMON_TYPE_DONT_USE_TYPEOF)
50 #include <boost/type_traits/detail/common_type_imp.hpp>
51 #include <boost/type_traits/remove_cv.hpp>
52 #endif
53 #include <boost/mpl/if.hpp>
54 #include <boost/utility/declval.hpp>
55 #include <boost/type_traits/add_rvalue_reference.hpp>
56
57 //----------------------------------------------------------------------------//
58 //                                                                            //
59 //                           C++03 implementation of                          //
60 //             20.6.7 Other transformations [meta.trans.other]                //
61 //                          Written by Howard Hinnant                         //
62 //      Adapted for Boost by Beman Dawes, Vicente Botet and  Jeffrey Hellrung //
63 //                                                                            //
64 //----------------------------------------------------------------------------//
65
66 namespace boost {
67
68 // prototype
69 #if !defined(BOOST_NO_VARIADIC_TEMPLATES)
70     template<typename... T>
71     struct common_type;
72 #else // or no specialization
73     template <class T, class U = void, class V = void>
74     struct common_type
75     {
76     public:
77         typedef typename common_type<typename common_type<T, U>::type, V>::type type;
78     };
79 #endif
80
81
82 // 1 arg
83     template<typename T>
84 #if !defined(BOOST_NO_VARIADIC_TEMPLATES)
85     struct common_type<T>
86 #else
87     struct common_type<T, void, void>
88
89 #endif
90     {
91         BOOST_COMMON_TYPE_STATIC_ASSERT(sizeof(T) > 0, BOOST_COMMON_TYPE_MUST_BE_A_COMPLE_TYPE, (T));
92     public:
93         typedef T type;
94     };
95
96 // 2 args
97 namespace type_traits_detail {
98
99     template <class T, class U>
100     struct common_type_2
101     {
102     private:
103         BOOST_COMMON_TYPE_STATIC_ASSERT(sizeof(T) > 0, BOOST_COMMON_TYPE_MUST_BE_A_COMPLE_TYPE, (T));
104         BOOST_COMMON_TYPE_STATIC_ASSERT(sizeof(U) > 0, BOOST_COMMON_TYPE_MUST_BE_A_COMPLE_TYPE, (U));
105         static bool declval_bool();  // workaround gcc bug; not required by std
106         static typename add_rvalue_reference<T>::type declval_T();  // workaround gcc bug; not required by std
107         static typename add_rvalue_reference<U>::type declval_U();  // workaround gcc bug; not required by std
108         static typename add_rvalue_reference<bool>::type declval_b();  
109
110 #if !defined(BOOST_NO_DECLTYPE)
111     public:
112         typedef decltype(declval<bool>() ? declval<T>() : declval<U>()) type;
113 #elif defined(BOOST_COMMON_TYPE_DONT_USE_TYPEOF)
114     public:
115     typedef typename detail_type_traits_common_type::common_type_impl<
116           typename remove_cv<T>::type,
117           typename remove_cv<U>::type
118       >::type type;
119 #else
120     public:
121         typedef BOOST_TYPEOF_TPL(declval_b() ? declval_T() : declval_U()) type;
122 #endif
123
124 #if defined(__GNUC__) && __GNUC__ == 3 && (__GNUC_MINOR__ == 2 || __GNUC_MINOR__ == 3)
125     public:
126         void public_dummy_function_just_to_silence_warning();
127 #endif
128     };
129
130     template <class T>
131     struct common_type_2<T, T>
132     {
133         typedef T type;
134     };
135     }
136
137 #if !defined(BOOST_NO_VARIADIC_TEMPLATES)
138     template <class T, class U>
139     struct common_type<T, U>
140 #else
141     template <class T, class U>
142     struct common_type<T, U, void>
143 #endif
144     : public type_traits_detail::common_type_2<T,U>
145     { };
146
147
148 // 3 or more args
149 #if !defined(BOOST_NO_VARIADIC_TEMPLATES)
150     template<typename T, typename U, typename... V>
151     struct common_type<T, U, V...> {
152     public:
153         typedef typename common_type<typename common_type<T, U>::type, V...>::type type;
154     };
155 #endif
156 }  // namespace boost
157
158 #endif  // BOOST_TYPE_TRAITS_COMMON_TYPE_HPP