OpenKalman
may_hold_components.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) 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_MAY_HOLD_COMPONENTS_HPP
18 #define OPENKALMAN_MAY_HOLD_COMPONENTS_HPP
19 
20 
21 namespace OpenKalman::internal
22 {
23  namespace detail
24  {
25  template<typename T, std::size_t N, std::size_t...I>
26  constexpr bool may_hold_components_impl(std::index_sequence<I...>)
27  {
28  constexpr auto dims = ((dynamic_dimension<T, I> ? 1 : index_dimension_of_v<T, I>) * ... * 1);
29  if constexpr (N == 0) return dims == 0;
30  else if constexpr (dims == 0) return false;
31  else return N % dims == 0;
32  }
33  } // namespace detail
34 
35 
36  template<typename T, typename...Components>
37 #ifdef __cpp_concepts
38  concept may_hold_components = indexible<T> and (std::convertible_to<Components, const scalar_type_of_t<T>> and ...) and
39 #else
40  constexpr bool may_hold_components = indexible<T> and (std::is_convertible_v<Components, const scalar_type_of_t<T>> and ...) and
41 #endif
42  detail::may_hold_components_impl<T, sizeof...(Components)>(std::make_index_sequence<index_count_v<T>> {});
43 
44 
45 } // namespace OpenKalman::internal
46 
47 #endif //OPENKALMAN_MAY_HOLD_COMPONENTS_HPP
Definition: basics.hpp:48