OpenKalman
uniformly_gettable.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_UNIFORMLY_GETTABLE_HPP
17 #define OPENKALMAN_COLLECTIONS_UNIFORMLY_GETTABLE_HPP
18 
19 #include <type_traits>
20 #include "gettable.hpp"
22 
24 {
25 #if not defined(__cpp_concepts) or __cpp_generic_lambdas < 201707L
26  namespace detail
27  {
28  template<typename T, typename = std::make_index_sequence<size_of_v<T>>, typename = void>
29  struct uniformly_gettable_sized_impl : std::false_type {};
30 
31  template<typename T, std::size_t...i>
32  struct uniformly_gettable_sized_impl<T, std::index_sequence<i...>, std::enable_if_t<(... and gettable<i, T>)>> : std::true_type {};
33 
34 
35  template<typename T, typename = void>
36  struct uniformly_gettable_sized : std::false_type {};
37 
38  template<typename T>
39  struct uniformly_gettable_sized<T, std::enable_if_t<size_of<T>::value != dynamic_size>>
40  : uniformly_gettable_sized_impl<T> {};
41 
42  } // namespace detail
43 #endif
44 
45 
50  template<typename T>
51 #if defined(__cpp_concepts) and __cpp_generic_lambdas >= 201707L
52  concept uniformly_gettable =
53  ((sized<T> and size_of_v<T> != dynamic_size) or
54  (gettable<0_uz, T> and gettable<std::numeric_limits<std::size_t>::max() - 1_uz, T>)) and
55  (not sized<T> or size_of_v<T> == dynamic_size or
56  []<std::size_t...i>(std::index_sequence<i...>) { return (... and gettable<i, T>); }
57  (std::make_index_sequence<size_of_v<T>>{}));
58 #else
59  constexpr bool uniformly_gettable =
60  ((sized<T> and size_of_v<T> != dynamic_size) or
61  (gettable<0_uz, T> and gettable<std::numeric_limits<std::size_t>::max() - 1_uz, T>)) and
62  (not sized<T> or size_of_v<T> == dynamic_size or detail::uniformly_gettable_sized<T>::value);
63 #endif
64 
65 
66 } // namespace OpenKalman::collections
67 
68 #endif //OPENKALMAN_COLLECTIONS_UNIFORMLY_GETTABLE_HPP
Namespace for collections.
Definition: collections.hpp:27
constexpr bool uniformly_gettable
T is gettable for all indices.
Definition: uniformly_gettable.hpp:59
constexpr bool gettable
T has an element i that is accessible by a get(...) function.
Definition: gettable.hpp:58
Definition: tuple_reverse.hpp:103
Definition for collections::size_of.
constexpr bool value
T is numerical value or is reducible to a numerical value.
Definition: value.hpp:31
constexpr std::size_t dynamic_size
A constant indicating that a size or index is dynamic.
Definition: global-definitions.hpp:33
Definition for collections::gettable.