OpenKalman
index_range_for.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) 2024 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_INDEX_RANGE_FOR_HPP
17 #define OPENKALMAN_INDEX_RANGE_FOR_HPP
18 
19 #include <type_traits>
20 #ifdef __cpp_lib_ranges
21 #include <ranges>
22 #else
24 #endif
25 
26 namespace OpenKalman
27 {
28 #ifndef __cpp_lib_ranges
29  namespace detail
30  {
31  template<typename Indices, typename Indexible, typename = void>
32  struct index_range_for_impl_it : std::false_type {};
33 
34  template<typename Indices, typename Indexible>
35  struct index_range_for_impl_it<Indices, Indexible, std::enable_if_t<values::index<ranges::iterator_t<Indices>>>>
36  : std::true_type {};
37 
38 
39  template<typename Indices, typename Indexible, typename = void>
40  struct index_range_for_impl : std::false_type {};
41 
42  template<typename Indices, typename Indexible>
43  struct index_range_for_impl<Indices, Indexible, std::enable_if_t<
44  collections::size_of<Indices>::value == dynamic_size or index_count<Indexible>::value == dynamic_size or
45  collections::size_of<Indices>::value >= index_count<Indexible>::value>>
46  : std::true_type {};
47 
48  }
49 #endif
50 
51 
55  template<typename Indices, typename T>
56 #ifdef __cpp_lib_ranges
57  concept index_range_for =
58  indexible<T> and std::ranges::input_range<std::decay_t<Indices>> and
59  values::index<std::ranges::range_value_t<Indices>> and
60  interface::get_component_defined_for<T, T, Indices> and
61  (collections::size_of_v<Indices> == dynamic_size or index_count_v<T> == dynamic_size or
62  collections::size_of_v<Indices> >= index_count_v<T>);
63 #else
64  constexpr bool index_range_for =
65  indexible<T> and
67  interface::get_component_defined_for<T, T, Indices> and
69 #endif
70 
71 } // namespace OpenKalman
72 
73 #endif //OPENKALMAN_INDEX_RANGE_FOR_HPP
constexpr bool index_range_for
Indices is a std::ranges::sized_range of indices that are compatible with indexible object T...
Definition: index_range_for.hpp:64
Definition: tuple_reverse.hpp:103
constexpr bool value
T is numerical value or is reducible to a numerical value.
Definition: value.hpp:31
The root namespace for OpenKalman.
Definition: basics.hpp:34
Definition: index_range_for.hpp:32
Definitions implementing features of the c++ ranges library for compatibility.
The minimum number of indices need to access all the components of an object.
Definition: index_count.hpp:33
Definition: index_range_for.hpp:40
constexpr std::size_t dynamic_size
A constant indicating that a size or index is dynamic.
Definition: global-definitions.hpp:33