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