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 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 
22 #include "../interfaces/library_interface.hpp"
25 
26 namespace OpenKalman
27 {
36 #ifdef __cpp_lib_concepts
37  template<indexible Arg, index_collection_for<Arg> Indices> requires
38  (not empty_object<Arg>) and
39  (not values::size_compares_with<collections::size_of<Indices>, index_count<Arg>, &stdex::is_lt>)
40  constexpr values::value decltype(auto)
41 #else
42  template<typename Arg, typename Indices, std::enable_if_t<
43  index_collection_for<Indices, Arg> and (not empty_object<Arg>) and
44  (not values::size_compares_with<collections::size_of<Indices>, index_count<Arg>, &stdex::is_lt>), int> = 0>
45  constexpr decltype(auto)
46 #endif
47  access_at(Arg&& arg, const Indices& indices)
48  {
49  bool in_bounds = collections::compare_indices<&stdex::is_lt>(indices, coordinates::views::dimensions(get_pattern_collection(arg)));
50  if (not in_bounds) throw std::out_of_range {"One or more indices out of range."};
51  return access(std::forward<Arg>(arg), indices);
52  }
53 
54 
59 #ifdef __cpp_lib_concepts
60  template<indexible Arg, values::index...I> requires
61  (not empty_object<Arg>) and
62  (not values::size_compares_with<std::integral_constant<std::size_t, sizeof...(I)>, index_count<Arg>, &stdex::is_lt>)
63  constexpr values::value decltype(auto)
64 #else
65  template<typename Arg, typename...I, std::enable_if_t<indexible<Arg> and (... and values::index<I>) and
66  (not empty_object<Arg>) and
67  (not values::size_compares_with<std::integral_constant<std::size_t, sizeof...(I)>, index_count<Arg>, &stdex::is_lt>), int> = 0>
68  constexpr decltype(auto)
69 #endif
70  access_at(Arg&& arg, I...i)
71  {
72  return access_at(std::forward<Arg>(arg), std::array<std::size_t, sizeof...(I)>{std::move(i)...});
73  }
74 
75 
76 }
77 
78 #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:47
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 coordinates::pattern_collection associated with indexible object T.
Definition: get_pattern_collection.hpp:59
constexpr bool value
T is a fixed or dynamic value that is reducible to a number.
Definition: value.hpp:45
Definition for dimension_size_of_index_is.
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
Definition for empty_object.
constexpr detail::dimensions_adaptor dimensions
a std::ranges::range_adaptor_closure for the dimensions of a pattern_collection.
Definition: dimensions.hpp:149
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