OpenKalman
core-concepts.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) 2021-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_COMPATIBILITY_CORE_CONCEPTS_HPP
17 #define OPENKALMAN_COMPATIBILITY_CORE_CONCEPTS_HPP
18 
19 #include "language-features.hpp"
20 
21 namespace OpenKalman::stdex
22 {
23 #ifdef __cpp_lib_concepts
24  using std::same_as;
25  using std::derived_from;
26  using std::convertible_to;
27  using std::integral;
28  using std::signed_integral;
29  using std::unsigned_integral;
30  using std::floating_point;
31  using std::destructible;
32  using std::constructible_from;
33  using std::default_initializable;
34  using std::move_constructible;
35  using std::copy_constructible;
36 #else
37  template<typename T, typename U>
38  inline constexpr bool
39  same_as = std::is_same_v<T, U> and std::is_same_v<U, T>;
40 
41 
42  template<typename Derived, typename Base>
43  inline constexpr bool
44  derived_from =
45  std::is_base_of_v<Base, Derived> and
46  std::is_convertible_v<const volatile Derived*, const volatile Base*>;
47 
48 
49  namespace detail
50  {
51  template<typename From, typename To, typename = void>
52  struct convertible_to_impl : std::false_type {};
53 
54  template<typename From, typename To>
55  struct convertible_to_impl<From, To, std::void_t<decltype(static_cast<To>(std::declval<From>()))>> : std::true_type {};
56  }
57 
58 
59  template<typename From, typename To>
60  inline constexpr bool
61  convertible_to = std::is_convertible_v<From, To> and detail::convertible_to_impl<From, To>::value;
62 
63 
64  template<typename T>
65  inline constexpr bool
66  integral = std::is_integral_v<T>;
67 
68 
69  template<typename T>
70  inline constexpr bool
71  signed_integral = integral<T> and std::is_signed_v<T>;
72 
73 
74  template<typename T>
75  inline constexpr bool
76  unsigned_integral = integral<T> and not std::is_signed_v<T>;
77 
78 
79  template<typename T>
80  inline constexpr bool
81  floating_point = std::is_floating_point_v<T>;
82 
83 
84  template<typename T, typename...Args>
85  inline constexpr bool
86  destructible = std::is_nothrow_destructible_v<T>;
87 
88 
89  template<typename T, typename...Args>
90  inline constexpr bool
91  constructible_from = destructible<T> and std::is_constructible_v<T, Args...>;
92 
93 
94  namespace detail
95  {
96  template<typename T, typename = void>
97  struct default_initializable_impl : std::false_type {};
98 
99  template<typename T>
100  struct default_initializable_impl<T, std::void_t<decltype(T{}), decltype(::new T)>> : std::true_type {};
101  }
102 
103 
104  template<typename T>
105  inline constexpr bool
106  default_initializable = constructible_from<T> and detail::default_initializable_impl<T>::value;
107 
108 
109  template<typename T>
110  inline constexpr bool
111  move_constructible = constructible_from<T, T> and convertible_to<T, T>;
112 
113 
114  template<typename T>
115  inline constexpr bool
116  copy_constructible =
117  move_constructible<T> and
118  constructible_from<T, T&> and convertible_to<T&, T> and
119  constructible_from<T, const T&> && convertible_to<const T&, T> and
120  constructible_from<T, const T> && convertible_to<const T, T>;
121 
122 #endif
123 }
124 
125 
126 #endif
Definitions relating to the availability of c++ language features.
Definition: core-concepts.hpp:52
Definition: basics.hpp:55