1#ifndef TATOOINE_TUPLE_H
2#define TATOOINE_TUPLE_H
10template <
typename... Ts>
13template <
typename Head,
typename... Tail>
15 template <std::
size_t I>
19 static auto constexpr size() {
return 1 +
sizeof...(Tail); }
21 template <
typename... Tail_>
22 tuple(Head&& head_, Tail_&&... tail_)
23 : head{std::move(head_)}, tail{std::
forward<Tail_>(tail_)...} {}
25 template <std::convertible_to<Head> Head_,
typename... Tail_>
26 tuple(Head_&& head_, Tail_&&... tail_)
27 : head{static_cast<Head>(std::
forward<Head_>(head_))},
28 tail{std::
forward<Tail_>(tail_)...} {}
37 template <typename T = Head>
39 return reinterpret_cast<T*
>(
this);
42 template <std::
size_t I>
requires (I <
size())
43 auto at()
const ->
auto const& {
44 if constexpr (I == 0) {
47 return tail.template at<I - 1>();
51 template <std::
size_t I>
requires (I <
size())
53 if constexpr (I == 0) {
56 return tail.template at<I - 1>();
60 template <std::invocable<Head> F>
61 requires(std::invocable<F, Tail>&&...)
64 tail.iterate(std::forward<F>(f));
67 template <std::invocable<Head> F>
68 requires(std::invocable<F, Tail>&&...)
70 f(
static_cast<Head const&
>(head));
71 tail.iterate(std::forward<F>(f));
75template <
typename Head,
typename... Tail>
78template <
typename Head>
80 static auto constexpr size() {
return 1;}
83 template <std::convertible_to<Head> Head_>
84 tuple(Head_&& head_) : head{static_cast<Head>(std::
forward<Head_>(head_))} {}
93 template <typename T = Head>
95 return reinterpret_cast<T*
>(
this);
98 template <std::
size_t I>
100 auto at()
const ->
auto const& {
return head; }
102 template <std::
size_t I>
104 auto at() ->
auto& {
return head; }
106 template <std::invocable<Head> F>
111 template <std::invocable<Head> F>
113 f(
static_cast<Head const&
>(head));
117template <
typename Head>
120template <std::size_t Idx,
typename... Ts>
122 return t.template at<Idx>();
125template <std::size_t Idx,
typename... Ts>
127 return t.template at<Idx>();
130template <
typename Tuple1,
typename Tuple2>
133template <
typename... TsTuple1,
typename... TsTuple2>
137template <
typename Tuple1,
typename Tuple2>
typename ith_type_impl< I, Types... >::type ith_type
Definition: ith_type.h:15
Definition: algorithm.h:6
typename get_impl< Container, I >::type get
Definition: get.h:11
typename tuple_concat_types_impl< Tuple1, Tuple2 >::type tuple_concat_types
Definition: tuple.h:139
auto size(vec< ValueType, N > const &v)
Definition: vec.h:148
static constexpr forward_tag forward
Definition: tags.h:9
T type
Definition: common_type.h:13
static auto constexpr size()
Definition: tuple.h:19
auto at() -> auto &
Definition: tuple.h:52
Head head
Definition: tuple.h:17
tuple(Head &&head_, Tail_ &&... tail_)
Definition: tuple.h:22
auto iterate(F &&f) const
Definition: tuple.h:69
auto iterate(F &&f)
Definition: tuple.h:62
tuple< Tail... > tail
Definition: tuple.h:18
tuple(tuple const &)=default
auto at() const -> auto const &
Definition: tuple.h:43
variadic::ith_type< I, Head, Tail... > type_at
Definition: tuple.h:16
tuple(tuple &&) noexcept=default
tuple(Head_ &&head_, Tail_ &&... tail_)
Definition: tuple.h:26
auto iterate(F &&f) const
Definition: tuple.h:112
tuple(tuple &&) noexcept=default
auto at() const -> auto const &
Definition: tuple.h:100
tuple(Head_ &&head_)
Definition: tuple.h:84
auto at() -> auto &
Definition: tuple.h:104
tuple(tuple const &)=default
static auto constexpr size()
Definition: tuple.h:80
Head head
Definition: tuple.h:81
auto iterate(F &&f)
Definition: tuple.h:107