12#ifndef __AUDACITY_TUPLE__
13#define __AUDACITY_TUPLE__
22template<
typename T>
struct is_tuple : std::false_type{};
28template<
typename T,
typename =
void>
struct is_tuple_like : std::false_type{};
32 std::void_t<decltype(std::tuple_size<T>{})>
38template<
typename Tuple>
constexpr bool Empty_v =
39 (0 == size_t(std::tuple_size_v<Tuple>));
41template<
typename Tuple> [[nodiscard]]
constexpr bool Empty(
const Tuple &tuple)
43 return Empty_v<Tuple>;
50 std::index_sequence<Indices...>
51> : std::index_sequence<Indices + 1 ...> {};
54template<
size_t... Indices1,
size_t... Indices2>
56 std::index_sequence<Indices1...>, std::index_sequence<Indices2...>
58 static constexpr auto value = ((Indices1 < Indices2) && ...);
61constexpr size_t npos( -1 );
64template<>
struct increasing<> {
static constexpr auto value =
true; };
66 static constexpr auto value =
true;
68template<
size_t Index,
size_t... Indices>
struct increasing<Index, Indices...> {
70 std::index_sequence<Index, Indices...>,
71 std::index_sequence<Indices...,
npos>
77template<
size_t... Indices>
constexpr auto Project = [](
auto &&tuple)
79 using Tuple =
decltype(tuple);
80 constexpr auto size = std::tuple_size_v<std::remove_reference_t<Tuple>>;
81 static_assert(((Indices <
size) && ...),
"Indices must be in range");
86 "Indices must be strictly increasing");
87 return std::make_tuple(std::get<Indices>(std::forward<Tuple>(tuple))...);
92 const std::index_sequence<Indices...> &,
Tuple &&tuple)
94 return Project<Indices...>(std::forward<Tuple>(tuple));
100 using Tuple =
decltype(tuple);
101 constexpr auto size = std::tuple_size_v<std::remove_reference_t<Tuple>>;
102 static_assert(((Indices <
size) && ...),
"Indices must be in range");
107 "Indices must be strictly increasing");
109 std::forward_as_tuple(std::get<Indices>(std::forward<Tuple>(tuple))...);
114 const std::index_sequence<Indices...> &,
Tuple &&tuple)
121 constexpr auto Length = std::tuple_size_v<std::decay_t<Tuple>>;
123 std::make_index_sequence<Length>{}, std::forward<Tuple>(tuple));
127template<
typename Tuple>
using All_t =
decltype(
All(std::declval<Tuple>()));
131 constexpr auto Length = std::tuple_size_v<std::decay_t<Tuple>>;
133 std::make_index_sequence<Length>{}, std::forward<Tuple>(tuple));
141template<
typename Tuple,
142 typename Decayed = std::decay_t<Tuple>,
143 auto Length = std::tuple_size_v<Decayed>,
144 typename sfinae = std::enable_if_t<(
Length > 0)>
149 std::forward<Tuple>(tuple));
153template<
typename Tuple>
using Next_t =
decltype(
Next(std::declval<Tuple>()));
156template<
typename Tuple,
157 typename Decayed = std::decay_t<Tuple>,
158 auto Length = std::tuple_size_v<Decayed>,
159 typename sfinae = std::enable_if_t<(
Length > 0)>
164 std::forward<Tuple>(tuple));
std::vector< Type > Types
constexpr size_t npos(-1)
decltype(All(std::declval< Tuple >())) All_t
Type of projection of all of a tuple.
decltype(Next(std::declval< Tuple >())) Next_t
Type of projection of the tail of a tuple.
constexpr bool Empty(const Tuple &tuple)
constexpr auto ForwardProject
Forwarding of a subsequence of a tuple.
auto Next(Tuple &&tuple)
Projection of the tail of a tuple.
decltype(ForwardAll(std::declval< Tuple >())) ForwardAll_t
Type of forwarding references to all members of a tuple.
constexpr auto ForwardingProjection(const std::index_sequence< Indices... > &, Tuple &&tuple)
Destructures a std::index_sequence argument.
static constexpr auto is_tuple_v
decltype(ForwardNext(std::declval< Tuple >())) ForwardNext_t
Type of forwarding references to tail members of a tuple.
auto Projection(const std::index_sequence< Indices... > &, Tuple &&tuple)
Destructures a std::index_sequence argument.
auto All(Tuple &&tuple)
Projection of all of a tuple.
static constexpr auto is_tuple_like_v
auto ForwardNext(Tuple &&tuple)
Forwarding of the tail of a tuple.
auto ForwardAll(Tuple &&tuple)
Forwarding of all of a tuple.
constexpr auto Project
Return a tuple of values initialized from a subsequence of a tuple.
Type test metapredicate, for more general tuple-like types.
Type test metapredicate, for specializations of std::tuple only.