OpenKalman
get_is_euclidean.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) 2020-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_GET_IS_EUCLIDEAN_HPP
17 #define OPENKALMAN_GET_IS_EUCLIDEAN_HPP
18 
23 
25 {
26  namespace detail
27  {
28 #ifndef __cpp_lib_ranges
29  template<typename T, typename = void>
30  struct is_unbound_fixed_range : std::false_type {};
31 
32  template<typename T>
33  struct is_unbound_fixed_range<T, std::enable_if_t<stdex::ranges::range<T>>>
34  : std::bool_constant<values::fixed<decltype(coordinates::internal::get_descriptor_is_euclidean(
35  std::declval<stdex::ranges::range_value_t<T>>()))>> {};
36 #endif
37 
38 
39  template<std::size_t i = 0, typename T>
40  static constexpr auto get_is_euclidean_fixed(const T& t)
41  {
42  if constexpr (i < collections::size_of_v<T>)
43  {
44  return values::operation(
45  std::logical_and{},
46  internal::get_descriptor_is_euclidean(collections::get<i>(t)),
47  get_is_euclidean_fixed<i + 1>(t));
48  }
49  else return std::true_type {};
50  }
51  }
52 
53 
57 #ifdef __cpp_concepts
58  template<pattern Arg> requires descriptor<Arg> or collections::sized<Arg> or
59  values::fixed<decltype(internal::get_descriptor_is_euclidean(std::declval<stdex::ranges::range_value_t<Arg>>()))>
60 #else
61  template<typename Arg, std::enable_if_t<pattern<Arg> and
62  (descriptor<Arg> or collections::sized<Arg> or detail::is_unbound_fixed_range<Arg>::value), int> = 0>
63 #endif
64  constexpr auto
65  get_is_euclidean(const Arg& arg)
66  {
67  if constexpr (descriptor<Arg>)
68  {
69  return internal::get_descriptor_is_euclidean(arg);
70  }
72  {
73  return std::true_type {};
74  }
75  else if constexpr (not collections::sized<Arg> or values::fixed_value_compares_with<collections::size_of<Arg>, stdex::dynamic_extent>)
76  {
77  using C = decltype(internal::get_descriptor_is_euclidean(std::declval<stdex::ranges::range_value_t<Arg>>()));
78  if constexpr (values::fixed<C>)
80  else
81 #ifdef __cpp_lib_ranges_fold
82  return std::ranges::fold_left(collections::views::all(arg), true,
83  [](const auto& a, const auto& b) { return a and internal::get_descriptor_is_euclidean(b); });
84 #else
85  {
86  for (const auto& c : arg) if (not internal::get_descriptor_is_euclidean(c)) return false;
87  return true;
88  }
89 #endif
90  }
91  else
92  {
93  return detail::get_is_euclidean_fixed(arg);
94  }
95  }
96 
97 
98 }
99 
100 #endif
The size of a sized object (including a collection).
Definition: size_of.hpp:33
The fixed value associated with a fixed.
Definition: fixed_value_of.hpp:44
Definition for coordinates::pattern.
constexpr auto get_is_euclidean(const Arg &arg)
Determine, whether coordinates::pattern Arg is euclidean.
Definition: get_is_euclidean.hpp:65
Definition for coordinates::descriptor.
The namespace for features relating to coordinates::pattern object.
Definition: compares_with.hpp:25
constexpr detail::all_closure all
a std::ranges::range_adaptor_closure which returns a view to all members of its collection argument...
Definition: all.hpp:72
Inclusion file for collections.
constexpr bool fixed_value_compares_with
T has a fixed value that compares with N in a particular way based on parameter comp.
Definition: fixed_value_compares_with.hpp:74
constexpr auto operation(Operation &&op, Args &&...args)
A potentially constant-evaluated operation involving some number of values.
Definition: operation.hpp:98