OpenKalman
number_traits.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-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_NUMBER_TRAITS_HPP
17 #define OPENKALMAN_NUMBER_TRAITS_HPP
18 
19 #include <limits>
20 #include <complex>
21 #include "basics/basics.hpp"
22 
23 namespace OpenKalman::interface
24 {
31 #ifdef __cpp_concepts
32  template<typename T>
33 #else
34  template<typename T, typename = void>
35 #endif
37  {
42  static constexpr bool is_specialized = false;
43 
44 
48  static constexpr bool is_complex = false;
49 
50 
51 #ifdef DOXYGEN_SHOULD_SKIP_THIS
52 
55  static constexpr auto real = [](T t) { return std::real(std::move(t)); };
56 
57 
61  static constexpr auto imag = [](T t) { return std::imag(std::move(t)); };
62 
63 
69  static constexpr auto make_complex = [](auto re, auto im) { return std::complex<T> {std::move(re), std::move(im)}; };
70 
71 #endif
72  };
73 
74 
78 #ifdef __cpp_concepts
79  template<typename T> requires std::is_arithmetic_v<T>
80  struct number_traits<T>
81 #else
82  template<typename T>
83  struct number_traits<T, std::enable_if_t<std::is_arithmetic_v<T>>>
84 #endif
85  {
86  static constexpr bool is_specialized = true;
87  static constexpr bool is_complex = false;
88  static constexpr auto real = [](T t) { return std::real(std::move(t)); };
89  static constexpr auto imag = [](T t) { return std::imag(std::move(t)); };
90  static constexpr auto make_complex = [](T re, T im) { return std::complex<T> {std::move(re), std::move(im)}; };
91  };
92 
93 
97  template<typename T>
99  {
100  static constexpr bool is_specialized = true;
101  static constexpr bool is_complex = true;
102  static constexpr auto real = [](std::complex<T> t) { return std::real(std::move(t)); };
103  static constexpr auto imag = [](std::complex<T> t) { return std::imag(std::move(t)); };
104  static constexpr auto make_complex = [](T re, T im) { return std::complex<T> {std::move(re), std::move(im)}; };
105  };
106 
107 }
108 
109 #endif
Definition: basics.hpp:41
constexpr bool complex
T is a value that reduces to std::complex or a custom complex type.
Definition: complex.hpp:47
static constexpr bool is_specialized
This value is true for all T for which there exists a specialization of numeric_traits.
Definition: number_traits.hpp:42
constexpr auto imag(const Arg &arg)
A constexpr function to obtain the imaginary part of a (complex) number.
Definition: imag.hpp:40
constexpr auto real(const Arg &arg)
A constexpr function to obtain the real part of a (complex) number.
Definition: real.hpp:40
Basic definitions for OpenKalman as a whole.
static constexpr bool is_complex
Whether T is a complex number.
Definition: number_traits.hpp:48
Definition: number_traits.hpp:36