Skip to main content

literals.h File

C++ header file with declarations for the µTest++ user-defined literals and type wrappers. More...

Included Headers

#include "type-traits.h" #include "math.h" #include <cstdint> #include "inlines/literals-inlines.h"

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

Classes Index

struct_t<T>

Deprecated generic strongly-typed wrapper for explicit type conversion. More...

structto_t<T>

Generic strongly-typed wrapper for explicit type conversion. 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...

Deprecated Type Wrappers Index

using_b = type_traits::value< bool >

Strongly-typed wrapper for bool values. More...

using_c = type_traits::value< char >

Strongly-typed wrapper for char values. More...

using_d = type_traits::value< double >

Strongly-typed wrapper for double values. More...

using_f = type_traits::value< float >

Strongly-typed wrapper for float values. More...

using_i = type_traits::value< int >

Strongly-typed wrapper for int values. More...

using_i16 = type_traits::value< std::int16_t >

Strongly-typed wrapper for std::int16_t values. More...

using_i32 = type_traits::value< std::int32_t >

Strongly-typed wrapper for std::int32_t values. More...

using_i64 = type_traits::value< std::int64_t >

Strongly-typed wrapper for std::int64_t values. More...

using_i8 = type_traits::value< std::int8_t >

Strongly-typed wrapper for std::int8_t values. More...

using_l = type_traits::value< long >

Strongly-typed wrapper for long values. More...

using_ld = type_traits::value< long double >

Strongly-typed wrapper for long double values. More...

using_ll = type_traits::value< long long >

Strongly-typed wrapper for long long values. More...

using_s = type_traits::value< short >

Strongly-typed wrapper for short values. More...

using_sc = type_traits::value< signed char >

Strongly-typed wrapper for signed char values. More...

using_u = type_traits::value< unsigned >

Strongly-typed wrapper for unsigned values. More...

using_u16 = type_traits::value< std::uint16_t >

Strongly-typed wrapper for std::uint16_t values. More...

using_u32 = type_traits::value< std::uint32_t >

Strongly-typed wrapper for std::uint32_t values. More...

using_u64 = type_traits::value< std::uint64_t >

Strongly-typed wrapper for std::uint64_t values. More...

using_u8 = type_traits::value< std::uint8_t >

Strongly-typed wrapper for std::uint8_t values. More...

using_uc = type_traits::value< unsigned char >

Strongly-typed wrapper for unsigned char values. More...

using_ul = type_traits::value< unsigned long >

Strongly-typed wrapper for unsigned long values. More...

using_ull = type_traits::value< unsigned long long >

Strongly-typed wrapper for unsigned long long values. More...

using_us = type_traits::value< unsigned short >

Strongly-typed wrapper for unsigned short values. More...

Type Wrappers Index

usingto_b = type_traits::value< bool >

Strongly-typed wrapper for bool values. More...

usingto_c = type_traits::value< char >

Strongly-typed wrapper for char values. More...

usingto_d = type_traits::value< double >

Strongly-typed wrapper for double values. More...

usingto_f = type_traits::value< float >

Strongly-typed wrapper for float values. More...

usingto_i = type_traits::value< int >

Strongly-typed wrapper for int values. More...

usingto_i16 = type_traits::value< std::int16_t >

Strongly-typed wrapper for std::int16_t values. More...

usingto_i32 = type_traits::value< std::int32_t >

Strongly-typed wrapper for std::int32_t values. More...

usingto_i64 = type_traits::value< std::int64_t >

Strongly-typed wrapper for std::int64_t values. More...

usingto_i8 = type_traits::value< std::int8_t >

Strongly-typed wrapper for std::int8_t values. More...

usingto_l = type_traits::value< long >

Strongly-typed wrapper for long values. More...

usingto_ld = type_traits::value< long double >

Strongly-typed wrapper for long double values. More...

usingto_ll = type_traits::value< long long >

Strongly-typed wrapper for long long values. More...

usingto_s = type_traits::value< short >

Strongly-typed wrapper for short values. More...

usingto_sc = type_traits::value< signed char >

Strongly-typed wrapper for signed char values. More...

usingto_u = type_traits::value< unsigned >

Strongly-typed wrapper for unsigned values. More...

usingto_u16 = type_traits::value< std::uint16_t >

Strongly-typed wrapper for std::uint16_t values. More...

usingto_u32 = type_traits::value< std::uint32_t >

Strongly-typed wrapper for std::uint32_t values. More...

usingto_u64 = type_traits::value< std::uint64_t >

Strongly-typed wrapper for std::uint64_t values. More...

usingto_u8 = type_traits::value< std::uint8_t >

Strongly-typed wrapper for std::uint8_t values. More...

usingto_uc = type_traits::value< unsigned char >

Strongly-typed wrapper for unsigned char values. More...

usingto_ul = type_traits::value< unsigned long >

Strongly-typed wrapper for unsigned long values. More...

usingto_ull = type_traits::value< unsigned long long >

Strongly-typed wrapper for unsigned long long values. More...

usingto_us = type_traits::value< unsigned short >

Strongly-typed wrapper for unsigned short values. More...

Description

C++ header file with declarations for the µTest++ user-defined literals and type wrappers.

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

The declared 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.

In addition to literal operators, this header declares both deprecated and modern type wrappers for explicit type conversion, supporting enhanced clarity and type safety in test conditions. The preferred to_* forms are recommended for new code, while the older _i, _u8, etc. aliases are retained for backwards compatibility.

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 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
52
53#ifndef MICRO_OS_PLUS_MICRO_TEST_PLUS_LITERALS_H_
54#define MICRO_OS_PLUS_MICRO_TEST_PLUS_LITERALS_H_
55
56// ----------------------------------------------------------------------------
57
58#if defined(__cplusplus)
59
60// ----------------------------------------------------------------------------
61
62#if __has_include("micro-os-plus/project-config.h")
63#include "micro-os-plus/project-config.h"
64#endif // __has_include("micro-os-plus/project-config.h")
65
66#if __has_include("micro-os-plus/micro-test-plus-defines.h")
67#include "micro-os-plus/micro-test-plus-defines.h"
68#endif // __has_include("micro-os-plus/micro-test-plus-defines.h")
69
70#include "type-traits.h"
71#include "math.h"
72
73#include <cstdint>
74
75// ----------------------------------------------------------------------------
76
77#if defined(__GNUC__)
78#pragma GCC diagnostic push
79
80#pragma GCC diagnostic ignored "-Waggregate-return"
81#if defined(__clang__)
82#pragma clang diagnostic ignored "-Wc++98-compat"
83#pragma clang diagnostic ignored "-Wc++98-compat-pedantic"
84#endif // defined(__clang__)
85#endif // defined(__GNUC__)
86
87// =============================================================================
88
90{
91 // --------------------------------------------------------------------------
92
118 namespace literals
119 {
130 template <char... Cs>
131 [[nodiscard]] constexpr auto
132 operator""_i ();
133
144 template <char... Cs>
145 [[nodiscard]] constexpr auto
146 operator""_s ();
147
158 template <char... Cs>
159 [[nodiscard]] constexpr auto
160 operator""_c ();
161
172 template <char... Cs>
173 [[nodiscard]] constexpr auto
174 operator""_sc ();
175
186 template <char... Cs>
187 [[nodiscard]] constexpr auto
188 operator""_l ();
189
200 template <char... Cs>
201 [[nodiscard]] constexpr auto
202 operator""_ll ();
203
214 template <char... Cs>
215 [[nodiscard]] constexpr auto
216 operator""_u ();
217
228 template <char... Cs>
229 [[nodiscard]] constexpr auto
230 operator""_uc ();
231
242 template <char... Cs>
243 [[nodiscard]] constexpr auto
244 operator""_us ();
245
256 template <char... Cs>
257 [[nodiscard]] constexpr auto
258 operator""_ul ();
259
270 template <char... Cs>
271 [[nodiscard]] constexpr auto
272 operator""_ull ();
273
284 template <char... Cs>
285 [[nodiscard]] constexpr auto
286 operator""_i8 ();
287
298 template <char... Cs>
299 [[nodiscard]] constexpr auto
300 operator""_i16 ();
301
312 template <char... Cs>
313 [[nodiscard]] constexpr auto
314 operator""_i32 ();
315
326 template <char... Cs>
327 [[nodiscard]] constexpr auto
328 operator""_i64 ();
329
340 template <char... Cs>
341 [[nodiscard]] constexpr auto
342 operator""_u8 ();
343
354 template <char... Cs>
355 [[nodiscard]] constexpr auto
356 operator""_u16 ();
357
368 template <char... Cs>
369 [[nodiscard]] constexpr auto
370 operator""_u32 ();
371
382 template <char... Cs>
383 [[nodiscard]] constexpr auto
384 operator""_u64 ();
385
396 template <char... Cs>
397 [[nodiscard]] constexpr auto
398 operator""_f ();
399
410 template <char... Cs>
411 [[nodiscard]] constexpr auto
412 operator""_d ();
413
424 template <char... Cs>
425 [[nodiscard]] constexpr auto
426 operator""_ld ();
427
437 constexpr auto
438 operator""_b (const char* name, decltype (sizeof ("")) size);
439
440 // ------------------------------------------------------------------------
441 } // namespace literals
442
443 // --------------------------------------------------------------------------
444
445#if defined(__GNUC__)
446#pragma GCC diagnostic push
447
448#if defined(__clang__)
449#pragma clang diagnostic ignored "-Wdocumentation-deprecated-sync"
450#endif // defined(__clang__)
451#endif // defined(__GNUC__)
452
457
474
481
488
495
502
509
516
523
530
537
544
551
558
565
572
579
586
593
600
607
614
620
626
633
650 template <class T>
652 {
658 constexpr explicit _t (const T& t);
659 };
660
661#if defined(__GNUC__)
662#pragma GCC diagnostic pop
663#endif // defined(__GNUC__)
664
690
697
704
711
718
725
732
739
746
753
760
767
774
781
788
795
802
809
816
823
830
837
844
851
855
886 template <class T>
888 {
894 constexpr explicit to_t (const T& t);
895 };
896
897 // --------------------------------------------------------------------------
898} // namespace micro_os_plus::micro_test_plus
899
900#if defined(__GNUC__)
901#pragma GCC diagnostic pop
902#endif // defined(__GNUC__)
903
904// ----------------------------------------------------------------------------
905
906#endif // defined(__cplusplus)
907
908// ============================================================================
909// Templates, inlines & constexpr implementations.
910
912
913// ----------------------------------------------------------------------------
914
915#endif // MICRO_OS_PLUS_MICRO_TEST_PLUS_LITERALS_H_
916
917// ----------------------------------------------------------------------------

Generated via doxygen2docusaurus 2.2.2 by Doxygen 1.17.0.