Iros
 
Loading...
Searching...
No Matches
tuple_impl.h
Go to the documentation of this file.
1#pragma once
2
3#include "di/meta/constexpr.h"
4#include "di/meta/core.h"
6#include "di/meta/util.h"
8#include "di/util/declval.h"
13
14namespace di::vocab {
16
18
20
22
23template<typename Indices, typename... Types>
25
26namespace detail {
27 template<types::size_t index, typename Indices, typename... Types>
29
30 template<types::size_t... indices, typename... Types>
31 struct TupleImplBase<0, meta::ListV<indices...>, Types...> {
32 using Type = TupleImpl<meta::ListV<indices...>, Types...>;
33 };
34
35 template<types::size_t index_head, types::size_t... indices, types::size_t index_to_find, typename T,
36 typename... Rest>
37 requires(index_to_find != 0)
38 struct TupleImplBase<index_to_find, meta::ListV<index_head, indices...>, T, Rest...>
39 : TupleImplBase<index_to_find - 1, meta::ListV<indices...>, Rest...> {};
40
41}
42
43template<types::size_t index, types::size_t... indices, typename T, typename... Rest>
44class TupleImpl<meta::ListV<index, indices...>, T, Rest...> : public TupleImpl<meta::ListV<indices...>, Rest...> {
45private:
46 using Base = TupleImpl<meta::ListV<indices...>, Rest...>;
47
48public:
49 constexpr TupleImpl()
51 : m_value() {}
52
53 constexpr TupleImpl(TupleImpl const&) = default;
54 constexpr TupleImpl(TupleImpl&&) = default;
55
56 template<typename Arg, typename... Args>
57 constexpr TupleImpl(ConstructTupleImplValuewise, Arg&& arg, Args&&... args)
58 : Base(construct_tuple_impl_valuewise, util::forward<Args>(args)...), m_value(util::forward<Arg>(arg)) {}
59
60 template<concepts::TupleLike Tup>
61 requires(sizeof...(Rest) + 1 == meta::TupleSize<Tup> &&
64 // NOLINTBEGIN(bugprone-use-after-move)
66 : Base(construct_tuple_impl_valuewise, util::get<indices>(util::forward<Tup>(tuple))...)
67 , m_value(util::get<index>(util::forward<Tup>(tuple))) {}
68 // NOLINTEND(bugprone-use-after-move)
69
70 constexpr ~TupleImpl() = default;
71
72 constexpr auto operator=(TupleImpl const&) -> TupleImpl& = default;
73 constexpr auto operator=(TupleImpl&&) -> TupleImpl& = default;
74
75protected:
76 template<concepts::DecaySameAs<TupleImpl> Self>
77 constexpr static auto static_get(Self&& self) -> meta::Like<Self, T>&& {
78 return static_cast<meta::Like<Self, T>&&>(self.m_value);
79 }
80
81 template<concepts::DecaySameAs<TupleImpl> Self, concepts::TupleLike Tup>
82 requires(sizeof...(Rest) + 1 == meta::TupleSize<Tup> &&
86 constexpr static void static_assign(Self&& self, Tup&& other) {
87 self.m_value = util::get<index>(util::forward<Tup>(other));
88 // NOLINTNEXTLINE(bugprone-use-after-move)
89 Base::static_assign_unchecked(util::forward_as_base<Self, Base>(self), util::forward<Tup>(other));
90 }
91
92 template<typename Self, typename Tup>
93 constexpr static void static_assign_unchecked(Self&& self, Tup&& other) {
94 self.m_value = util::get<index>(util::forward<Tup>(other));
95 // NOLINTNEXTLINE(bugprone-use-after-move)
96 Base::static_assign_unchecked(util::forward_as_base<Self, Base>(self), util::forward<Tup>(other));
97 }
98
99private:
101};
102
103template<>
104class TupleImpl<meta::ListV<>> {
105public:
106 constexpr TupleImpl() = default;
107 constexpr TupleImpl(TupleImpl const&) = default;
108 constexpr TupleImpl(TupleImpl&&) = default;
109
111
112 constexpr ~TupleImpl() = default;
113
114 template<concepts::TupleLike T>
115 requires(meta::TupleSize<T> == 0)
117
118 constexpr auto operator=(TupleImpl const&) -> TupleImpl& = default;
119 constexpr auto operator=(TupleImpl&&) -> TupleImpl& = default;
120
121protected:
122 template<concepts::DecaySameAs<TupleImpl> Self, concepts::TupleLike Tup>
123 requires(meta::TupleSize<Tup> == 0 &&
125 constexpr static void static_assign(Self&&, Tup&&) {}
126
127 template<typename Self, typename Tup>
128 constexpr static void static_assign_unchecked(Self&&, Tup&&) {}
129};
130}
Definition tuple_impl.h:24
static constexpr void static_assign(Self &&self, Tup &&other)
Definition tuple_impl.h:86
constexpr TupleImpl(TupleImpl const &)=default
constexpr TupleImpl(ConstructTupleImplValuewise, Arg &&arg, Args &&... args)
Definition tuple_impl.h:57
static constexpr void static_assign_unchecked(Self &&, Tup &&)
Definition tuple_impl.h:128
constexpr TupleImpl(ConstructTupleImplValuewise)
Definition tuple_impl.h:110
constexpr auto operator=(TupleImpl &&) -> TupleImpl &=default
constexpr auto operator=(TupleImpl const &) -> TupleImpl &=default
constexpr TupleImpl(TupleImpl &&)=default
constexpr auto operator=(TupleImpl &&) -> TupleImpl &=default
constexpr auto operator=(TupleImpl const &) -> TupleImpl &=default
static constexpr void static_assign(Self &&, Tup &&)
Definition tuple_impl.h:125
constexpr TupleImpl(ConstructTupleImplFromTuplelike, T &&)
Definition tuple_impl.h:116
constexpr TupleImpl(ConstructTupleImplFromTuplelike, Tup &&tuple)
Definition tuple_impl.h:65
static constexpr auto static_get(Self &&self) -> meta::Like< Self, T > &&
Definition tuple_impl.h:77
static constexpr void static_assign_unchecked(Self &&self, Tup &&other)
Definition tuple_impl.h:93
#define DI_IMMOVABLE_NO_UNIQUE_ADDRESS
Definition compiler.h:15
Definition operations.h:19
Definition language.h:33
Definition operations.h:11
Definition operations.h:24
Definition language.h:47
Definition merge_interfaces.h:6
constexpr auto TupleSize
Definition tuple_size.h:23
decltype(util::get< index >(util::declval< Tup >())) TupleValue
Definition tuple_value.h:10
Type< detail::LikeHelper< T, U > > Like
Definition language.h:468
std::size_t size_t
Definition size_t.h:12
Definition vocab.h:96
constexpr auto get(T &&value) -> decltype(auto)
Definition get.h:8
constexpr auto forward_as_base(meta::RemoveReference< Derived > &derived) -> meta::Like< meta::RemoveReference< Derived > &, Base > &&
Definition forward_as_base.h:12
Definition erasure_cast.h:7
Definition lazy.h:165
constexpr auto construct_tuple_impl_from_tuplelike
Definition tuple_impl.h:21
constexpr auto construct_tuple_impl_valuewise
Definition tuple_impl.h:17
constexpr auto get(T &&value) -> decltype(auto)
Definition get.h:8
Definition core.h:8
Definition tuple_impl.h:15
Definition tuple_impl.h:28
TupleImpl< meta::ListV< indices... >, Types... > Type
Definition tuple_impl.h:32