OpenKalman
index.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-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_COLLECTIONS_INDEX_HPP
17 #define OPENKALMAN_COLLECTIONS_INDEX_HPP
18 
19 #include <type_traits>
20 #ifdef __cpp_lib_ranges
21 #include <ranges>
22 #else
24 #endif
25 #include "../../basics/compatibility/language-features.hpp"
26 #include "values/values.hpp"
27 #include "collection.hpp"
28 
30 {
31 #if not defined(__cpp_lib_ranges) or not defined(__cpp_lib_remove_cvref) or __cpp_generic_lambdas < 201707L
32  namespace detail_index
33  {
34  template<typename T, std::size_t...Ix>
35  constexpr bool is_index_tuple_impl(std::index_sequence<Ix...>) { return (... and values::index<typename std::tuple_element<Ix, T>::type>); }
36 
37  template<typename T, typename = void>
38  struct is_index_tuple : std::false_type {};
39 
40  template<typename T>
41  struct is_index_tuple<T, std::enable_if_t<tuple_like<T>>>
42  : std::bool_constant<is_index_tuple_impl<T>(std::make_index_sequence<std::tuple_size_v<T>>{})> {};
43 
44 
45 #ifdef __cpp_lib_remove_cvref
46  using std::remove_cvref_t;
47 #endif
48 #ifdef __cpp_lib_ranges
49  namespace ranges = std::ranges;
50 #endif
51 
52 
53  template<typename T, typename = void>
54  struct is_index_range : std::false_type {};
55 
56  template<typename T>
57  struct is_index_range<T, std::enable_if_t<values::index<ranges::range_value_t<remove_cvref_t<T>>>>> : std::true_type {};
58 
59  }
60 #endif
61 
62 
67  template<typename T>
68 #if defined(__cpp_lib_ranges) and defined(__cpp_lib_remove_cvref) and __cpp_generic_lambdas >= 201707L
69  concept index = collection<T> and
70  ([]<std::size_t...Ix>(std::index_sequence<Ix...>)
71  { return (... and values::index<std::tuple_element_t<Ix, std::remove_cvref_t<T>>>); }
72  (std::make_index_sequence<std::tuple_size<std::remove_cvref_t<T>>::value>{}) or
73  values::index<std::ranges::range_value_t<std::remove_cvref_t<T>>>);
74 #else
75  constexpr bool index = collection<T> and
76  (detail_index::is_index_tuple<std::decay_t<T>>::value or detail_index::is_index_range<std::decay_t<T>>::value);
77 #endif
78 
79 } // namespace OpenKalman::collections
80 
81 #endif //OPENKALMAN_COLLECTIONS_INDEX_HPP
Namespace for collections.
Definition: collections.hpp:27
Definition for collections::collection.
Header file for code relating to values (e.g., scalars and indices)
Definition: tuple_reverse.hpp:103
constexpr bool value
T is numerical value or is reducible to a numerical value.
Definition: value.hpp:31
Definitions implementing features of the c++ ranges library for compatibility.
constexpr bool index
T is an index value.
Definition: index.hpp:56
constexpr bool index
An object describing a collection of /ref values::index objects.
Definition: index.hpp:75