OpenKalman
square_shaped.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-2026 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_SQUARE_SHAPED_HPP
17 #define OPENKALMAN_SQUARE_SHAPED_HPP
18 
19 #include "patterns/patterns.hpp"
22 
23 namespace OpenKalman
24 {
25  namespace detail
26  {
27  template<auto N, typename T>
28  constexpr std::size_t
29  N_adjusted()
30  {
31 #ifdef __cpp_concepts
32  if constexpr (std::same_as<std::decay_t<decltype(N)>, values::unbounded_size_t>)
33 #else
34  if constexpr (N == std::size_t(values::unbounded_size))
35 #endif
36  {
37  if constexpr (values::fixed<index_count<T>>)
38  return std::max(2_uz, index_count_v<T>);
39  else
40  return 2_uz;
41  }
42  else return N;
43  }
44 
45 
46 #ifndef __cpp_concepts
47  template<typename T, applicability b, typename = void>
48  struct is_explicitly_square : std::false_type {};
49 
50  template<typename T, applicability b>
51  struct is_explicitly_square<T, b, std::enable_if_t<
52  interface::object_traits<stdex::remove_cvref_t<T>>::template is_square<b>>>
53  : std::true_type {};
54 
55 
56  template<typename T, auto N, applicability b, typename = void>
57  struct same_pattern_dimensions : std::false_type {};
58 
59  template<typename T, auto N, applicability b>
60  struct same_pattern_dimensions<T, N, b, std::enable_if_t<
61  patterns::collection_patterns_have_same_dimension<typename pattern_collection_type_of<T>::type, N_adjusted<N, T>(), b>>>
62  : std::true_type {};
63 #endif
64  }
65 
66 
79 #ifdef __cpp_concepts
80  template<typename T, auto N = values::unbounded_size, applicability b = applicability::guaranteed>
81  concept square_shaped =
82  indexible<T> and
83  (values::integral<decltype(N)> or std::same_as<std::decay_t<decltype(N)>, values::unbounded_size_t>) and
84  (not values::integral<decltype(N)> or N >= 2) and
85  (not interface::is_square_defined_for<T, b> or
86  interface::object_traits<std::remove_cvref_t<T>>::template is_square<b>) and
87  (interface::is_square_defined_for<T, b> or
89 #else
90  template<typename T, std::size_t N = values::unbounded_size, applicability b = applicability::guaranteed>
91  constexpr bool square_shaped =
92  indexible<T> and
93  (N == values::unbounded_size or N >= 2) and
94  (interface::is_square_defined_for<T, b> ?
95  detail::is_explicitly_square<T, b>::value :
96  detail::same_pattern_dimensions<T, N, b>::value);
97 #endif
98 
99 
100 }
101 
102 #endif
typename pattern_collection_type_of< T >::type pattern_collection_type_of_t
helper template for pattern_collection_type_of.
Definition: pattern_collection_type_of.hpp:55
Definition for pattern_collection_type_of.
constexpr bool square_shaped
At least 2 and at most N indices have the same extent.
Definition: square_shaped.hpp:91
Definition: square_shaped.hpp:57
constexpr bool value
T is a fixed or dynamic value that is reducible to a number.
Definition: value.hpp:45
constexpr bool collection_patterns_have_same_dimension
Specifies that the first N elements of a pattern_collection have the same dimensions.
Definition: collection_patterns_have_same_dimension.hpp:121
The root namespace for OpenKalman.
Definition: basics.hpp:34
Forward declaration of object_traits, which must be defined for all objects used in OpenKalman...
Definition: object_traits.hpp:38
A type reflecting an unbound size.
Definition: size.hpp:27
Definition: square_shaped.hpp:48
constexpr bool integral
T is an integral value.
Definition: integral.hpp:47
constexpr unbounded_size_t unbounded_size
An instance of unbounded_size_t;.
Definition: size.hpp:60
constexpr bool fixed
T has a value that is determinable at compile time.
Definition: fixed.hpp:65