16 #ifndef OPENKALMAN_COLLECTIONS_VIEWS_FROM_TUPLE_HPP 17 #define OPENKALMAN_COLLECTIONS_VIEWS_FROM_TUPLE_HPP 31 template<
typename D,
typename = std::make_index_sequence<size_of_v<D>>>
38 using element_type = std::size_t;
40 static constexpr element_type
43 static constexpr std::array<decltype(call_table_get), 0>
48 template<
typename D, std::size_t...is>
51 using element_type = std::decay_t<common_collection_type_t<D>>;
53 template<std::
size_t i>
57 return static_cast<element_type
>(get<i>(box));
60 static constexpr std::array
61 value {call_table_get<is>...};
69 #ifdef __cpp_lib_ranges 70 template<viewable_tuple_like Tup>
72 template<
typename Tup>
80 template<
bool Const,
typename T>
81 using maybe_const = std::conditional_t<Const, const T, T>;
94 using Parent = maybe_const<Const, from_tuple_like>;
99 using iterator_concept = std::random_access_iterator_tag;
100 using iterator_category = std::random_access_iterator_tag;
101 using value_type = maybe_const<Const, typename call_table::element_type>;
102 using difference_type = std::ptrdiff_t;
103 using reference =
typename call_table::element_type;
104 using pointer = void;
106 constexpr
iterator(Parent& p, std::size_t pos) : parent_ {std::addressof(p)}, current_{
static_cast<difference_type
>(pos)} {}
107 constexpr iterator(
iterator<not Const> it) : parent_ {std::move(it.parent_)}, current_ {std::move(it.current_)} {}
108 constexpr decltype(
auto) operator*() {
return call_table::value[current_](parent_->tup_); }
109 constexpr decltype(
auto) operator*()
const {
return call_table::value[current_](parent_->tup_); }
110 constexpr decltype(
auto) operator[](difference_type offset) {
return call_table::value[current_ + offset](parent_->tup_); }
111 constexpr decltype(
auto) operator[](difference_type offset)
const {
return call_table::value[current_ + offset](parent_->tup_); }
112 constexpr
auto& operator++() { ++current_;
return *
this; }
113 constexpr
auto operator++(
int) {
auto temp = *
this; ++*
this;
return temp; }
114 constexpr
auto& operator--() { --current_;
return *
this; }
115 constexpr
auto operator--(
int) {
auto temp = *
this; --*
this;
return temp; }
116 constexpr
auto& operator+=(
const difference_type diff) { current_ += diff;
return *
this; }
117 constexpr
auto& operator-=(
const difference_type diff) { current_ -= diff;
return *
this; }
118 friend constexpr
auto operator+(
const iterator& it,
const difference_type diff)
119 {
return iterator {*it.parent_,
static_cast<std::size_t
>(it.current_ + diff)}; }
120 friend constexpr
auto operator+(
const difference_type diff,
const iterator& it)
121 {
return iterator {*it.parent_,
static_cast<std::size_t
>(diff + it.current_)}; }
122 friend constexpr
auto operator-(
const iterator& it,
const difference_type diff)
123 {
if (it.current_ < diff)
throw std::out_of_range{
"Iterator out of range"};
return iterator {*it.parent_,
static_cast<std::size_t
>(it.current_ - diff)}; }
124 friend constexpr difference_type operator-(
const iterator& it,
const iterator& other)
125 {
return it.current_ - other.current_; }
126 friend constexpr
bool operator==(
const iterator& it,
const iterator& other)
127 {
return it.current_ == other.current_; }
128 #ifdef __cpp_impl_three_way_comparison 129 constexpr
auto operator<=>(
const iterator& other)
const {
return current_ <=> other.current_; }
131 constexpr
bool operator!=(
const iterator& other)
const {
return current_ != other.current_; }
132 constexpr
bool operator<(
const iterator& other)
const {
return current_ < other.current_; }
133 constexpr
bool operator>(
const iterator& other)
const {
return current_ > other.current_; }
134 constexpr
bool operator<=(
const iterator& other)
const {
return current_ <= other.current_; }
135 constexpr
bool operator>=(
const iterator& other)
const {
return current_ >= other.current_; }
141 difference_type current_;
149 #ifdef __cpp_concepts 153 template<
bool Enable = true, std::enable_if_t<Enable and stdex::default_initializable<TupBox>,
int> = 0>
162 #ifdef __cpp_concepts 163 template<
typename Arg> requires (not std::same_as<stdex::remove_cvref_t<Arg>,
from_tuple_like>)
165 template<
typename Arg, std::enable_if_t<(not std::is_same_v<stdex::remove_cvref_t<Arg>, from_tuple_like>),
int> = 0>
199 constexpr
auto end()
const 208 static constexpr
auto 215 static constexpr
auto 218 if constexpr (size_of_v<Tup> == 0)
return std::true_type{};
219 else return std::false_type{};
226 constexpr decltype(
auto)
227 front() {
return collections::get<0>(tup_); }
230 constexpr decltype(
auto)
231 front()
const {
return collections::get<0>(tup_); }
237 constexpr decltype(
auto)
241 constexpr decltype(
auto)
249 #ifdef __cpp_explicit_this_parameter 250 template<
typename Self, values::index I>
251 constexpr decltype(
auto)
252 operator[](
this Self&&
self, I i) noexcept
258 template<
typename I, std::enable_if_t<values::index<I>,
int> = 0>
259 constexpr decltype(
auto)
266 template<
typename I, std::enable_if_t<values::index<I>,
int> = 0>
267 constexpr decltype(
auto)
268 operator[](I i)
const &
274 template<
typename I, std::enable_if_t<values::index<I>,
int> = 0>
275 constexpr decltype(
auto)
276 operator[](I i) && noexcept
282 template<
typename I, std::enable_if_t<values::index<I>,
int> = 0>
283 constexpr decltype(
auto)
284 operator[](I i)
const && noexcept
296 #ifdef __cpp_explicit_this_parameter 297 template<std::
size_t i>
298 constexpr decltype(
auto)
299 get(
this auto&&
self) noexcept
301 static_assert(i < size_of_v<Tup>,
"Index out of range");
302 return collections::get<i>(std::forward<decltype(self)>(
self).tup_);
305 template<std::
size_t i>
306 constexpr decltype(
auto)
309 static_assert(i < size_of_v<Tup>,
"Index out of range");
310 return collections::get<i>(tup_);
313 template<std::
size_t i>
314 constexpr decltype(
auto)
317 static_assert(i < size_of_v<Tup>,
"Index out of range");
318 return collections::get<i>(tup_);
321 template<std::
size_t i>
322 constexpr decltype(
auto)
325 static_assert(i < size_of_v<Tup>,
"Index out of range");
326 return collections::get<i>(std::move(*this).tup_);
329 template<std::
size_t i>
330 constexpr decltype(
auto)
331 get()
const && noexcept
333 static_assert(i < size_of_v<Tup>,
"Index out of range");
334 return collections::get<i>(std::move(*this).tup_);
345 template<
typename Tup>
351 #ifdef __cpp_lib_ranges 352 namespace std::ranges
357 template<
typename Tup>
358 constexpr
bool enable_borrowed_range<OpenKalman::collections::from_tuple_like<Tup>> =
359 std::is_lvalue_reference_v<Tup> or enable_borrowed_range<OpenKalman::stdex::remove_cvref_t<Tup>>;
365 template<
typename Tup>
366 struct tuple_size<
OpenKalman::collections::from_tuple_like<Tup>>
370 template<std::
size_t i,
typename Tup>
371 struct tuple_element<i, OpenKalman::collections::from_tuple_like<Tup>>
Namespace for collections.
Definition: collections.hpp:27
Definition for collections::get.
constexpr detail_get::get_impl< i > get
A generalization of std::get, where the index is known at compile time.
Definition: get.hpp:50
Definition of lexicographical_compare_three_way for collections.
constexpr from_tuple_like()
Default constructor.
Definition: from_tuple_like.hpp:155
Definition: tuple_wrapper.hpp:39
constexpr auto end() const
Definition: from_tuple_like.hpp:199
Header file for code relating to values (e.g., scalars and indices)
constexpr auto begin()
An iterator to the beginning of the tuple (treated as a std::ranges::range).
Definition: from_tuple_like.hpp:176
Definition for collections::size_of.
Iterator for from_tuple_like.
Definition: from_tuple_like.hpp:90
The fixed value associated with a fixed.
Definition: fixed_value_of.hpp:44
constexpr bool value
T is a fixed or dynamic value that is reducible to a number.
Definition: value.hpp:45
Definition: view_interface.hpp:32
constexpr auto end()
An iterator to the end of the tuple (treated as a std::ranges::range).
Definition: from_tuple_like.hpp:193
The root namespace for OpenKalman.
Definition: basics.hpp:34
A collection_view created from a viewable_tuple_like object.
Definition: from_tuple_like.hpp:74
Definition: from_tuple_like.hpp:32
constexpr bool size
T is either an index representing a size, or unbounded_size_t, which indicates that the size is unbou...
Definition: size.hpp:65
constexpr auto begin() const
Definition: from_tuple_like.hpp:182
The type of the element at a given index, if it can be determined at compile time.
Definition: collection_element.hpp:48
constexpr from_tuple_like(Arg &&arg) noexcept
Construct from a viewable_tuple_like object.
Definition: from_tuple_like.hpp:168
decltype(auto) constexpr get_element(Arg &&arg, I i)
A generalization of std::get and the range subscript operator.
Definition: get_element.hpp:122
static constexpr auto size()
The size of the resulting object.
Definition: from_tuple_like.hpp:209
Definition for collections::collection_element.
Definition for collections::common_collection_type.
static constexpr auto empty()
Definition: from_tuple_like.hpp:216