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 "values/values.hpp"
20 #include "collection.hpp"
21 #include "sized.hpp"
24 
26 {
27 #if not defined(__cpp_lib_ranges) or __cpp_generic_lambdas < 201707L
28  namespace detail
29  {
30  template<typename T, typename = void>
31  struct is_index_range : std::false_type {};
32 
33  template<typename T>
34  struct is_index_range<T, std::enable_if_t<values::index<stdex::ranges::range_value_t<T>>>> : std::true_type {};
35 
36 
37  template<std::size_t i, typename T, typename = void>
38  struct has_index_element : std::false_type {};
39 
40  template<std::size_t i, typename T>
41  struct has_index_element<i, T, std::enable_if_t<values::index<typename collection_element<i, T>::type>>>
42  : std::true_type {};
43 
44 
45  template<typename T, typename = std::make_index_sequence<size_of_v<T>>>
46  struct is_index_tuple_impl : std::false_type {};
47 
48  template<typename T, std::size_t...i>
49  struct is_index_tuple_impl<T, std::index_sequence<i...>>
50  : std::bool_constant<(... and has_index_element<i, T>::value)> {};
51 
52 
53  template<typename T, typename = void>
54  struct is_index_tuple : std::false_type {};
55 
56  template<typename T>
57  struct is_index_tuple<T, std::enable_if_t<size_of<T>::value != stdex::dynamic_extent>> : is_index_tuple_impl<T> {};
58  }
59 #endif
60 
61 
66  template<typename T>
67 #if defined(__cpp_lib_ranges) and __cpp_generic_lambdas >= 201707L
68  concept index =
69  collection<T> and
70  (values::index<std::ranges::range_value_t<T>> or (
71  size_of_v<T> != stdex::dynamic_extent and
72  []<std::size_t...Ix>(std::index_sequence<Ix...>) {
73  return (... and values::index<typename collection_element<Ix, T>::type>);
74  }(std::make_index_sequence<size_of<T>::value>{}))
75  );
76 #else
77  constexpr bool index =
78  collection<T> and
80 #endif
81 
82 }
83 
84 #endif
Namespace for collections.
Definition: collections.hpp:27
Definition for collections::collection.
Header file for code relating to values (e.g., scalars and indices)
Definition for collections::size_of.
constexpr bool value
T is a fixed or dynamic value that is reducible to a number.
Definition: value.hpp:45
Definition for collections::sized.
Definition: trait_backports.hpp:64
constexpr bool index
T is an index value.
Definition: index.hpp:62
Definition for collections::collection_element.
constexpr bool index
An object describing a collection of /ref values::index objects.
Definition: index.hpp:77