micro-test-plus 4.1.0
µTest++ Testing Framework
Loading...
Searching...
No Matches
literals-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
49
50#ifndef MICRO_TEST_PLUS_LITERALS_INLINES_H_
51#define MICRO_TEST_PLUS_LITERALS_INLINES_H_
52
53// ----------------------------------------------------------------------------
54
55#ifdef __cplusplus
56
57// ----------------------------------------------------------------------------
58
59#include <cstdint>
60
61// ----------------------------------------------------------------------------
62
63#if defined(__GNUC__)
64#pragma GCC diagnostic push
65#pragma GCC diagnostic ignored "-Waggregate-return"
66#if defined(__clang__)
67#pragma clang diagnostic ignored "-Wc++98-compat"
68#pragma clang diagnostic ignored "-Wc++98-compat-pedantic"
69#endif
70#endif
71
72// ===========================================================================
73
75{
76 // --------------------------------------------------------------------------
77
78 namespace literals
79 {
80
92 template <char... Cs>
93 constexpr auto
94 operator""_i ()
95 {
96 return type_traits::integral_constant<math::num<int, Cs...> ()>{};
97 }
98
110 template <char... Cs>
111 constexpr auto
112 operator""_s ()
113 {
114 return type_traits::integral_constant<math::num<short, Cs...> ()>{};
115 }
116
128 template <char... Cs>
129 constexpr auto
130 operator""_c ()
131 {
132 return type_traits::integral_constant<math::num<char, Cs...> ()>{};
133 }
134
146 template <char... Cs>
147 constexpr auto
148 operator""_sc ()
149 {
151 math::num<signed char, Cs...> ()>{};
152 }
153
165 template <char... Cs>
166 constexpr auto
167 operator""_l ()
168 {
169 return type_traits::integral_constant<math::num<long, Cs...> ()>{};
170 }
171
183 template <char... Cs>
184 constexpr auto
185 operator""_ll ()
186 {
187 return type_traits::integral_constant<math::num<long long, Cs...> ()>{};
188 }
189
201 template <char... Cs>
202 constexpr auto
203 operator""_u ()
204 {
205 return type_traits::integral_constant<math::num<unsigned, Cs...> ()>{};
206 }
207
219 template <char... Cs>
220 constexpr auto
221 operator""_uc ()
222 {
224 math::num<unsigned char, Cs...> ()>{};
225 }
226
238 template <char... Cs>
239 constexpr auto
240 operator""_us ()
241 {
243 math::num<unsigned short, Cs...> ()>{};
244 }
245
257 template <char... Cs>
258 constexpr auto
259 operator""_ul ()
260 {
262 math::num<unsigned long, Cs...> ()>{};
263 }
264
276 template <char... Cs>
277 constexpr auto
278 operator""_ull ()
279 {
281 math::num<unsigned long long, Cs...> ()>{};
282 }
283
295 template <char... Cs>
296 constexpr auto
297 operator""_i8 ()
298 {
300 math::num<std::int8_t, Cs...> ()>{};
301 }
302
314 template <char... Cs>
315 constexpr auto
316 operator""_i16 ()
317 {
319 math::num<std::int16_t, Cs...> ()>{};
320 }
321
333 template <char... Cs>
334 constexpr auto
335 operator""_i32 ()
336 {
338 math::num<std::int32_t, Cs...> ()>{};
339 }
340
352 template <char... Cs>
353 constexpr auto
354 operator""_i64 ()
355 {
357 math::num<std::int64_t, Cs...> ()>{};
358 }
359
371 template <char... Cs>
372 constexpr auto
373 operator""_u8 ()
374 {
376 math::num<std::uint8_t, Cs...> ()>{};
377 }
378
390 template <char... Cs>
391 constexpr auto
392 operator""_u16 ()
393 {
395 math::num<std::uint16_t, Cs...> ()>{};
396 }
397
409 template <char... Cs>
410 constexpr auto
411 operator""_u32 ()
412 {
414 math::num<std::uint32_t, Cs...> ()>{};
415 }
416
428 template <char... Cs>
429 constexpr auto
430 operator""_u64 ()
431 {
433 math::num<std::uint64_t, Cs...> ()>{};
434 }
435
447 template <char... Cs>
448 constexpr auto
449 operator""_f ()
450 {
452 float, math::num<unsigned long, Cs...> (),
454 math::den_size<unsigned long, Cs...> ()>{};
455 }
456
468 template <char... Cs>
469 constexpr auto
470 operator""_d ()
471 {
473 double, math::num<unsigned long, Cs...> (),
475 math::den_size<unsigned long, Cs...> ()>{};
476 }
477
489 template <char... Cs>
490 constexpr auto
491 operator""_ld ()
492 {
494 long double, math::num<unsigned long long, Cs...> (),
496 math::den_size<unsigned long long, Cs...> ()>{};
497 }
498
515 constexpr auto
516 operator""_b (const char* name, decltype (sizeof ("")) size)
517 {
527 struct named : std::string_view, type_traits::op
528 {
532 using value_type = bool;
533
543 constexpr
544 operator value_type () const
545 {
546 return true;
547 }
548
558 constexpr auto
559 operator== (const named&) const
560 {
561 return true;
562 }
563
573 constexpr auto
574 operator== (const bool other) const
575 {
576 return other;
577 }
578 };
579
580 return named{ { name, size }, {} };
581 }
582
583 // ------------------------------------------------------------------------
584 } // namespace literals
585
586 // ==========================================================================
587
593 template <class T>
594 constexpr _t<T>::_t (const T& t) : type_traits::value<T>{ t }
595 {
596 }
597
603 template <class T>
604 constexpr to_t<T>::to_t (const T& t) : type_traits::value<T>{ t }
605 {
606 }
607
608 // --------------------------------------------------------------------------
609} // namespace micro_os_plus::micro_test_plus
610
611#if defined(__GNUC__)
612#pragma GCC diagnostic pop
613#endif
614
615// ----------------------------------------------------------------------------
616
617#endif // __cplusplus
618
619// ----------------------------------------------------------------------------
620
621#endif // MICRO_TEST_PLUS_LITERALS_INLINES_H_
622
623// ----------------------------------------------------------------------------
type_traits::value< std::uint16_t > _u16
Strongly-typed wrapper for std::uint16_t values.
Definition literals.h:589
type_traits::value< unsigned long long > _ull
Strongly-typed wrapper for unsigned long long values.
Definition literals.h:547
type_traits::value< short > _s
Strongly-typed wrapper for short values.
Definition literals.h:491
type_traits::value< int > _i
Strongly-typed wrapper for int values.
Definition literals.h:498
type_traits::value< unsigned char > _uc
Strongly-typed wrapper for unsigned char values.
Definition literals.h:526
type_traits::value< std::uint8_t > _u8
Strongly-typed wrapper for std::uint8_t values.
Definition literals.h:582
type_traits::value< std::int8_t > _i8
Strongly-typed wrapper for std::int8_t values.
Definition literals.h:554
type_traits::value< std::int32_t > _i32
Strongly-typed wrapper for std::int32_t values.
Definition literals.h:568
constexpr _t(const T &t)
Constructor for the deprecated strongly-typed wrapper.
type_traits::value< unsigned short > _us
Strongly-typed wrapper for unsigned short values.
Definition literals.h:533
type_traits::value< double > _d
Strongly-typed wrapper for double values.
Definition literals.h:615
type_traits::value< long long > _ll
Strongly-typed wrapper for long long values.
Definition literals.h:512
type_traits::value< unsigned > _u
Strongly-typed wrapper for unsigned values.
Definition literals.h:519
type_traits::value< bool > _b
Strongly-typed wrapper for bool values.
Definition literals.h:470
type_traits::value< long double > _ld
Strongly-typed wrapper for long double values.
Definition literals.h:622
type_traits::value< unsigned long > _ul
Strongly-typed wrapper for unsigned long values.
Definition literals.h:540
constexpr to_t(const T &t)
Constructor for the strongly-typed wrapper.
type_traits::value< long > _l
Strongly-typed wrapper for long values.
Definition literals.h:505
type_traits::value< char > _c
Strongly-typed wrapper for char values.
Definition literals.h:477
type_traits::value< std::uint64_t > _u64
Strongly-typed wrapper for std::uint64_t values.
Definition literals.h:603
type_traits::value< signed char > _sc
Strongly-typed wrapper for signed char values.
Definition literals.h:484
type_traits::value< float > _f
Strongly-typed wrapper for float values.
Definition literals.h:609
type_traits::value< std::int64_t > _i64
Strongly-typed wrapper for std::int64_t values.
Definition literals.h:575
type_traits::value< std::int16_t > _i16
Strongly-typed wrapper for std::int16_t values.
Definition literals.h:561
type_traits::value< std::uint32_t > _u32
Strongly-typed wrapper for std::uint32_t values.
Definition literals.h:596
User-defined literals and type wrappers for the µTest++ testing framework.
consteval auto den(void) -> T
Computes the decimal part of a number represented as an array of characters.
consteval auto den_size(void) -> T
Computes the number of decimal places in a number represented as an array of characters.
consteval auto num(void) -> T
Computes the integral value of a number represented as an array of characters.
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.
Struct template representing a generic integral constant.
Empty base struct for all operator types.
constexpr value(const T &_value, const T precision) noexcept
Constructs a floating-point value with a specified precision.