liuxiaolong
2021-07-20 58d904a328c0d849769b483e901a0be9426b8209
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
// Boost.Geometry
 
// Copyright (c) 2020, Oracle and/or its affiliates.
 
// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
 
// Licensed under the Boost Software License version 1.0.
// http://www.boost.org/users/license.html
 
#ifndef BOOST_GEOMETRY_UTIL_TYPE_TRAITS_STD_HPP
#define BOOST_GEOMETRY_UTIL_TYPE_TRAITS_STD_HPP
 
 
#include <cstddef>
#include <type_traits>
 
 
namespace boost { namespace geometry
{
 
 
namespace util
{
 
 
// C++17
template <bool B>
using bool_constant = std::integral_constant<bool, B>;
 
// non-standard
template <int I>
using int_constant = std::integral_constant<int, I>;
 
// non-standard
template <std::size_t I>
using index_constant = std::integral_constant<std::size_t, I>;
 
// non-standard
template <std::size_t S>
using size_constant = std::integral_constant<std::size_t, S>;
 
 
// C++17
template <typename ...>
struct conjunction
    : std::true_type
{};
template<typename Trait>
struct conjunction<Trait>
    : Trait
{};
template <typename Trait, typename ...Traits>
struct conjunction<Trait, Traits...>
    : std::conditional_t<Trait::value, conjunction<Traits...>, Trait>
{};
 
// C++17
template <typename ...>
struct disjunction
    : std::false_type
{};
template <typename Trait>
struct disjunction<Trait>
    : Trait
{};
template <typename Trait, typename ...Traits>
struct disjunction<Trait, Traits...>
    : std::conditional_t<Trait::value, Trait, disjunction<Traits...>>
{};
 
// C++17
template <typename Trait>
struct negation
    : bool_constant<!Trait::value>
{};
 
 
// non-standard
/*
template <typename ...Traits>
using and_ = conjunction<Traits...>;
 
template <typename ...Traits>
using or_ = disjunction<Traits...>;
 
template <typename Trait>
using not_ = negation<Trait>;
*/
 
 
// C++20
template <typename T>
struct remove_cvref
{
    using type = std::remove_cv_t<std::remove_reference_t<T>>;
};
 
template <typename T>
using remove_cvref_t = typename remove_cvref<T>::type;
 
// non-standard
template <typename T>
struct remove_cref
{
    using type = std::remove_const_t<std::remove_reference_t<T>>;
};
 
template <typename T>
using remove_cref_t = typename remove_cref<T>::type;
 
// non-standard
template <typename T>
struct remove_cptrref
{
    using type = std::remove_const_t
        <
            std::remove_pointer_t<std::remove_reference_t<T>>
        >;
};
 
template <typename T>
using remove_cptrref_t = typename remove_cptrref<T>::type;
 
 
// non-standard
template <typename From, typename To>
struct transcribe_const
{
    using type = std::conditional_t
                    <
                        std::is_const<std::remove_reference_t<From>>::value,
                        std::add_const_t<To>,
                        To
                    >;
};
 
template <typename From, typename To>
using transcribe_const_t = typename transcribe_const<From, To>::type;
 
 
} // namespace util
 
 
// Deprecated utilities, defined for backward compatibility but might be
// removed in the future.
 
 
/*!
    \brief Meta-function to define a const or non const type
    \ingroup utility
    \details If the boolean template parameter is true, the type parameter
        will be defined as const, otherwise it will be defined as it was.
        This meta-function is used to have one implementation for both
        const and non const references
    \note This traits class is completely independant from Boost.Geometry
        and might be a separate addition to Boost
    \note Used in a.o. for_each, interior_rings, exterior_ring
    \par Example
    \code
        void foo(typename add_const_if_c<IsConst, Point>::type& point)
    \endcode
*/
template <bool IsConst, typename Type>
struct add_const_if_c
{
    typedef std::conditional_t
        <
            IsConst,
            Type const,
            Type
        > type;
};
 
 
namespace util
{
 
template <typename T>
using bare_type = remove_cptrref<T>;
 
} // namespace util
 
 
}} // namespace boost::geometry
 
#endif // BOOST_GEOMETRY_UTIL_TYPE_TRAITS_STD_HPP