12 #ifndef DOCWIRE_TUPLE_UTILS_H
13 #define DOCWIRE_TUPLE_UTILS_H
34 template <std::size_t Start, std::size_t Length,
typename... Ts>
35 auto subrange(
const std::tuple<Ts...>& tuple) {
36 if constexpr (Length == 0) {
37 return std::tuple<>();
39 static_assert(Start <
sizeof...(Ts),
"Start index out of range");
40 static_assert(Start + Length <=
sizeof...(Ts),
"Length out of range");
41 return std::tuple_cat(std::make_tuple(std::get<Start>(tuple)), subrange<Start + 1, Length - 1>(tuple));
51 template <std::
size_t Start, std::
size_t Length,
typename T>
52 using subrange_t = decltype(subrange<Start, Length>(std::declval<T>()));
65 static_assert(std::tuple_size_v<T> > 0,
"Cannot remove the first element of an empty tuple.");
66 return subrange<1, std::tuple_size_v<T> - 1>(tuple);
89 static_assert(std::tuple_size_v<T> > 0,
"Cannot remove the last element of an empty tuple.");
90 return subrange<0, std::tuple_size_v<T> - 1>(tuple);
108 template <
typename T>
110 static_assert(std::tuple_size_v<T> > 0,
"Cannot get the first element of an empty tuple.");
111 return std::get<0>(tuple);
120 template <
typename T>
129 template <
typename T>
131 static_assert(std::tuple_size_v<T> > 0,
"Cannot get the last element of an empty tuple.");
132 return std::get<std::tuple_size_v<T> - 1>(tuple);
141 template <
typename T>
Provides transformations for tuples.
decltype(last_element(std::declval< T >())) last_element_t
Type alias for the type of the last element of a tuple.
auto subrange(const std::tuple< Ts... > &tuple)
Returns subrange of a tuple.
decltype(remove_first(std::declval< T >())) remove_first_t
Type alias for the type of the result of removing the first element from a tuple.
auto last_element(T &&tuple)
Returns the last element of a tuple.
auto remove_last(T &&tuple)
Removes the last element from a tuple.
decltype(remove_last(std::declval< T >())) remove_last_t
Type alias for the type of the result of removing the last element from a tuple.
decltype(subrange< Start, Length >(std::declval< T >())) subrange_t
Type alias for the type of the result of subrange of a tuple.
decltype(first_element(std::declval< T >())) first_element_t
Type alias for the type of the first element of a tuple.
auto remove_first(T &&tuple)
Removes the first element from a tuple.
auto first_element(T &&tuple)
Returns the first element of a tuple.