OpenKalman
collection_element.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_COLLECTIONS_COLLECTION_ELEMENT_HPP
17 #define OPENKALMAN_COLLECTIONS_COLLECTION_ELEMENT_HPP
18 
19 #include "values/values.hpp"
23 
25 {
26 #ifndef __cpp_concepts
27  namespace detail
28  {
29  template<std::size_t i, typename T, typename = void>
30  struct has_tuple_element : std::false_type {};
31 
32  template<std::size_t i, typename T>
33  struct has_tuple_element<i, T, std::void_t<typename std::tuple_element<i, std::decay_t<T>>::type>>
34  : std::true_type {};
35  }
36 #endif
37 
38 
43 #ifdef __cpp_concepts
44  template<std::size_t i, typename T>
45 #else
46  template<std::size_t i, typename T, typename = void>
47 #endif
48  struct collection_element {};
49 
50 
52 #ifdef __cpp_concepts
53  template<std::size_t i, sized T> requires
54  values::size_compares_with<std::integral_constant<std::size_t, i>, size_of<T>, &std::is_lt> and
55  requires { typename std::tuple_element<i, std::decay_t<T>>::type; }
56  struct collection_element<i, T>
57 #else
58  template<std::size_t i, typename T>
59  struct collection_element<i, T, std::enable_if_t<
60  values::size_compares_with<std::integral_constant<std::size_t, i>, size_of<T>, &stdex::is_lt> and
61  detail::has_tuple_element<i, T>::value>>
62 #endif
63  : std::tuple_element<i, std::decay_t<T>> {};
64 
65 
70 #ifdef __cpp_concepts
71  template<std::size_t i, typename T> requires
72  values::size_compares_with<std::integral_constant<std::size_t, i>, size_of<T>, &std::is_lt> and
73  (not requires { typename std::tuple_element<i, std::decay_t<T>>::type; }) and
74  gettable<i, T>
76 #else
77  template<std::size_t i, typename T>
78  struct collection_element<i, T, std::enable_if_t<
79  values::size_compares_with<std::integral_constant<std::size_t, i>, size_of<T>, &stdex::is_lt> and
81  gettable<i, T>>>
82 #endif
83  {
85  decltype(get<i>(std::declval<stdex::remove_cvref_t<T>>()))>;
86  };
87 
88 
93 #ifdef __cpp_concepts
94  template<std::size_t i, stdex::ranges::random_access_range T> requires
95  (not values::size_compares_with<std::integral_constant<std::size_t, i>, size_of<T>, &std::is_lt>) and
96  (not requires { typename std::tuple_element<i, std::decay_t<T>>::type; }) and
97  (not gettable<i, T>)
98  struct collection_element<i, T>
99 #else
100  template<std::size_t i, typename T>
101  struct collection_element<i, T, std::enable_if_t<
102  (not values::size_compares_with<std::integral_constant<std::size_t, i>, size_of<T>, &stdex::is_lt>) and
103  stdex::ranges::random_access_range<T> and
104  not detail::has_tuple_element<i, T>::value and
105  not gettable<i, T>>>
106 #endif
107  {
108  using type = stdex::ranges::range_value_t<stdex::remove_cvref_t<T>>;
109  };
110 
111 
115  template<std::size_t i, typename T>
117 
118 
119 }
120 
121 #endif
Namespace for collections.
Definition: collections.hpp:27
Header file for code relating to values (e.g., scalars and indices)
Definition for collections::size_of.
Definition for collections::sized.
typename remove_rvalue_reference< T >::type remove_rvalue_reference_t
Helper type for remove_rvalue_reference.
Definition: global-definitions.hpp:61
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
The type of the element at a given index, if it can be determined at compile time.
Definition: collection_element.hpp:48
typename collection_element< i, T >::type collection_element_t
Helper template for collection_element.
Definition: collection_element.hpp:116
Definition: collection_element.hpp:30
Definition for collections::gettable.