OpenKalman
is_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) 2022-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 
16 #ifndef OPENKALMAN_IS_ONE_DIMENSIONAL_HPP
17 #define OPENKALMAN_IS_ONE_DIMENSIONAL_HPP
18 
22 
23 namespace OpenKalman
24 {
25  namespace detail
26  {
27  template<std::size_t i = 0, typename T>
28  constexpr bool is_one_dimensional_impl(const T& t)
29  {
30  if constexpr (i < index_count_v<T>)
31  {
32  return values::operation(
33  std::logical_and{},
34  values::operation(std::equal_to{}, get_index_extent<i>(t), std::integral_constant<std::size_t, 1>{}),
35  is_one_dimensional_impl<i + 1>(t));
36  }
37  else
38  {
39  return std::true_type {};
40  }
41  }
42  }
43 
44 
49 #ifdef __cpp_concepts
50  template<indexible T>
51  constexpr internal::boolean_testable auto is_one_dimensional(const T& t)
52 #else
53  template<typename T, std::enable_if_t<indexible<T>, int> = 0>
54  constexpr auto is_one_dimensional(const T& t)
55 #endif
56  {
57  if constexpr (index_count_v<T> == stdex::dynamic_extent)
58  {
59  for (std::size_t i = 1; i < count_indices(t); ++i) if (get_index_extent(t, i) != 1) return false;
60  return true;
61  }
62  else
63  {
64  return detail::is_one_dimensional_impl(t);
65  }
66 
67  }
68 
69 }
70 
71 #endif
constexpr auto count_indices(const T &)
Get the number of indices necessary to address all the components of an indexible object...
Definition: count_indices.hpp:51
Definition of get_index_extent function.
Definition of count_indices.
constexpr auto get_index_extent(T &&t, I i=I{})
Get the runtime dimensions of index N of indexible T.
Definition: get_index_extent.hpp:36
The root namespace for OpenKalman.
Definition: basics.hpp:34
constexpr auto is_one_dimensional(const T &t)
Determine whether T is one_dimensional, meaning that every index has a dimension of 1...
Definition: is_one_dimensional.hpp:54
Definition for index_count.
constexpr auto operation(Operation &&op, Args &&...args)
A potentially constant-evaluated operation involving some number of values.
Definition: operation.hpp:98