OpenKalman
one_dimensional.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) 2019-2023 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 
17 #ifndef OPENKALMAN_ONE_DIMENSIONAL_HPP
18 #define OPENKALMAN_ONE_DIMENSIONAL_HPP
19 
21 
22 namespace OpenKalman
23 {
24  namespace detail
25  {
26  template<typename T, Applicability b, std::size_t I, std::size_t...Is>
27  constexpr bool has_1_by_1_dims(std::index_sequence<I, Is...>)
28  {
29  return compares_with<vector_space_descriptor_of_t<T, I>, vector_space_descriptor_of_t<T, Is>, equal_to<>, Applicability::permitted> and
30  (dimension_size_of_index_is<T, I, 1, b> and ... and dimension_size_of_index_is<T, Is, 1, b>);
31  }
32 
33 
34 #ifdef __cpp_concepts
35  template<typename T, Applicability b>
36 #else
37  template<typename T, Applicability b, typename = void>
38 #endif
39  struct one_dimensional_impl : std::false_type {};
40 
41 
42 #ifdef __cpp_concepts
43  template<typename T, Applicability b> requires (index_count_v<T> == dynamic_size)
44  struct one_dimensional_impl<T, b>
45 #else
46  template<typename T, Applicability b>
47  struct one_dimensional_impl<T, b, std::enable_if_t<index_count<T>::value == dynamic_size>>
48 #endif
49  : std::bool_constant<b == Applicability::permitted and detail::has_1_by_1_dims<T, b>(std::make_index_sequence<2>{})> {};
50 
51 
52 #ifdef __cpp_concepts
53  template<typename T, Applicability b> requires (index_count_v<T> == 0)
54  struct one_dimensional_impl<T, b>
55 #else
56  template<typename T, Applicability b>
57  struct one_dimensional_impl<T, b, std::enable_if_t<index_count<T>::value == 0>>
58 #endif
59  : std::true_type {};
60 
61 
62 #ifdef __cpp_concepts
63  template<typename T, Applicability b> requires (index_count_v<T> != dynamic_size and index_count_v<T> > 0)
64  struct one_dimensional_impl<T, b>
65  #else
66  template<typename T, Applicability b>
67  struct one_dimensional_impl<T, b, std::enable_if_t<index_count<T>::value != dynamic_size and index_count<T>::value > 0>>
68  #endif
69  : std::bool_constant<detail::has_1_by_1_dims<T, b>(std::make_index_sequence<index_count_v<T>>{})> {};
70  } // namespace detail
71 
72 
77  template<typename T, Applicability b = Applicability::guaranteed>
78 #ifdef __cpp_concepts
79  concept one_dimensional = indexible<T> and
80  (not interface::one_dimensional_defined_for<T, b> or interface::indexible_object_traits<std::decay_t<T>>::template one_dimensional<b>) and
81  (interface::one_dimensional_defined_for<T, b> or detail::one_dimensional_impl<T, b>::value);
82 #else
83  constexpr bool one_dimensional = indexible<T> and
84  (interface::one_dimensional_defined_for<T, b> ? interface::is_explicitly_one_dimensional<T, b>::value : detail::one_dimensional_impl<T, b>::value);
85 #endif
86 
87 
88 } // namespace OpenKalman
89 
90 #endif //OPENKALMAN_ONE_DIMENSIONAL_HPP
constexpr bool one_dimensional
Specifies that a type is one-dimensional in every index.
Definition: one_dimensional.hpp:83
Definition: indexible_object_traits.hpp:36
Definition for compares_with.
Definition: tuple_reverse.hpp:103
The root namespace for OpenKalman.
Definition: basics.hpp:34
The concept, trait, or restraint is permitted, but whether it applies is not necessarily known at com...
Definition: one_dimensional.hpp:39
Applicability
The applicability of a concept, trait, or restraint.
Definition: global-definitions.hpp:93
Definition: object-traits-defined.hpp:205
constexpr std::size_t dynamic_size
A constant indicating that a size or index is dynamic.
Definition: global-definitions.hpp:33