OpenKalman
fixed.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_VALUE_FIXED_HPP
17 #define OPENKALMAN_VALUE_FIXED_HPP
18 
19 #ifdef __cpp_concepts
20 #include <concepts>
21 #endif
22 #include <type_traits>
23 #include "number.hpp"
24 
25 namespace OpenKalman::values
26 {
27 #ifndef __cpp_concepts
28  namespace internal
29  {
30  // These functions are also used in values::to_number
31 
32  template<typename T, typename = void>
33  struct has_value_member : std::false_type {};
34 
35  template<typename T>
36  struct has_value_member<T, std::enable_if_t<number<decltype(T::value)>>> : std::true_type {};
37 
38  template<typename T, typename = void>
39  struct call_result_is_fixed : std::false_type {};
40 
41  template<typename T>
42  struct call_result_is_fixed<T, std::void_t<std::bool_constant<(T{}(), true)>>> : std::true_type {};
43 
44  } // namespace internal
45 #endif
46 
47 
51  template<typename T>
52 #ifdef __cpp_concepts
53  concept fixed = std::default_initializable<std::decay_t<T>> and
54  (requires { {std::decay_t<T>::value} -> number; } or
55  requires {
56  {std::decay_t<T>{}()} -> number;
57  typename std::bool_constant<(std::decay_t<T>{}(), true)>;
58  });
59 #else
60  constexpr bool fixed = std::is_default_constructible_v<std::decay_t<T>> and
61  (internal::has_value_member<std::decay_t<T>>::value or internal::call_result_is_fixed<std::decay_t<T>>::value);
62 #endif
63 
64 
65 } // namespace OpenKalman::values
66 
67 #endif //OPENKALMAN_VALUE_FIXED_HPP
constexpr bool number
T is a numerical type.
Definition: number.hpp:33
Definition: tuple_reverse.hpp:103
constexpr bool value
T is numerical value or is reducible to a numerical value.
Definition: value.hpp:31
Definition for values::abs.
Definition: constant_coefficient.hpp:25
constexpr bool fixed
T is a values::value that is determinable at compile time.
Definition: fixed.hpp:60
Definition for values::number.