OpenKalman
fixed_number_of.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) 2024 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_VALUES_FIXED_NUMBER_OF_HPP
17 #define OPENKALMAN_VALUES_FIXED_NUMBER_OF_HPP
18 
19 #include <type_traits>
22 
23 namespace OpenKalman::values
24 {
25 #ifndef __cpp_concepts
26  namespace detail
27  {
28  template<typename T, typename = void>
29  struct fixed_number_of_impl : std::false_type {};
30 
31  template<typename T>
32  struct fixed_number_of_impl<T, std::void_t<decltype(T::value)>> : std::true_type {};
33  }
34 #endif
35 
36 
40 #ifdef __cpp_concepts
41  template<typename T>
42 #else
43  template<typename T, typename = void>
44 #endif
45  struct fixed_number_of {};
46 
47 
48 #ifdef __cpp_concepts
49  template<values::fixed T>
50  struct fixed_number_of<T>
51 #else
52  template<typename T>
53  struct fixed_number_of<T, std::enable_if_t<values::fixed<T>>>
54 #endif
55  {
56  private:
57 
58  static constexpr auto get_value()
59  {
60 #ifdef __cpp_concepts
61  if constexpr (requires { std::decay_t<T>::value; })
62 #else
63  if constexpr (detail::fixed_number_of_impl<std::decay_t<T>>::value)
64 #endif
66  else
67  return std::decay_t<T>{}();
68  };
69 
70  public:
71 
72  using value_type = std::decay_t<decltype(get_value())>;
73  static constexpr value_type value {get_value()};
74  using type = fixed_number_of;
75  constexpr operator value_type() const { return value; }
76  constexpr value_type operator()() const { return value; }
77  };
78 
79 
83  template<typename T>
85 
86 
87 } // namespace OpenKalman::values
88 
89 #endif //OPENKALMAN_VALUES_FIXED_NUMBER_OF_HPP
Definition: tuple_reverse.hpp:103
constexpr bool value
T is numerical value or is reducible to a numerical value.
Definition: value.hpp:31
constexpr auto fixed_number_of_v
Helper template for fixed_number_of.
Definition: fixed_number_of.hpp:84
The fixed number associated with a values::fixed.
Definition: fixed_number_of.hpp:45
Definition for values::abs.
Definition: constant_coefficient.hpp:25
Definition: fixed_number_of.hpp:29
Definition for ::fixed.
Definition for ::value.