16 #ifndef OPENKALMAN_VIEWS_CONCAT_HPP 17 #define OPENKALMAN_VIEWS_CONCAT_HPP 25 template<std::
size_t i>
26 constexpr
auto concat_tuple_view_indices()
28 return std::pair {std::integral_constant<std::size_t, 0_uz>{}, std::integral_constant<std::size_t, 0_uz>{}};
31 template<std::size_t i,
typename T,
typename...Ts>
32 constexpr
auto concat_tuple_view_indices()
34 constexpr std::size_t
size = std::tuple_size_v<std::decay_t<T>>;
35 if constexpr (i < size)
return std::pair {std::integral_constant<std::size_t, 0_uz>{}, std::integral_constant<std::size_t, i>{}};
38 auto [a, b] = concat_tuple_view_indices<i -
size, Ts...>();
39 return std::pair {std::integral_constant<std::size_t, 1_uz + decltype(a)::value>{}, b};
53 template<
typename...Ts>
58 constexpr
concat_tuple_view() requires (... and std::default_initializable<Ts>) =
default;
60 template<
typename Tup = std::tuple<Ts...>, std::enable_if_t<std::is_default_constructible_v<Tup>,
int> = 0>
66 template<
typename...Args> requires (... and std::constructible_from<Ts, Args&&>)
68 template<
typename...Args, std::enable_if_t<(... and std::is_constructible_v<Ts, Args&&>),
int> = 0>
70 explicit constexpr
concat_tuple_view(Args&&...args) : tup {std::forward<Args>(args)...} {}
77 template<std::
size_t i> requires (i < (0_uz + ... + std::tuple_size_v<std::decay_t<Ts>>))
79 template<std::size_t i, std::enable_if_t<(i < (0_uz + ... + std::tuple_size_v<std::decay_t<Ts>>)),
int> = 0>
81 friend constexpr decltype(
auto)
84 auto [element,
index] = std::decay_t<decltype(detail::concat_tuple_view_indices<i, Ts...>())>();
85 return get(
get(v.tup, element),
index);
93 template<std::
size_t i> requires (i < (0_uz + ... + std::tuple_size_v<std::decay_t<Ts>>))
95 template<std::size_t i, std::enable_if_t<(i < (0_uz + ... + std::tuple_size_v<std::decay_t<Ts>>)),
int> = 0>
97 friend constexpr decltype(
auto)
100 auto [element,
index] = std::decay_t<decltype(detail::concat_tuple_view_indices<i, Ts...>())>();
101 return get(
get(std::move(v).tup, element),
index);
106 std::tuple<Ts...> tup;
113 template<
typename...Args>
121 template<
typename...Ts>
123 : std::integral_constant<std::size_t, (0_uz + ... + std::tuple_size_v<std::decay_t<Ts>>)> {};
126 template<std::size_t i,
typename...Ts>
129 static_assert(i < (0_uz + ... + std::tuple_size_v<std::decay_t<Ts>>));
130 using indices = decltype(OpenKalman::collections::detail::concat_tuple_view_indices<i, Ts...>());
131 using element = std::tuple_element_t<0, indices>;
132 using index = std::tuple_element_t<1, indices>;
144 #ifdef __cpp_concepts 147 template<
typename...R, std::enable_if_t<(
sizeof...(R) > 0) and (... and viewable_collection<R>),
int> = 0>
150 operator() (R&&...r)
const 152 #if __cpp_lib_ranges_concat >= 202403L 153 namespace cv = std::ranges::views;
155 namespace cv = ranges::views;
157 if constexpr (
sizeof...(R) == 1)
158 return all(std::forward<R>(r)...);
159 else if constexpr ((... and tuple_like<R>))
162 return cv::concat(all(std::forward<R>(r))...) | all;
178 #endif //OPENKALMAN_VIEWS_CONCAT_HPP Definition for collections::tuple_like.
Namespace for collections.
Definition: collections.hpp:27
constexpr detail::concat_adaptor concat
a std::ranges::range_adaptor_closure for a set of concatenated collection objects.
Definition: concat.hpp:173
decltype(auto) constexpr get(Arg &&arg, I i)
A generalization of std::get.
Definition: get.hpp:62
A view to a concatenation of some number of other tuple_like object.
Definition: concat.hpp:55
Definition: tuple_reverse.hpp:103
constexpr bool value
T is numerical value or is reducible to a numerical value.
Definition: value.hpp:31
constexpr bool viewable_collection
A std::range or uniform_tuple_like object that can be converted into a collection_view by passing it ...
Definition: viewable_collection.hpp:37
concat_tuple_view(Args &&...) -> concat_tuple_view< Args... >
Deduction guide.
The root namespace for OpenKalman.
Definition: basics.hpp:34
constexpr bool size
T is either an index representing a size, or void which represents that there is no size...
Definition: size.hpp:32
Namespace for generalized views.
Definition: collections.hpp:33
Definition: concat.hpp:142
constexpr bool tuple_like
T is a non-empty tuple, pair, array, or other type that acts like a tuple.
Definition: tuple_like.hpp:51
constexpr bool index
An object describing a collection of /ref values::index objects.
Definition: index.hpp:75