micro-test-plus 5.0.1
µ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_OS_PLUS_MICRO_TEST_PLUS_INLINES_LITERALS_INLINES_H_
51#define MICRO_OS_PLUS_MICRO_TEST_PLUS_INLINES_LITERALS_INLINES_H_
52
53// ----------------------------------------------------------------------------
54
55#if defined(__cplusplus)
56
57// ----------------------------------------------------------------------------
58
59#include <cstdint>
60
61// ----------------------------------------------------------------------------
62
63#if defined(__GNUC__)
64#pragma GCC diagnostic push
65
66#pragma GCC diagnostic ignored "-Waggregate-return"
67#if defined(__clang__)
68#pragma clang diagnostic ignored "-Wc++98-compat"
69#pragma clang diagnostic ignored "-Wc++98-compat-pedantic"
70#endif // defined(__clang__)
71#endif // defined(__GNUC__)
72
73// ===========================================================================
74
76{
77 // --------------------------------------------------------------------------
78
79 namespace literals
80 {
81
93 template <char... Cs>
94 constexpr auto
95 operator""_i ()
96 {
97 return type_traits::integral_constant<math::num<int, Cs...> ()>{};
98 }
99
111 template <char... Cs>
112 constexpr auto
113 operator""_s ()
114 {
115 return type_traits::integral_constant<math::num<short, Cs...> ()>{};
116 }
117
129 template <char... Cs>
130 constexpr auto
131 operator""_c ()
132 {
133 return type_traits::integral_constant<math::num<char, Cs...> ()>{};
134 }
135
147 template <char... Cs>
148 constexpr auto
149 operator""_sc ()
150 {
152 math::num<signed char, Cs...> ()>{};
153 }
154
166 template <char... Cs>
167 constexpr auto
168 operator""_l ()
169 {
170 return type_traits::integral_constant<math::num<long, Cs...> ()>{};
171 }
172
184 template <char... Cs>
185 constexpr auto
186 operator""_ll ()
187 {
188 return type_traits::integral_constant<math::num<long long, Cs...> ()>{};
189 }
190
202 template <char... Cs>
203 constexpr auto
204 operator""_u ()
205 {
206 return type_traits::integral_constant<math::num<unsigned, Cs...> ()>{};
207 }
208
220 template <char... Cs>
221 constexpr auto
222 operator""_uc ()
223 {
225 math::num<unsigned char, Cs...> ()>{};
226 }
227
239 template <char... Cs>
240 constexpr auto
241 operator""_us ()
242 {
244 math::num<unsigned short, Cs...> ()>{};
245 }
246
258 template <char... Cs>
259 constexpr auto
260 operator""_ul ()
261 {
263 math::num<unsigned long, Cs...> ()>{};
264 }
265
277 template <char... Cs>
278 constexpr auto
279 operator""_ull ()
280 {
282 math::num<unsigned long long, Cs...> ()>{};
283 }
284
296 template <char... Cs>
297 constexpr auto
298 operator""_i8 ()
299 {
301 math::num<std::int8_t, Cs...> ()>{};
302 }
303
315 template <char... Cs>
316 constexpr auto
317 operator""_i16 ()
318 {
320 math::num<std::int16_t, Cs...> ()>{};
321 }
322
334 template <char... Cs>
335 constexpr auto
336 operator""_i32 ()
337 {
339 math::num<std::int32_t, Cs...> ()>{};
340 }
341
353 template <char... Cs>
354 constexpr auto
355 operator""_i64 ()
356 {
358 math::num<std::int64_t, Cs...> ()>{};
359 }
360
372 template <char... Cs>
373 constexpr auto
374 operator""_u8 ()
375 {
377 math::num<std::uint8_t, Cs...> ()>{};
378 }
379
391 template <char... Cs>
392 constexpr auto
393 operator""_u16 ()
394 {
396 math::num<std::uint16_t, Cs...> ()>{};
397 }
398
410 template <char... Cs>
411 constexpr auto
412 operator""_u32 ()
413 {
415 math::num<std::uint32_t, Cs...> ()>{};
416 }
417
429 template <char... Cs>
430 constexpr auto
431 operator""_u64 ()
432 {
434 math::num<std::uint64_t, Cs...> ()>{};
435 }
436
448 template <char... Cs>
449 constexpr auto
450 operator""_f ()
451 {
453 float, math::num<unsigned long, Cs...> (),
455 math::den_size<unsigned long, Cs...> ()>{};
456 }
457
469 template <char... Cs>
470 constexpr auto
471 operator""_d ()
472 {
474 double, math::num<unsigned long, Cs...> (),
476 math::den_size<unsigned long, Cs...> ()>{};
477 }
478
490 template <char... Cs>
491 constexpr auto
492 operator""_ld ()
493 {
495 long double, math::num<unsigned long long, Cs...> (),
497 math::den_size<unsigned long long, Cs...> ()>{};
498 }
499
516 constexpr auto
517 operator""_b (const char* name, decltype (sizeof ("")) size)
518 {
528 struct named : std::string_view, type_traits::op
529 {
533 using value_type = bool;
534
544 constexpr
545 operator value_type () const
546 {
547 return true;
548 }
549
559 constexpr auto
560 operator== (const named&) const
561 {
562 return true;
563 }
564
574 constexpr auto
575 operator== (const bool other) const
576 {
577 return other;
578 }
579 };
580
581 return named{ { name, size }, {} };
582 }
583
584 // ------------------------------------------------------------------------
585 } // namespace literals
586
587 // ==========================================================================
588
594 template <class T>
595 constexpr _t<T>::_t (const T& t) : type_traits::value<T>{ t }
596 {
597 }
598
604 template <class T>
605 constexpr to_t<T>::to_t (const T& t) : type_traits::value<T>{ t }
606 {
607 }
608
609 // --------------------------------------------------------------------------
610} // namespace micro_os_plus::micro_test_plus
611
612#if defined(__GNUC__)
613#pragma GCC diagnostic pop
614#endif // defined(__GNUC__)
615
616// ----------------------------------------------------------------------------
617
618#endif // defined(__cplusplus)
619
620// ----------------------------------------------------------------------------
621
622#endif // MICRO_OS_PLUS_MICRO_TEST_PLUS_INLINES_LITERALS_INLINES_H_
623
624// ----------------------------------------------------------------------------
type_traits::value< std::uint16_t > _u16
Strongly-typed wrapper for std::uint16_t values.
Definition literals.h:599
type_traits::value< unsigned long long > _ull
Strongly-typed wrapper for unsigned long long values.
Definition literals.h:557
type_traits::value< short > _s
Strongly-typed wrapper for short values.
Definition literals.h:501
type_traits::value< int > _i
Strongly-typed wrapper for int values.
Definition literals.h:508
type_traits::value< unsigned char > _uc
Strongly-typed wrapper for unsigned char values.
Definition literals.h:536
type_traits::value< std::uint8_t > _u8
Strongly-typed wrapper for std::uint8_t values.
Definition literals.h:592
type_traits::value< std::int8_t > _i8
Strongly-typed wrapper for std::int8_t values.
Definition literals.h:564
type_traits::value< std::int32_t > _i32
Strongly-typed wrapper for std::int32_t values.
Definition literals.h:578
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:543
type_traits::value< double > _d
Strongly-typed wrapper for double values.
Definition literals.h:625
type_traits::value< long long > _ll
Strongly-typed wrapper for long long values.
Definition literals.h:522
type_traits::value< unsigned > _u
Strongly-typed wrapper for unsigned values.
Definition literals.h:529
type_traits::value< bool > _b
Strongly-typed wrapper for bool values.
Definition literals.h:480
type_traits::value< long double > _ld
Strongly-typed wrapper for long double values.
Definition literals.h:632
type_traits::value< unsigned long > _ul
Strongly-typed wrapper for unsigned long values.
Definition literals.h:550
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:515
type_traits::value< char > _c
Strongly-typed wrapper for char values.
Definition literals.h:487
type_traits::value< std::uint64_t > _u64
Strongly-typed wrapper for std::uint64_t values.
Definition literals.h:613
type_traits::value< signed char > _sc
Strongly-typed wrapper for signed char values.
Definition literals.h:494
type_traits::value< float > _f
Strongly-typed wrapper for float values.
Definition literals.h:619
type_traits::value< std::int64_t > _i64
Strongly-typed wrapper for std::int64_t values.
Definition literals.h:585
type_traits::value< std::int16_t > _i16
Strongly-typed wrapper for std::int16_t values.
Definition literals.h:571
type_traits::value< std::uint32_t > _u32
Strongly-typed wrapper for std::uint32_t values.
Definition literals.h:606
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.