OpenKalman
to_number.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-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_TO_NUMBER_HPP
17 #define OPENKALMAN_VALUE_TO_NUMBER_HPP
18 
21 
22 namespace OpenKalman::values
23 {
27 #ifdef __cpp_concepts
28  template<value Arg>
29  constexpr number auto
30  to_number(Arg arg)
31 #else
32  template<typename Arg>
33  constexpr auto
34  to_number(Arg arg)
35 #endif
36  {
37 #ifdef __cpp_concepts
38  if constexpr (requires { {std::decay_t<Arg>::value} -> number; }) return std::decay_t<Arg>::value;
39  else if constexpr (requires { {std::move(arg)()} -> number; }) return std::move(arg)();
40  else return std::move(arg);
41 #else
42  static_assert(value<Arg>);
43  if constexpr (internal::has_value_member<std::decay_t<Arg>>::value) return std::decay_t<Arg>::value;
44  else if constexpr (internal::call_result_is_fixed<std::decay_t<Arg>>::value or internal::is_dynamic<std::decay_t<Arg>>::value)
45  return std::move(arg)();
46  else { static_assert(number<Arg>); return std::move(arg); }
47 #endif
48  }
49 
50 
51 } // namespace OpenKalman::values
52 
53 #endif //OPENKALMAN_VALUE_TO_NUMBER_HPP
constexpr bool number
T is a numerical type.
Definition: number.hpp:33
constexpr bool value
T is numerical value or is reducible to a numerical value.
Definition: value.hpp:31
constexpr auto to_number(Arg arg)
Convert any values::value to a values::number.
Definition: to_number.hpp:34
Definition for values::abs.
Definition: constant_coefficient.hpp:25
Definition for values::number.
Definition for ::value.