Skip to main content

The literals.h File Reference

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

Included Headers

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

Namespaces Index

namespacemicro_os_plus

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

namespacemicro_os_plus::micro_test_plus

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

namespacemicro_os_plus::micro_test_plus::literals

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

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

Functions Index

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

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

constexpr autooperator""_c ()

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

constexpr autooperator""_d ()

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

constexpr autooperator""_f ()

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

constexpr autooperator""_i ()

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

constexpr autooperator""_i16 ()

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

constexpr autooperator""_i32 ()

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

constexpr autooperator""_i64 ()

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

constexpr autooperator""_i8 ()

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

constexpr autooperator""_l ()

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

constexpr autooperator""_ld ()

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

constexpr autooperator""_ll ()

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

constexpr autooperator""_s ()

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

constexpr autooperator""_sc ()

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

constexpr autooperator""_u ()

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

constexpr autooperator""_u16 ()

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

constexpr autooperator""_u32 ()

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

constexpr autooperator""_u64 ()

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

constexpr autooperator""_u8 ()

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

constexpr autooperator""_uc ()

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

constexpr autooperator""_ul ()

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

constexpr autooperator""_ull ()

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

constexpr autooperator""_us ()

User-defined literal operator to convert to unsigned short. 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 Liviu Ionescu. All rights reserved.
4 *
5 * Permission to use, copy, modify, and/or distribute this software
6 * for any 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
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&#95;1&#95;0.txt.
14 */
15
16// ----------------------------------------------------------------------------
17
52
53#ifndef MICRO_TEST_PLUS_LITERALS_H_
54#define MICRO_TEST_PLUS_LITERALS_H_
55
56// ----------------------------------------------------------------------------
57
58#ifdef __cplusplus
59
60// ----------------------------------------------------------------------------
61
62#include <cstdint>
63#include "type-traits.h"
64#include "math.h"
65
66// ----------------------------------------------------------------------------
67
68#if defined(__GNUC__)
69#pragma GCC diagnostic push
70#pragma GCC diagnostic ignored "-Waggregate-return"
71#if defined(__clang__)
72#pragma clang diagnostic ignored "-Wc++98-compat"
73#pragma clang diagnostic ignored "-Wc++98-compat-pedantic"
74#endif
75#endif
76
78{
79 // --------------------------------------------------------------------------
80
106 namespace literals
107 {
118 template <char... Cs>
119 [[nodiscard]] constexpr auto
120 operator""_i ();
121
132 template <char... Cs>
133 [[nodiscard]] constexpr auto
134 operator""_s ();
135
146 template <char... Cs>
147 [[nodiscard]] constexpr auto
148 operator""_c ();
149
160 template <char... Cs>
161 [[nodiscard]] constexpr auto
162 operator""_sc ();
163
174 template <char... Cs>
175 [[nodiscard]] constexpr auto
176 operator""_l ();
177
188 template <char... Cs>
189 [[nodiscard]] constexpr auto
190 operator""_ll ();
191
202 template <char... Cs>
203 [[nodiscard]] constexpr auto
204 operator""_u ();
205
216 template <char... Cs>
217 [[nodiscard]] constexpr auto
218 operator""_uc ();
219
230 template <char... Cs>
231 [[nodiscard]] constexpr auto
232 operator""_us ();
233
244 template <char... Cs>
245 [[nodiscard]] constexpr auto
246 operator""_ul ();
247
258 template <char... Cs>
259 [[nodiscard]] constexpr auto
260 operator""_ull ();
261
272 template <char... Cs>
273 [[nodiscard]] constexpr auto
274 operator""_i8 ();
275
286 template <char... Cs>
287 [[nodiscard]] constexpr auto
288 operator""_i16 ();
289
300 template <char... Cs>
301 [[nodiscard]] constexpr auto
302 operator""_i32 ();
303
314 template <char... Cs>
315 [[nodiscard]] constexpr auto
316 operator""_i64 ();
317
329 template <char... Cs>
330 [[nodiscard]] constexpr auto
331 operator""_u8 ();
332
343 template <char... Cs>
344 [[nodiscard]] constexpr auto
345 operator""_u16 ();
346
357 template <char... Cs>
358 [[nodiscard]] constexpr auto
359 operator""_u32 ();
360
371 template <char... Cs>
372 [[nodiscard]] constexpr auto
373 operator""_u64 ();
374
385 template <char... Cs>
386 [[nodiscard]] constexpr auto
387 operator""_f ();
388
399 template <char... Cs>
400 [[nodiscard]] constexpr auto
401 operator""_d ();
402
413 template <char... Cs>
414 [[nodiscard]] constexpr auto
415 operator""_ld ();
416
426 constexpr auto
427 operator""_b (const char* name, decltype (sizeof ("")) size);
428
429 // ------------------------------------------------------------------------
430 } // namespace literals
431
432 // --------------------------------------------------------------------------
433
434#if defined(__GNUC__)
435#pragma GCC diagnostic push
436#if defined(__clang__)
437#pragma clang diagnostic ignored "-Wdocumentation-deprecated-sync"
438#endif
439#endif
440
445
462
469
476
483
490
497
504
511
518
525
532
539
546
553
560
567
574
581
588
595
602
608
614
621
638 template <class T>
640 {
650 constexpr explicit _t (const T& t) : type_traits::value<T>{ t }
651 {
652 }
653 };
654
655#if defined(__GNUC__)
656#pragma GCC diagnostic pop
657#endif
658
684
691
698
705
712
719
726
733
740
747
754
761
768
775
782
789
796
803
810
817
824
831
838
845
849
880 template <class T>
882 {
892 constexpr explicit to_t (const T& t) : type_traits::value<T>{ t }
893 {
894 }
895 };
896
897 // --------------------------------------------------------------------------
898} // namespace micro_os_plus::micro_test_plus
899
900#if defined(__GNUC__)
901#pragma GCC diagnostic pop
902#endif
903
904// ----------------------------------------------------------------------------
905
906#endif // __cplusplus
907
908// ----------------------------------------------------------------------------
909
910#endif // MICRO_TEST_PLUS_LITERALS_H_
911
912// ----------------------------------------------------------------------------

Generated via docusaurus-plugin-doxygen by Doxygen 1.14.0.