16 #ifndef OPENKALMAN_COLLECTIONS_VIEWS_FROM_RANGE_HPP 17 #define OPENKALMAN_COLLECTIONS_VIEWS_FROM_RANGE_HPP 28 namespace detail_from_range
31 template<std::
size_t i,
typename T>
33 template<std::
size_t i,
typename T,
typename =
void>
37 using type = stdex::ranges::range_value_t<T>;
39 template<
typename R> constexpr decltype(
auto) operator() (R&& r)
const 40 {
return get<i>(std::forward<R>(r)); }
45 template<std::
size_t i,
typename T> requires gettable<i, T>
48 template<std::size_t i, typename T>
53 template<
typename R> constexpr decltype(
auto) operator() (R&& r)
const 54 {
return get<i>(std::forward<R>(r)); }
59 template<std::
size_t i,
typename T>
61 template<std::
size_t i,
typename T,
typename =
void>
66 template<std::
size_t i,
typename R>
67 inline constexpr decltype(
auto)
72 struct get_elem<0, stdex::ranges::single_view<T>>
75 template<
typename U> constexpr decltype(
auto) operator() (U&& u)
const {
return *std::forward<U>(u).data(); }
79 template<std::
size_t i,
typename R>
82 template<
typename T> constexpr decltype(
auto) operator() (T&& t)
const {
return get_from_base<i>(std::forward<T>(t).base()); }
86 template<std::
size_t i,
typename R>
87 struct get_elem<i, stdex::ranges::owning_view<R>> :
get_elem<i, stdex::remove_cvref_t<R>>
89 template<
typename T> constexpr decltype(
auto) operator() (T&& t)
const {
return get_from_base<i>(std::forward<T>(t).base()); }
94 template<std::
size_t i,
typename V> requires (size_of_v<V> != stdex::dynamic_extent)
95 struct get_elem<i, stdex::ranges::reverse_view<V>>
97 template<std::size_t i, typename V>
98 struct
get_elem<i, stdex::ranges::reverse_view<V>, std::enable_if_t<size_of_v<V> != stdex::dynamic_extent>>
100 :
get_elem<size_of_v<V> - i - 1_uz, stdex::remove_cvref_t<V>>
102 template<
typename T> constexpr decltype(
auto) operator() (T&& t)
const 104 if constexpr (not std::is_lvalue_reference_v<T> or stdex::copy_constructible<V>)
105 return get_from_base<size_of_v<V> - i - 1_uz>(std::forward<T>(t).base());
107 return get<i>(std::forward<T>(t));
117 #ifdef __cpp_concepts 118 template<stdex::ranges::random_access_range V> requires stdex::ranges::viewable_range<V>
133 #ifdef __cpp_concepts 137 template<
bool Enable = true, std::enable_if_t<Enable and stdex::default_initializable<RangeBox>,
int> = 0>
146 #ifdef __cpp_concepts 147 template<
typename Arg> requires (not std::same_as<stdex::remove_cvref_t<Arg>,
from_range>)
149 template<
typename Arg, std::enable_if_t<(not std::is_same_v<stdex::remove_cvref_t<Arg>, from_range>),
int> = 0>
152 from_range(Arg&& arg) noexcept : r_ {std::forward<Arg>(arg)} {}
158 #ifdef __cpp_explicit_this_parameter 159 constexpr decltype(
auto)
160 base(
this auto&&
self) noexcept {
return std::forward<decltype(self)>(
self).r_.get(); }
162 constexpr V&
base() & {
return this->r_.get(); }
163 constexpr
const V& base()
const & {
return this->r_.get(); }
164 constexpr V&& base() && noexcept {
return std::move(*this).r_.get(); }
165 constexpr
const V&& base()
const && noexcept {
return std::move(*this).r_.get(); }
172 constexpr
auto begin() {
return stdex::ranges::begin(base()); }
175 constexpr
auto begin()
const {
return stdex::ranges::begin(base()); }
181 constexpr
auto end() {
return stdex::ranges::end(base()); }
184 constexpr
auto end()
const {
return stdex::ranges::end(base()); }
190 #ifdef __cpp_concepts 192 size()
const requires sized<V>
194 template<
bool Enable = true, std::enable_if_t<Enable and sized<V>,
int> = 0>
209 #ifdef __cpp_concepts 211 empty()
const requires sized<V> or stdex::ranges::forward_range<V>
213 template<
bool Enable = true, std::enable_if_t<Enable and (sized<V> or stdex::ranges::forward_range<V>),
int> = 0>
218 if constexpr (sized<V>)
220 if constexpr (size_of_v<V> == stdex::dynamic_extent)
return get_size(base()) == 0_uz;
221 else if constexpr (size_of_v<V> == 0)
return std::true_type{};
222 else return std::false_type{};
226 return stdex::ranges::begin(base()) == stdex::ranges::end(base());
234 constexpr decltype(
auto)
235 front() {
return collections::get<0>(base()); }
238 constexpr decltype(
auto)
239 front()
const {
return collections::get<0>(base()); }
243 #ifdef __cpp_lib_ranges 246 template<
typename T,
typename =
void>
248 struct back_gettable : std::false_type {};
251 #ifdef __cpp_lib_ranges 252 requires values::fixed_value_compares_with<size_of<T>, stdex::dynamic_extent, &stdex::is_neq>
253 struct back_gettable<T>
255 struct back_gettable<T, std::enable_if_t<
256 values::fixed_value_compares_with<size_of<T>, stdex::dynamic_extent, &stdex::is_neq>>>
258 : std::bool_constant<gettable<size_of_v<T> - 1_uz, T>> {};
265 #ifdef __cpp_concepts 266 constexpr decltype(
auto)
267 back() requires (stdex::ranges::bidirectional_range<V> and stdex::ranges::common_range<V>) or
back_gettable<V>::value 269 template<
bool Enable =
true, std::enable_if_t<Enable and
270 (stdex::ranges::bidirectional_range<V> and stdex::ranges::common_range<V>) or
back_gettable<V>::value,
int> = 0>
271 constexpr decltype(
auto)
275 if constexpr (back_gettable<V>::value)
276 return collections::get<size_of_v<V> - 1_uz>(base());
282 #ifdef __cpp_concepts 283 constexpr decltype(
auto)
284 back()
const requires (stdex::ranges::bidirectional_range<V> and stdex::ranges::common_range<V>) or back_gettable<V>::value
286 template<
bool Enable =
true, std::enable_if_t<Enable and
287 (stdex::ranges::bidirectional_range<V> and stdex::ranges::common_range<V>) or back_gettable<V>::value,
int> = 0>
288 constexpr decltype(
auto)
292 if constexpr (back_gettable<V>::value)
293 return collections::get<size_of_v<V> - 1_uz>(base());
303 #ifdef __cpp_explicit_this_parameter 304 template<
typename Self, values::index I>
305 constexpr decltype(
auto)
306 operator[](
this Self&&
self, I i)
312 template<
typename I, std::enable_if_t<values::index<I>,
int> = 0>
313 constexpr decltype(
auto)
320 template<
typename I, std::enable_if_t<values::index<I>,
int> = 0>
321 constexpr decltype(
auto)
322 operator[](I i)
const &
328 template<
typename I, std::enable_if_t<values::index<I>,
int> = 0>
329 constexpr decltype(
auto)
330 operator[](I i) && noexcept
336 template<
typename I, std::enable_if_t<values::index<I>,
int> = 0>
337 constexpr decltype(
auto)
338 operator[](I i)
const && noexcept
350 #ifdef __cpp_explicit_this_parameter 351 template<std::
size_t i>
352 constexpr decltype(
auto)
353 get(
this auto&&
self) noexcept
355 using Ni = std::integral_constant<std::size_t, i>;
357 return detail_from_range::get_from_base<i>(std::forward<decltype(self)>(
self).base());
360 template<std::
size_t i>
361 constexpr decltype(
auto)
364 using Ni = std::integral_constant<std::size_t, i>;
366 return detail_from_range::get_from_base<i>(base());
369 template<std::
size_t i>
370 constexpr decltype(
auto)
373 using Ni = std::integral_constant<std::size_t, i>;
375 return detail_from_range::get_from_base<i>(base());
378 template<std::
size_t i>
379 constexpr decltype(
auto)
382 using Ni = std::integral_constant<std::size_t, i>;
384 return detail_from_range::get_from_base<i>(std::move(*this).base());
387 template<std::
size_t i>
388 constexpr decltype(
auto)
389 get()
const && noexcept
391 using Ni = std::integral_constant<std::size_t, i>;
393 return detail_from_range::get_from_base<i>(std::move(*this).base());
412 #ifdef __cpp_lib_ranges 413 namespace std::ranges
419 constexpr
bool enable_borrowed_range<OpenKalman::collections::from_range<V>> =
420 std::is_lvalue_reference_v<V> or enable_borrowed_range<OpenKalman::stdex::remove_cvref_t<V>>;
428 : std::conditional_t<
429 OpenKalman::values::fixed_value_compares_with<
430 OpenKalman::collections::size_of<V>, OpenKalman::stdex::dynamic_extent, &OpenKalman::stdex::is_neq>,
431 OpenKalman::collections::size_of<V>,
435 template<std::
size_t i,
typename V>
constexpr from_range()
Default constructor.
Definition: from_range.hpp:139
constexpr auto size() const
The size of the resulting object.
Definition: from_range.hpp:196
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
from_range(V &&) -> from_range< V >
Deduction guide.
Header file for code relating to values (e.g., scalars and indices)
constexpr V & base() &
The base tuple.
Definition: from_range.hpp:162
A collection_view created from a std::ranges::random_access_range that is a std::ranges::viewable_ran...
Definition: from_range.hpp:122
constexpr auto end()
An iterator to the end of the range.
Definition: from_range.hpp:181
constexpr from_range(Arg &&arg) noexcept
Construct from a std::ranges::random_access_range.
Definition: from_range.hpp:152
Definition for collections::size_of.
The size of a sized object (including a collection).
Definition: size_of.hpp:33
constexpr bool value
T is a fixed or dynamic value that is reducible to a number.
Definition: value.hpp:45
constexpr auto begin()
An iterator to the beginning of the range.
Definition: from_range.hpp:172
Definition: view_interface.hpp:32
Definition: from_range.hpp:35
Definition for collections::get_size.
The root namespace for OpenKalman.
Definition: basics.hpp:34
constexpr auto empty() const
Definition: from_range.hpp:215
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 bool size_compares_with
T and U are sizes that compare in a particular way based on parameter comp.
Definition: size_compares_with.hpp:98
The type of the element at a given index, if it can be determined at compile time.
Definition: collection_element.hpp:48
constexpr bool fixed_value_compares_with
T has a fixed value that compares with N in a particular way based on parameter comp.
Definition: fixed_value_compares_with.hpp:74
decltype(auto) constexpr get_element(Arg &&arg, I i)
A generalization of std::get and the range subscript operator.
Definition: get_element.hpp:122
Definition: from_range.hpp:63
constexpr auto begin() const
Definition: from_range.hpp:175
constexpr auto get_size(Arg &&arg)
Get the size of a sized object (e.g, a collection)
Definition: get_size.hpp:188
constexpr auto end() const
Definition: from_range.hpp:184