]> git.donarmstrong.com Git - rsem.git/blob - boost/type_traits/common_type.hpp
Added error detection for cases such as a read's two mates having different names...
[rsem.git] / 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_CXX11_VARIADIC_TEMPLATES) && !defined(BOOST_COMMON_TYPE_ARITY)
23 #define BOOST_COMMON_TYPE_ARITY 3
24 #endif
25
26 //----------------------------------------------------------------------------//
27 #if defined(BOOST_NO_CXX11_DECLTYPE) && !defined(BOOST_COMMON_TYPE_DONT_USE_TYPEOF)
28 #include <boost/typeof/typeof.hpp>   // boost wonders never cease!
29 #endif
30
31 //----------------------------------------------------------------------------//
32 #ifndef BOOST_NO_CXX11_STATIC_ASSERT
33 #define BOOST_COMMON_TYPE_STATIC_ASSERT(CND, MSG, TYPES) static_assert(CND,MSG)
34 #elif defined(BOOST_COMMON_TYPE_USES_MPL_ASSERT)
35 #include <boost/mpl/assert.hpp>
36 #include <boost/mpl/bool.hpp>
37 #define BOOST_COMMON_TYPE_STATIC_ASSERT(CND, MSG, TYPES)                                 \
38     BOOST_MPL_ASSERT_MSG(boost::mpl::bool_< (CND) >::type::value, MSG, TYPES)
39 #else
40 #include <boost/static_assert.hpp>
41 #define BOOST_COMMON_TYPE_STATIC_ASSERT(CND, MSG, TYPES) BOOST_STATIC_ASSERT(CND)
42 #endif
43
44 #if !defined(BOOST_NO_CXX11_STATIC_ASSERT) || !defined(BOOST_COMMON_TYPE_USES_MPL_ASSERT)
45 #define BOOST_COMMON_TYPE_MUST_BE_A_COMPLE_TYPE "must be complete type"
46 #endif
47
48 #if defined(BOOST_NO_CXX11_DECLTYPE) && defined(BOOST_COMMON_TYPE_DONT_USE_TYPEOF)
49 #include <boost/type_traits/detail/common_type_imp.hpp>
50 #include <boost/type_traits/remove_cv.hpp>
51 #endif
52 #include <boost/mpl/if.hpp>
53 #include <boost/utility/declval.hpp>
54 #include <boost/type_traits/add_rvalue_reference.hpp>
55
56 //----------------------------------------------------------------------------//
57 //                                                                            //
58 //                           C++03 implementation of                          //
59 //             20.9.7.6 Other transformations [meta.trans.other]              //
60 //                          Written by Howard Hinnant                         //
61 //      Adapted for Boost by Beman Dawes, Vicente Botet and  Jeffrey Hellrung //
62 //                                                                            //
63 //----------------------------------------------------------------------------//
64
65 namespace boost {
66
67 // prototype
68 #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
69     template<typename... T>
70     struct common_type;
71 #else // or no specialization
72     template <class T, class U = void, class V = void>
73     struct common_type
74     {
75     public:
76         typedef typename common_type<typename common_type<T, U>::type, V>::type type;
77     };
78 #endif
79
80
81 // 1 arg
82     template<typename T>
83 #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
84     struct common_type<T>
85 #else
86     struct common_type<T, void, void>
87
88 #endif
89     {
90         BOOST_COMMON_TYPE_STATIC_ASSERT(sizeof(T) > 0, BOOST_COMMON_TYPE_MUST_BE_A_COMPLE_TYPE, (T));
91     public:
92         typedef T type;
93     };
94
95 // 2 args
96 namespace type_traits_detail {
97
98     template <class T, class U>
99     struct common_type_2
100     {
101     private:
102         BOOST_COMMON_TYPE_STATIC_ASSERT(sizeof(T) > 0, BOOST_COMMON_TYPE_MUST_BE_A_COMPLE_TYPE, (T));
103         BOOST_COMMON_TYPE_STATIC_ASSERT(sizeof(U) > 0, BOOST_COMMON_TYPE_MUST_BE_A_COMPLE_TYPE, (U));
104         static bool declval_bool();  // workaround gcc bug; not required by std
105         static typename add_rvalue_reference<T>::type declval_T();  // workaround gcc bug; not required by std
106         static typename add_rvalue_reference<U>::type declval_U();  // workaround gcc bug; not required by std
107         static typename add_rvalue_reference<bool>::type declval_b();  
108
109 #if !defined(BOOST_NO_CXX11_DECLTYPE)
110     public:
111         typedef decltype(declval<bool>() ? declval<T>() : declval<U>()) type;
112 #elif defined(BOOST_COMMON_TYPE_DONT_USE_TYPEOF)
113     public:
114     typedef typename detail_type_traits_common_type::common_type_impl<
115           typename remove_cv<T>::type,
116           typename remove_cv<U>::type
117       >::type type;
118 #else
119     public:
120         typedef BOOST_TYPEOF_TPL(declval_b() ? declval_T() : declval_U()) type;
121 #endif
122
123 #if defined(__GNUC__) && __GNUC__ == 3 && (__GNUC_MINOR__ == 2 || __GNUC_MINOR__ == 3)
124     public:
125         void public_dummy_function_just_to_silence_warning();
126 #endif
127     };
128
129     template <class T>
130     struct common_type_2<T, T>
131     {
132         typedef T type;
133     };
134     }
135
136 #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
137     template <class T, class U>
138     struct common_type<T, U>
139 #else
140     template <class T, class U>
141     struct common_type<T, U, void>
142 #endif
143     : public type_traits_detail::common_type_2<T,U>
144     { };
145
146
147 // 3 or more args
148 #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
149     template<typename T, typename U, typename... V>
150     struct common_type<T, U, V...> {
151     public:
152         typedef typename common_type<typename common_type<T, U>::type, V...>::type type;
153     };
154 #endif
155 }  // namespace boost
156
157 #endif  // BOOST_TYPE_TRAITS_COMMON_TYPE_HPP