-
Notifications
You must be signed in to change notification settings - Fork 0
/
composite_pointer_type.hpp
145 lines (104 loc) · 3.23 KB
/
composite_pointer_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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#ifndef BOOST_TYPE_TRAITS_DETAIL_COMPOSITE_POINTER_TYPE_HPP_INCLUDED
#define BOOST_TYPE_TRAITS_DETAIL_COMPOSITE_POINTER_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 "copy_cv.hpp"
#include "tp_identity.hpp"
#include <boost/type_traits/remove_cv.hpp>
#include <boost/type_traits/is_same.hpp>
#include <boost/type_traits/is_void.hpp>
#include <boost/type_traits/is_base_of.hpp>
#include <boost/config.hpp>
#include <cstddef>
namespace boost
{
namespace type_traits_detail
{
template<class T, class U> struct composite_pointer_type;
// same type
template<class T> struct composite_pointer_type<T*, T*>
{
typedef T* type;
};
// nullptr_t
#if !defined( BOOST_NO_CXX11_NULLPTR )
#if !defined( BOOST_NO_CXX11_DECLTYPE ) && ( ( defined( __clang__ ) && !defined( _LIBCPP_VERSION ) ) || defined( __INTEL_COMPILER ) )
template<class T> struct composite_pointer_type<T*, decltype(nullptr)>
{
typedef T* type;
};
template<class T> struct composite_pointer_type<decltype(nullptr), T*>
{
typedef T* type;
};
template<> struct composite_pointer_type<decltype(nullptr), decltype(nullptr)>
{
typedef decltype(nullptr) type;
};
#else
template<class T> struct composite_pointer_type<T*, std::nullptr_t>
{
typedef T* type;
};
template<class T> struct composite_pointer_type<std::nullptr_t, T*>
{
typedef T* type;
};
template<> struct composite_pointer_type<std::nullptr_t, std::nullptr_t>
{
typedef std::nullptr_t type;
};
#endif
#endif // !defined( BOOST_NO_CXX11_NULLPTR )
namespace detail
{
template<class T, class U> struct has_common_pointee
{
private:
typedef typename boost::remove_cv<T>::type T2;
typedef typename boost::remove_cv<U>::type U2;
public:
BOOST_STATIC_CONSTANT( bool, value =
(boost::is_same<T2, U2>::value)
|| boost::is_void<T2>::value
|| boost::is_void<U2>::value
|| (boost::is_base_of<T2, U2>::value)
|| (boost::is_base_of<U2, T2>::value) );
};
template<class T, class U> struct common_pointee
{
private:
typedef typename boost::remove_cv<T>::type T2;
typedef typename boost::remove_cv<U>::type U2;
public:
typedef typename boost::conditional<
boost::is_same<T2, U2>::value || boost::is_void<T2>::value || boost::is_base_of<T2, U2>::value,
typename boost::copy_cv<T, U>::type,
typename boost::copy_cv<U, T>::type
>::type type;
};
template<class T, class U> struct composite_pointer_impl
{
private:
typedef typename boost::remove_cv<T>::type T2;
typedef typename boost::remove_cv<U>::type U2;
public:
typedef typename boost::copy_cv<typename boost::copy_cv<typename composite_pointer_type<T2, U2>::type const, T>::type, U>::type type;
};
} // detail
template<class T, class U> struct composite_pointer_type<T*, U*>
{
typedef typename boost::conditional<
detail::has_common_pointee<T, U>::value,
detail::common_pointee<T, U>,
detail::composite_pointer_impl<T, U>
>::type::type * type;
};
} // namespace type_traits_detail
} // namespace boost
#endif // #ifndef BOOST_TYPE_TRAITS_DETAIL_COMPOSITE_POINTER_TYPE_HPP_INCLUDED