OpenKalman
fixed_value_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-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_VALUES_FIXED_VALUE_OF_HPP
17 #define OPENKALMAN_VALUES_FIXED_VALUE_OF_HPP
18 
19 #include <type_traits>
21 
22 namespace OpenKalman::values
23 {
24 #ifndef __cpp_concepts
25  namespace detail
26  {
27  template<typename T, typename = void>
28  struct fixed_value_of_impl : std::false_type {};
29 
30  template<typename T>
31  struct fixed_value_of_impl<T, std::void_t<decltype(T::value)>> : std::true_type {};
32  }
33 #endif
34 
35 
39 #ifdef __cpp_concepts
40  template<typename T>
41 #else
42  template<typename T, typename = void>
43 #endif
44  struct fixed_value_of {};
45 
46 
48 #ifdef __cpp_concepts
49  template<fixed T>
50  struct fixed_value_of<T>
51 #else
52  template<typename T>
53  struct fixed_value_of<T, std::enable_if_t<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_value_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_value_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 }
88 
89 #endif
constexpr auto fixed_value_of_v
Helper template for fixed_value_of.
Definition: fixed_value_of.hpp:84
The fixed value associated with a fixed.
Definition: fixed_value_of.hpp:44
constexpr bool value
T is a fixed or dynamic value that is reducible to a number.
Definition: value.hpp:45
Definition: fixed_value_of.hpp:28
Definition for values::abs.
Definition: fixed-constants.hpp:23
Definition for ::fixed.