-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon_type.hpp
87 lines (61 loc) · 1.95 KB
/
common_type.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#ifndef BOOST_TYPE_TRAITS_COMMON_TYPE_HPP_INCLUDED
#define BOOST_TYPE_TRAITS_COMMON_TYPE_HPP_INCLUDED
//
// Copyright 2015 Peter Dimov
//
// Distributed under the Boost Software License, Version 1.0.
// See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt
//
#include <boost/type_traits/decay.hpp>
#include <boost/utility/declval.hpp>
#if defined(BOOST_NO_CXX11_DECLTYPE)
#include "common_type_impl.hpp"
#endif
namespace boost
{
// variadic common_type
#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
template<class... T> struct common_type
{
};
template<class T1, class T2, class... T>
struct common_type<T1, T2, T...>: common_type<typename common_type<T1, T2>::type, T...>
{
};
#else
template<
class T1 = void, class T2 = void, class T3 = void,
class T4 = void, class T5 = void, class T6 = void,
class T7 = void, class T8 = void, class T9 = void
>
struct common_type: common_type<typename common_type<T1, T2>::type, T3, T4, T5, T6, T7, T8, T9>
{
};
#endif // !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
// one argument
template<class T> struct common_type<T>: boost::decay<T>
{
};
// two arguments
namespace type_traits_detail
{
// binary common_type
#if !defined(BOOST_NO_CXX11_DECLTYPE)
template<class T1, class T2> struct common_type_impl: boost::decay<decltype( boost::declval<bool>()? boost::declval<T1>(): boost::declval<T2>() )>
{
};
#endif // #if !defined(BOOST_NO_CXX11_DECLTYPE)
// decay helper
template<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>
{
};
template<class T1, class T2> struct common_type_decay_helper<T1, T2, T1, T2>: common_type_impl<T1, T2>
{
};
} // type_traits_detail
template<class T1, class T2> struct common_type<T1, T2>: type_traits_detail::common_type_decay_helper<T1, T2>
{
};
} // namespace boost
#endif // #ifndef BOOST_TYPE_TRAITS_COMMON_TYPE_HPP_INCLUDED