17 #ifndef OPENKALMAN_ELEMENT_FUNCTIONS_HPP 18 #define OPENKALMAN_ELEMENT_FUNCTIONS_HPP 23 #if defined(__cpp_lib_ranges) 31 #if __cpp_lib_ranges >= 202202L 32 template<std::ranges::input_range Indices, values::index MinCount>
33 constexpr decltype(
auto) truncate_indices(const Indices& indices, const MinCount& min_count)
35 auto n {
static_cast<std::ranges::range_difference_t<Indices>
>(min_count)};
36 if (std::ranges::any_of(indices | std::ranges::views::drop(n), [](
const auto& x){
return x != 0; }))
37 throw std::invalid_argument {
"Component access: one or more trailing indices are not 0."};
38 return indices | std::ranges::views::take(n);
41 template<
typename Indices,
typename MinCount, std::enable_if_t<values::index<MinCount>,
int> = 0>
42 decltype(
auto) truncate_indices(const Indices& indices, const MinCount& min_count)
44 #ifdef __cpp_lib_ranges 45 namespace ranges = std::ranges;
47 auto n {
static_cast<std::size_t
>(min_count)};
48 auto ad = ranges::begin(indices);
50 if (std::any_of(ad, ranges::end(indices), [](
const auto& x){
return x != 0; }))
51 throw std::invalid_argument {
"Component access: one or more trailing indices are not 0."};
52 if constexpr (values::fixed<MinCount>)
54 std::array<std::size_t, MinCount::value> ret;
55 std::copy(ranges::begin(indices), ad, ranges::begin(ret));
60 std::vector<std::size_t> ret {n};
61 std::copy(ranges::begin(indices), ad, ranges::begin(ret));
68 #endif //OPENKALMAN_ELEMENT_FUNCTIONS_HPP Definitions implementing features of the c++ ranges library for compatibility.
Definition: basics.hpp:48