1#ifndef BOOST_TYPE_TRAITS_COMMON_TYPE_HPP_INCLUDED
2#define BOOST_TYPE_TRAITS_COMMON_TYPE_HPP_INCLUDED
3
4//
5// Copyright 2015 Peter Dimov
6//
7// Distributed under the Boost Software License, Version 1.0.
8// See accompanying file LICENSE_1_0.txt or copy at
9// http://www.boost.org/LICENSE_1_0.txt
10//
11
12#include <boost/config.hpp>
13#include <boost/type_traits/decay.hpp>
14#include <boost/type_traits/declval.hpp>
15#include <boost/detail/workaround.hpp>
16#include <boost/type_traits/is_complete.hpp>
17#include <boost/type_traits/is_void.hpp>
18#include <boost/type_traits/is_array.hpp>
19#include <boost/static_assert.hpp>
20
21#if defined(BOOST_NO_CXX11_DECLTYPE)
22#include <boost/type_traits/detail/common_type_impl.hpp>
23#endif
24
25#if !defined(BOOST_NO_CXX11_TEMPLATE_ALIASES) && !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
26#include <boost/type_traits/detail/mp_defer.hpp>
27#endif
28
29namespace boost
30{
31
32// variadic common_type
33
34#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
35
36template<class... T> struct common_type
37{
38};
39
40#if !defined(BOOST_NO_CXX11_TEMPLATE_ALIASES)
41
42template<class... T> using common_type_t = typename common_type<T...>::type;
43
44namespace type_traits_detail
45{
46
47template<class T1, class T2, class... T> using common_type_fold = common_type_t<common_type_t<T1, T2>, T...>;
48
49} // namespace type_traits_detail
50
51template<class T1, class T2, class... T>
52struct common_type<T1, T2, T...>: type_traits_detail::mp_defer<type_traits_detail::common_type_fold, T1, T2, T...>
53{
54};
55
56#else
57
58template<class T1, class T2, class... T>
59struct common_type<T1, T2, T...>: common_type<typename common_type<T1, T2>::type, T...>
60{
61};
62
63#endif // !defined(BOOST_NO_CXX11_TEMPLATE_ALIASES)
64
65#else
66
67template<
68 class T1 = void, class T2 = void, class T3 = void,
69 class T4 = void, class T5 = void, class T6 = void,
70 class T7 = void, class T8 = void, class T9 = void
71>
72struct common_type: common_type<typename common_type<T1, T2>::type, T3, T4, T5, T6, T7, T8, T9>
73{
74};
75
76#endif // !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
77
78// one argument
79
80template<class T> struct common_type<T>: boost::decay<T>
81{
82 BOOST_STATIC_ASSERT_MSG(::boost::is_complete<T>::value || ::boost::is_void<T>::value || ::boost::is_array<T>::value, "Arguments to common_type must both be complete types");
83};
84
85// two arguments
86
87namespace type_traits_detail
88{
89
90// binary common_type
91
92#if !defined(BOOST_NO_CXX11_DECLTYPE)
93
94#if !defined(BOOST_NO_CXX11_TEMPLATE_ALIASES) && !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
95
96#if !defined(BOOST_MSVC) || BOOST_MSVC > 1800
97
98// internal compiler error on msvc-12.0
99
100template<class T1, class T2> using builtin_common_type = typename boost::decay<decltype( boost::declval<bool>()? boost::declval<T1>(): boost::declval<T2>() )>::type;
101
102template<class T1, class T2> struct common_type_impl: mp_defer<builtin_common_type, T1, T2>
103{
104};
105
106#else
107
108template<class T1, class T2> using builtin_common_type = decltype( boost::declval<bool>()? boost::declval<T1>(): boost::declval<T2>() );
109
110template<class T1, class T2> struct common_type_impl_2: mp_defer<builtin_common_type, T1, T2>
111{
112};
113
114template<class T1, class T2> using decay_common_type = typename boost::decay<typename common_type_impl_2<T1, T2>::type>::type;
115
116template<class T1, class T2> struct common_type_impl: mp_defer<decay_common_type, T1, T2>
117{
118};
119
120#endif // !defined(BOOST_MSVC) || BOOST_MSVC > 1800
121
122#else
123
124template<class T1, class T2> struct common_type_impl: boost::decay<decltype( boost::declval<bool>()? boost::declval<T1>(): boost::declval<T2>() )>
125{
126};
127
128#endif // #if !defined(BOOST_NO_CXX11_TEMPLATE_ALIASES) && !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
129
130#endif // #if !defined(BOOST_NO_CXX11_DECLTYPE)
131
132// decay helper
133
134template<class T1, class T2, class T1d = typename boost::decay<T1>::type, class T2d = typename boost::decay<T2>::type> struct common_type_decay_helper: boost::common_type<T1d, T2d>
135{
136};
137
138template<class T1, class T2> struct common_type_decay_helper<T1, T2, T1, T2>: common_type_impl<T1, T2>
139{
140};
141
142} // type_traits_detail
143
144template<class T1, class T2> struct common_type<T1, T2>: type_traits_detail::common_type_decay_helper<T1, T2>
145{
146 BOOST_STATIC_ASSERT_MSG(::boost::is_complete<T1>::value || ::boost::is_void<T1>::value || ::boost::is_array<T1>::value, "Arguments to common_type must both be complete types");
147 BOOST_STATIC_ASSERT_MSG(::boost::is_complete<T2>::value || ::boost::is_void<T2>::value || ::boost::is_array<T2>::value, "Arguments to common_type must both be complete types");
148};
149
150} // namespace boost
151
152#endif // #ifndef BOOST_TYPE_TRAITS_COMMON_TYPE_HPP_INCLUDED
153

source code of boost/libs/type_traits/include/boost/type_traits/common_type.hpp