OpenKalman
access_at.hpp
Go to the documentation of this file.
1 /* This file is part of OpenKalman, a header-only C++ library for
2  * Kalman filters and other recursive filters.
3  *
4  * Copyright (c) 2025-2026 Christopher Lee Ogden <ogden@gatech.edu>
5  *
6  * This Source Code Form is subject to the terms of the Mozilla Public
7  * License, v. 2.0. If a copy of the MPL was not distributed with this
8  * file, You can obtain one at https://mozilla.org/MPL/2.0/.
9  */
10 
16 #ifndef OPENKALMAN_ACCESS_AT_HPP
17 #define OPENKALMAN_ACCESS_AT_HPP
18 
23 
24 namespace OpenKalman
25 {
34 #ifdef __cpp_lib_concepts
35  template<indexible Arg, index_collection_for<Arg> Indices> requires
36  (not empty_object<Arg>) and
37  (not values::size_compares_with<collections::size_of<Indices>, index_count<Arg>, &stdex::is_lt>)
38  constexpr values::value decltype(auto)
39 #else
40  template<typename Arg, typename Indices, std::enable_if_t<
41  index_collection_for<Indices, Arg> and (not empty_object<Arg>) and
42  (not values::size_compares_with<collections::size_of<Indices>, index_count<Arg>, &stdex::is_lt>), int> = 0>
43  constexpr decltype(auto)
44 #endif
45  access_at(Arg&& arg, const Indices& indices)
46  {
47  bool in_bounds = collections::compare_indices<&stdex::is_lt>(indices, patterns::views::dimensions(get_pattern_collection(arg)));
48  if (not in_bounds) throw std::out_of_range {"One or more indices out of range."};
49  return access(std::forward<Arg>(arg), indices);
50  }
51 
52 
57 #ifdef __cpp_lib_concepts
58  template<indexible Arg, values::index...I> requires
59  (not empty_object<Arg>) and
60  (not values::size_compares_with<std::integral_constant<std::size_t, sizeof...(I)>, index_count<Arg>, &stdex::is_lt>)
61  constexpr values::value decltype(auto)
62 #else
63  template<typename Arg, typename...I, std::enable_if_t<indexible<Arg> and (... and values::index<I>) and
64  (not empty_object<Arg>) and
65  (not values::size_compares_with<std::integral_constant<std::size_t, sizeof...(I)>, index_count<Arg>, &stdex::is_lt>), int> = 0>
66  constexpr decltype(auto)
67 #endif
68  access_at(Arg&& arg, I...i)
69  {
70  return access_at(std::forward<Arg>(arg), std::array<std::size_t, sizeof...(I)>{std::move(i)...});
71  }
72 
73 
74 }
75 
76 #endif
decltype(auto) constexpr access_at(Arg &&arg, const Indices &indices)
Access a component of an indexible object at a given set of indices, with bounds checking.
Definition: access_at.hpp:45
Definition for index_collection_for.
constexpr bool indexible
T is a multidimensional array type.
Definition: indexible.hpp:32
decltype(auto) constexpr get_pattern_collection(T &&t)
Get the patterns::pattern_collection associated with indexible object T.
Definition: get_pattern_collection.hpp:36
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.
Definition for index_dimension_of.
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
constexpr detail::dimensions_adaptor dimensions
a std::ranges::range_adaptor_closure for the dimensions of a pattern_collection.
Definition: dimensions.hpp:149
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