30 #ifndef BPSTD_UTILITY_HPP
31 #define BPSTD_UTILITY_HPP
33 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
35 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
37 #include "detail/config.hpp"
38 #include "detail/move.hpp"
44 BPSTD_COMPILER_DIAGNOSTIC_PREAMBLE
60 BPSTD_CPP17_INLINE constexpr
in_place_t in_place{};
76 #if BPSTD_HAS_TEMPLATE_VARIABLES
94 #if BPSTD_HAS_TEMPLATE_VARIABLES
95 template<std::
size_t I>
111 template <
typename T>
112 constexpr
typename bpstd::conditional<
113 !bpstd::is_nothrow_move_constructible<T>::value && bpstd::is_copy_constructible<T>::value,
116 >::type move_if_noexcept(T& x) noexcept;
122 template <
typename T>
123 constexpr add_const_t<T>& as_const(T& t) noexcept;
124 template <
typename T>
125 void as_const(
const T&&) =
delete;
137 template <
typename T,
typename U = T>
138 BPSTD_CPP14_CONSTEXPR T exchange(T& obj, U&& new_value);
144 template <
typename T,
typename U>
145 using pair = std::pair<T,U>;
156 template <std::
size_t N,
typename T,
typename U>
157 constexpr conditional_t<N==0,T,U>& get(pair<T, U>& p) noexcept;
158 template <std::
size_t N,
typename T,
typename U>
159 constexpr conditional_t<N==0,T,U>&& get(pair<T, U>&& p) noexcept;
160 template <std::
size_t N,
typename T,
typename U>
161 constexpr
const conditional_t<N==0,T,U>& get(
const pair<T, U>& p) noexcept;
162 template <std::
size_t N,
typename T,
typename U>
163 constexpr
const conditional_t<N==0,T,U>&& get(
const pair<T, U>&& p) noexcept;
165 template <
typename T,
typename U>
166 constexpr T& get(pair<T, U>& p) noexcept;
167 template <
typename T,
typename U>
168 constexpr T&& get(pair<T, U>&& p) noexcept;
169 template <
typename T,
typename U>
170 constexpr
const T& get(
const pair<T, U>& p) noexcept;
171 template <
typename T,
typename U>
172 constexpr
const T&& get(
const pair<T, U>&& p) noexcept;
174 template <
typename T,
typename U>
175 constexpr T& get(pair<U, T>& p) noexcept;
176 template <
typename T,
typename U>
177 constexpr
const T& get(
const pair<U, T>& p) noexcept;
178 template <
typename T,
typename U>
179 constexpr T&& get(pair<U, T>&& p) noexcept;
180 template <
typename T,
typename U>
181 constexpr
const T&& get(
const pair<U, T>&& p) noexcept;
187 template <
typename T, T... Ints>
190 using value_type = T;
192 static constexpr std::size_t size() noexcept {
return sizeof...(Ints); }
195 template <std::size_t... Ints>
199 template <
typename T,
bool End, T N, T...Tails>
200 struct make_integer_sequence_impl
201 : make_integer_sequence_impl<T,((N-1) == T(0)), N-1, N-1, Tails...>{};
203 template <
typename T, T N, T...Tails>
204 struct make_integer_sequence_impl<T, true, N, Tails...>
205 : type_identity<integer_sequence<T, Tails...>>{};
209 template <
typename T, T N>
210 using make_integer_sequence
211 =
typename detail::make_integer_sequence_impl<T, (N==T(0)), N>::type;
213 template<std::
size_t N>
214 using make_index_sequence = make_integer_sequence<std::size_t, N>;
216 template<
typename... T>
217 using index_sequence_for = make_index_sequence<
sizeof...(T)>;
229 template <
typename T>
230 inline BPSTD_INLINE_VISIBILITY constexpr
231 typename bpstd::conditional<
232 !bpstd::is_nothrow_move_constructible<T>::value && bpstd::is_copy_constructible<T>::value,
238 using result_type = conditional_t<
239 !is_nothrow_move_constructible<T>::value && is_copy_constructible<T>::value,
244 return static_cast<result_type
>(x);
247 template <
typename T>
248 inline BPSTD_INLINE_VISIBILITY constexpr
249 bpstd::add_const_t<T>& bpstd::as_const(T& t)
255 template <
typename T,
typename U>
256 inline BPSTD_INLINE_VISIBILITY BPSTD_CPP14_CONSTEXPR
259 auto old_value = bpstd::move(obj);
260 obj = bpstd::forward<U>(new_value);
272 template <std::
size_t N,
typename T,
typename U>
273 inline BPSTD_INLINE_VISIBILITY constexpr
274 bpstd::conditional_t<N==0,T,U>&
278 static_assert(N<=1,
"N must be either 0 or 1 for get<N>(pair<T,U>)");
280 return std::get<N>(p);
283 template <std::
size_t N,
typename T,
typename U>
284 inline BPSTD_INLINE_VISIBILITY constexpr
285 bpstd::conditional_t<N==0,T,U>&&
289 static_assert(N<=1,
"N must be either 0 or 1 for get<N>(pair<T,U>)");
291 return move(std::get<N>(p));
294 template <std::
size_t N,
typename T,
typename U>
295 inline BPSTD_INLINE_VISIBILITY constexpr
296 const bpstd::conditional_t<N==0,T,U>&
300 static_assert(N<=1,
"N must be either 0 or 1 for get<N>(pair<T,U>)");
302 return std::get<N>(p);
305 template <std::
size_t N,
typename T,
typename U>
306 inline BPSTD_INLINE_VISIBILITY constexpr
307 const bpstd::conditional_t<N==0,T,U>&&
311 static_assert(N<=1,
"N must be either 0 or 1 for get<N>(pair<T,U>)");
313 return move(std::get<N>(p));
316 template <
typename T,
typename U>
317 inline BPSTD_INLINE_VISIBILITY constexpr
324 template <
typename T,
typename U>
325 inline BPSTD_INLINE_VISIBILITY constexpr
332 template <
typename T,
typename U>
333 inline BPSTD_INLINE_VISIBILITY constexpr
337 return move(p.first);
340 template <
typename T,
typename U>
341 inline BPSTD_INLINE_VISIBILITY constexpr
345 return move(p.first);
348 template <
typename T,
typename U>
349 inline BPSTD_INLINE_VISIBILITY constexpr
356 template <
typename T,
typename U>
357 inline BPSTD_INLINE_VISIBILITY constexpr
364 template <
typename T,
typename U>
365 inline BPSTD_INLINE_VISIBILITY constexpr
369 return move(p.second);
372 template <
typename T,
typename U>
373 inline BPSTD_INLINE_VISIBILITY constexpr
377 return move(p.second);
380 BPSTD_COMPILER_DIAGNOSTIC_POSTAMBLE