9#ifndef STLAB_UTILITY_HPP
10#define STLAB_UTILITY_HPP
18#include <stlab/config.hpp>
22#include <initializer_list>
29STLAB_VERSION_NAMESPACE_BEGIN()
42template <
bool,
class T>
46struct move_if_helper<true, T> {
47 using type = std::remove_reference_t<T>&&;
51struct move_if_helper<false, T> {
52 using type = std::remove_reference_t<T>&;
55template <
bool P,
class T>
56using move_if_helper_t =
typename move_if_helper<P, T>::type;
64template <
class Seq1,
class Seq2>
67template <std::size_t... N1, std::size_t... N2>
69 using type = std::index_sequence<N1..., N2...>;
72template <
class Seq1,
class Seq2>
80template <std::size_t... N>
82 static constexpr std::array<std::size_t,
sizeof...(N)> value{{N...}};
87template <
class Seq,
template <std::
size_t>
class F, std::size_t Index, std::size_t Count>
91 template <std::
size_t>
class F,
92 std::size_t Index = 0,
93 std::size_t Count = Seq::size()>
94using index_sequence_transform_t =
typename index_sequence_transform<Seq, F, Index, Count>::type;
96template <
class Seq,
template <std::
size_t>
class F, std::size_t Index, std::size_t Count>
98 using type = index_sequence_cat_t<
99 index_sequence_transform_t<Seq, F, Index, Count / 2>,
100 index_sequence_transform_t<Seq, F, Index + Count / 2, Count - Count / 2>>;
103template <
class Seq,
template <std::
size_t>
class F, std::size_t Index>
105 using type = std::index_sequence<>;
108template <
class Seq,
template <std::
size_t>
class F, std::size_t Index>
110 using type =
typename F<index_sequence_to_array<Seq>::value[Index]>::type;
116template <
bool P,
class T>
117constexpr auto move_if(T&& t)
noexcept -> detail::move_if_helper_t<P, T> {
118 return static_cast<detail::move_if_helper_t<P, T>
>(t);
126template <
class F,
class... Args>
128 return (
void)std::initializer_list<int>{(std::forward<F>(f)(args), 0)...};
144constexpr auto copy(T&& value)
noexcept(
noexcept(std::decay_t<T>{
static_cast<T&&
>(value)}))
146 static_assert(!std::is_same_v<std::decay_t<T>, T>,
"explicit copy of rvalue.");
147 return std::decay_t<T>{
static_cast<T&&
>(value)};
154constexpr auto move(T&& t)
noexcept -> std::remove_reference_t<T>&& {
155 static_assert(!std::is_const_v<std::remove_reference_t<T>>,
156 "move of const type will unintentionally decay to copy");
157 return static_cast<std::remove_reference_t<T>&&
>(t);
164STLAB_VERSION_NAMESPACE_END()
constexpr auto copy(T &&value) noexcept(noexcept(std::decay_t< T >{static_cast< T && >(value)})) -> std::decay_t< T >
Returns a copy of the argument. Used to pass an lvalue to a function taking an rvalue,...
Definition utility.hpp:144
constexpr auto move_if(T &&t) noexcept -> detail::move_if_helper_t< P, T >
If P is true, casts t to an rvalue; otherwise keeps an lvalue reference.
Definition utility.hpp:117
constexpr auto move(T &&t) noexcept -> std::remove_reference_t< T > &&
A standard move implementation but with a compile-time check for const types.
Definition utility.hpp:154
void for_each_argument(F &&f, Args &&... args)
Invokes f(arg0), f(arg1), … f(argN).
Definition utility.hpp:127
Definition reverse.hpp:28
Definition utility.hpp:65
Definition utility.hpp:78