Skip to main content

literals-inlines.h File

C++ header file with inline implementations for the µTest++ literals and type wrappers. More...

Included Headers

#include <cstdint>

Namespaces Index

namespacemicro_os_plus

The primary namespace for the µOS++ framework. More...

namespacemicro_test_plus

Primary namespace for the µTest++ testing framework. More...

namespaceliterals

User-defined literals and type wrappers for the µTest++ testing framework. More...

Operators Index

constexpr autooperator""_b (const char *name, decltype(sizeof("")) size)

User-defined literal operator to convert to bool. More...

template <char... Cs>
constexpr autooperator""_c ()

User-defined literal operator to convert to char. More...

template <char... Cs>
constexpr autooperator""_d ()

User-defined literal operator to convert to double. More...

template <char... Cs>
constexpr autooperator""_f ()

User-defined literal operator to convert to float. More...

template <char... Cs>
constexpr autooperator""_i ()

User-defined literal operator to convert to int. More...

template <char... Cs>
constexpr autooperator""_i16 ()

User-defined literal operator to convert to int16_t. More...

template <char... Cs>
constexpr autooperator""_i32 ()

User-defined literal operator to convert to int32_t. More...

template <char... Cs>
constexpr autooperator""_i64 ()

User-defined literal operator to convert to int64_t. More...

template <char... Cs>
constexpr autooperator""_i8 ()

User-defined literal operator to convert to int8_t. More...

template <char... Cs>
constexpr autooperator""_l ()

User-defined literal operator to convert to long. More...

template <char... Cs>
constexpr autooperator""_ld ()

User-defined literal operator to convert to long double. More...

template <char... Cs>
constexpr autooperator""_ll ()

User-defined literal operator to convert to long long. More...

template <char... Cs>
constexpr autooperator""_s ()

User-defined literal operator to convert to short. More...

template <char... Cs>
constexpr autooperator""_sc ()

User-defined literal operator to convert to signed char. More...

template <char... Cs>
constexpr autooperator""_u ()

User-defined literal operator to convert to unsigned. More...

template <char... Cs>
constexpr autooperator""_u16 ()

User-defined literal operator to convert to uint16_t. More...

template <char... Cs>
constexpr autooperator""_u32 ()

User-defined literal operator to convert to uint32_t. More...

template <char... Cs>
constexpr autooperator""_u64 ()

User-defined literal operator to convert to uint64_t. More...

template <char... Cs>
constexpr autooperator""_u8 ()

User-defined literal operator to convert to uint8_t. More...

template <char... Cs>
constexpr autooperator""_uc ()

User-defined literal operator to convert to unsigned char. More...

template <char... Cs>
constexpr autooperator""_ul ()

User-defined literal operator to convert to unsigned long. More...

template <char... Cs>
constexpr autooperator""_ull ()

User-defined literal operator to convert to unsigned long long. More...

template <char... Cs>
constexpr autooperator""_us ()

User-defined literal operator to convert to unsigned short. More...

Description

C++ header file with inline implementations for the µTest++ literals and type wrappers.

This header provides the inline implementations for the user-defined literal operators and type wrappers used within the µTest++ framework. It defines the logic for generating strongly-typed integral, floating-point, and boolean constants at compile time, enabling expressive and type-safe test expressions.

The implemented literal operators support a wide range of C++ fundamental types, allowing constants to be suffixed with type-specific identifiers (such as _i, _u16, _f, _d, _b, etc.) to produce values that integrate seamlessly with the µTest++ comparators and reporting mechanisms.

Specialised wrappers are provided for named boolean literals, supporting enhanced expressiveness and type safety in test conditions.

All definitions reside within the micro_os_plus::micro_test_plus::literals namespace, ensuring clear separation from user code and minimising the risk of naming conflicts.

The header files are organised within the include/micro-os-plus/micro-test-plus folder to maintain a structured and modular codebase.

This file is intended solely for internal use within the framework and should not be included directly by user code.

File Listing

The file content with the documentation metadata removed is:

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 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// ----------------------------------------------------------------------------

Generated via doxygen2docusaurus 2.2.0 by Doxygen 1.17.0.