1// Boost.Geometry
2
3// Copyright (c) 2020, Oracle and/or its affiliates.
4
5// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
6
7// Licensed under the Boost Software License version 1.0.
8// http://www.boost.org/users/license.html
9
10#ifndef BOOST_GEOMETRY_UTIL_TYPE_TRAITS_STD_HPP
11#define BOOST_GEOMETRY_UTIL_TYPE_TRAITS_STD_HPP
12
13
14#include <cstddef>
15#include <type_traits>
16
17
18namespace boost { namespace geometry
19{
20
21
22namespace util
23{
24
25
26// C++17
27template <bool B>
28using bool_constant = std::integral_constant<bool, B>;
29
30// non-standard
31template <int I>
32using int_constant = std::integral_constant<int, I>;
33
34// non-standard
35template <std::size_t I>
36using index_constant = std::integral_constant<std::size_t, I>;
37
38// non-standard
39template <std::size_t S>
40using size_constant = std::integral_constant<std::size_t, S>;
41
42
43// C++17
44template <typename ...>
45struct conjunction
46 : std::true_type
47{};
48template<typename Trait>
49struct conjunction<Trait>
50 : Trait
51{};
52template <typename Trait, typename ...Traits>
53struct conjunction<Trait, Traits...>
54 : std::conditional_t<Trait::value, conjunction<Traits...>, Trait>
55{};
56
57// C++17
58template <typename ...>
59struct disjunction
60 : std::false_type
61{};
62template <typename Trait>
63struct disjunction<Trait>
64 : Trait
65{};
66template <typename Trait, typename ...Traits>
67struct disjunction<Trait, Traits...>
68 : std::conditional_t<Trait::value, Trait, disjunction<Traits...>>
69{};
70
71// C++17
72template <typename Trait>
73struct negation
74 : bool_constant<!Trait::value>
75{};
76
77
78// non-standard
79/*
80template <typename ...Traits>
81using and_ = conjunction<Traits...>;
82
83template <typename ...Traits>
84using or_ = disjunction<Traits...>;
85
86template <typename Trait>
87using not_ = negation<Trait>;
88*/
89
90
91// C++20
92template <typename T>
93struct remove_cvref
94{
95 using type = std::remove_cv_t<std::remove_reference_t<T>>;
96};
97
98template <typename T>
99using remove_cvref_t = typename remove_cvref<T>::type;
100
101// non-standard
102template <typename T>
103struct remove_cref
104{
105 using type = std::remove_const_t<std::remove_reference_t<T>>;
106};
107
108template <typename T>
109using remove_cref_t = typename remove_cref<T>::type;
110
111// non-standard
112template <typename T>
113struct remove_cptrref
114{
115 using type = std::remove_const_t
116 <
117 std::remove_pointer_t<std::remove_reference_t<T>>
118 >;
119};
120
121template <typename T>
122using remove_cptrref_t = typename remove_cptrref<T>::type;
123
124
125// non-standard
126template <typename From, typename To>
127struct transcribe_const
128{
129 using type = std::conditional_t
130 <
131 std::is_const<std::remove_reference_t<From>>::value,
132 std::add_const_t<To>,
133 To
134 >;
135};
136
137template <typename From, typename To>
138using transcribe_const_t = typename transcribe_const<From, To>::type;
139
140
141// non-standard
142template <typename From, typename To>
143struct transcribe_reference
144{
145 using type = std::remove_reference_t<To>;
146};
147
148template <typename From, typename To>
149struct transcribe_reference<From &, To>
150{
151 using type = std::remove_reference_t<To> &;
152};
153
154template <typename From, typename To>
155struct transcribe_reference<From &&, To>
156{
157 using type = std::remove_reference_t<To> &&;
158};
159
160template <typename From, typename To>
161using transcribe_reference_t = typename transcribe_reference<From, To>::type;
162
163
164// non-standard
165template <typename From, typename To>
166struct transcribe_cref
167{
168 using type = transcribe_reference_t<From, transcribe_const_t<From, To>>;
169};
170
171template <typename From, typename To>
172using transcribe_cref_t = typename transcribe_cref<From, To>::type;
173
174
175} // namespace util
176
177
178// Deprecated utilities, defined for backward compatibility but might be
179// removed in the future.
180
181
182/*!
183 \brief Meta-function to define a const or non const type
184 \ingroup utility
185 \details If the boolean template parameter is true, the type parameter
186 will be defined as const, otherwise it will be defined as it was.
187 This meta-function is used to have one implementation for both
188 const and non const references
189 \note This traits class is completely independant from Boost.Geometry
190 and might be a separate addition to Boost
191 \note Used in a.o. for_each, interior_rings, exterior_ring
192 \par Example
193 \code
194 void foo(typename add_const_if_c<IsConst, Point>::type& point)
195 \endcode
196*/
197template <bool IsConst, typename Type>
198struct add_const_if_c
199{
200 typedef std::conditional_t
201 <
202 IsConst,
203 Type const,
204 Type
205 > type;
206};
207
208
209namespace util
210{
211
212template <typename T>
213using bare_type = remove_cptrref<T>;
214
215} // namespace util
216
217
218}} // namespace boost::geometry
219
220#endif // BOOST_GEOMETRY_UTIL_TYPE_TRAITS_STD_HPP
221

source code of boost/libs/geometry/include/boost/geometry/util/type_traits_std.hpp