16 #ifndef OPENKALMAN_ACCESS_HPP 17 #define OPENKALMAN_ACCESS_HPP 28 template<
typename Indices, std::size_t...i>
29 constexpr decltype(
auto)
30 make_index_array(const Indices& indices,
std::index_sequence<i...>)
32 return std::array<std::size_t,
sizeof...(i)> { collections::get<i>(indices)...};
36 template<std::
size_t i,
typename Indices>
38 get_index(
const Indices& indices, std::size_t s)
41 return collections::get<i>(indices);
43 return collections::get<0>(indices);
47 template<
typename Indices, std::size_t...i>
48 constexpr decltype(
auto)
49 make_index_array_padded(const Indices& indices,
std::
size_t s,
std::index_sequence<i...>)
51 return std::array<std::size_t,
sizeof...(i)> {get_index<i>(indices, s)...};
63 #ifdef __cpp_lib_concepts 64 template<indexible Arg, index_collection_for<Arg> Indices> requires
65 (not empty_object<Arg>) and
67 constexpr values::
value decltype(auto)
69 template<
typename Arg,
typename Indices, std::enable_if_t<
70 index_collection_for<Indices, Arg> and (not empty_object<Arg>) and
72 constexpr decltype(
auto)
74 access(Arg&& arg,
const Indices& indices)
76 decltype(
auto) mds =
get_mdspan(std::forward<Arg>(arg));
77 constexpr std::size_t rank = std::decay_t<decltype(mds)>::rank();
80 return mds[detail::make_index_array_padded(indices, s, std::make_index_sequence<rank>{})];
81 if constexpr (stdex::ranges::range<Indices>)
82 return mds[stdex::span(indices).template subspan<0, rank>()];
84 return mds[detail::make_index_array(indices, std::make_index_sequence<rank>{})];
92 #ifdef __cpp_lib_concepts 94 (not empty_object<Arg>) and
98 template<
typename Arg,
typename...I, std::enable_if_t<indexible<Arg> and (... and values::index<I>) and
99 (not empty_object<Arg>) and
101 constexpr decltype(
auto)
105 return access(std::forward<Arg>(arg), std::array<std::size_t,
sizeof...(I)>{std::move(i)...});
constexpr auto get_mdspan(T &t)
Get the coordinates::pattern_collection associated with indexible object T.
Definition: get_mdspan.hpp:35
Definition for index_collection_for.
constexpr bool indexible
T is a multidimensional array type.
Definition: indexible.hpp:32
constexpr bool value
T is a fixed or dynamic value that is reducible to a number.
Definition: value.hpp:45
The root namespace for OpenKalman.
Definition: basics.hpp:34
decltype(auto) constexpr access(Arg &&arg, const Indices &indices)
Access a component of an indexible object at a given set of indices.
Definition: access.hpp:74
Inclusion file for collections.
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
Definition for index_count.
Definition for empty_object.
constexpr bool index
T is an index value.
Definition: index.hpp:62
The minimum number of indices needed to access all the components of an object (i.e., the rank or order).
Definition: index_count.hpp:34
constexpr auto get_size(Arg &&arg)
Get the size of a sized object (e.g, a collection)
Definition: get_size.hpp:188