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

Generated via doxygen2docusaurus 2.2.2 by Doxygen 1.17.0.