micro-test-plus 4.1.0
µTest++ Testing Framework
Loading...
Searching...
No Matches
type-traits-inlines.h
Go to the documentation of this file.
1/*
2 * This file is part of the µOS++ project (https://micro-os-plus.github.io/).
3 * Copyright (c) 2021-2026 Liviu Ionescu. All rights reserved.
4 *
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose is hereby granted, under the terms of the MIT license.
7 *
8 * If a copy of the license was not distributed with this file, it can be
9 * obtained from https://opensource.org/licenses/mit.
10 *
11 * Major parts of the code are inspired from v1.1.8 of the Boost UT project,
12 * released under the terms of the Boost Version 1.0 Software License,
13 * which can be obtained from https://www.boost.org/LICENSE_1_0.txt.
14 */
15
16// ----------------------------------------------------------------------------
17
42
43#ifndef MICRO_TEST_PLUS_TYPE_TRAITS_INLINES_H_
44#define MICRO_TEST_PLUS_TYPE_TRAITS_INLINES_H_
45
46// ----------------------------------------------------------------------------
47
48#ifdef __cplusplus
49
50// ----------------------------------------------------------------------------
51
52#if defined(__GNUC__)
53#pragma GCC diagnostic push
54#if defined(__clang__)
55#pragma clang diagnostic ignored "-Wc++98-compat"
56#pragma clang diagnostic ignored "-Wc++98-compat-pedantic"
57#endif
58#endif
59
60// ============================================================================
61
63{
64 namespace type_traits
65 {
66 // ========================================================================
67
72 template <class T>
73 constexpr value_base_<T>::value_base_ (const T& v) noexcept : value_{ v }
74 {
75 }
76
81 template <class T>
82 constexpr value_base_<T>::
83 operator T () const noexcept
84 {
85 return value_;
86 }
87
92 template <class T>
93 constexpr T
94 value_base_<T>::get (void) const noexcept
95 {
96 return value_;
97 }
98
99 // ------------------------------------------------------------------------
100
105 template <auto N>
107 : value_base_<decltype (N)>{ N }
108 {
109 }
110
116 template <auto N>
117 constexpr auto
119 {
120 return integral_constant<-N>{};
121 }
122
123 // ------------------------------------------------------------------------
124
129 template <class T, auto N, auto D, auto Size, auto P>
131 operator T () const noexcept
132 {
133 return value;
134 }
135
140 template <class T, auto N, auto D, auto Size, auto P>
141 constexpr T
143 {
144 return value;
145 }
146
152 template <class T, auto N, auto D, auto Size, auto P>
153 constexpr auto
155 {
156 return floating_point_constant<T, N, D, Size, -P>{};
157 }
158
159 // ------------------------------------------------------------------------
160
165 template <class T>
167 const T& _value) noexcept
168 : value_base_<T>{ _value }
169 {
170 }
171
172 // ------------------------------------------------------------------------
173
178 template <class T>
179 constexpr value<T>::value (const T& _value) noexcept
180 : value_base_<T>{ _value }
181 {
182 }
183
184 // ------------------------------------------------------------------------
185
191 template <class T>
192 requires is_floating_point<T>
193 constexpr value<T>::value (const T& _value, const T precision) noexcept
194 : value_base_<T>{ _value }, epsilon{ precision }
195 {
196 }
197
203 template <class T>
204 requires is_floating_point<T>
205 constexpr value<T>::value (const T& val)
206 : value{ val,
207 T (1)
208 / math::pow (T (10),
209 math::den_size<unsigned long long> (val)) }
210 {
211 }
212
213 // ------------------------------------------------------------------------
214 } // namespace type_traits
215
216 // --------------------------------------------------------------------------
217} // namespace micro_os_plus::micro_test_plus
218
219#if defined(__GNUC__)
220#pragma GCC diagnostic pop
221#endif
222
223// ----------------------------------------------------------------------------
224
225#endif // __cplusplus
226
227// ----------------------------------------------------------------------------
228
229#endif // MICRO_TEST_PLUS_TYPE_TRAITS_INLINES_H_
230
231// ----------------------------------------------------------------------------
Type trait utilities and metaprogramming support for the µTest++ testing framework.
Primary namespace for the µTest++ testing framework.
Struct template representing a generic floating point constant with custom size and precision.
constexpr auto operator-() const noexcept
Unary minus operator.
constexpr T get(void) const noexcept
Getter for the compile-time constant value.
static constexpr auto value
The compile-time constant value.
constexpr genuine_integral_value(const T &_value) noexcept
Constructs a genuine_integral_value with the specified value.
constexpr integral_constant() noexcept
Default constructor. Initialises the base with N.
constexpr auto operator-() const noexcept
Unary minus operator.
constexpr value_base_(const T &v) noexcept
Constructs a value_base_ with the given value.
constexpr T get(void) const noexcept
Getter for the stored value.
constexpr value(const T &_value) noexcept
Constructs a value object with the specified value.