Skip to main content

The literals-inlines.h File Reference

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

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 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
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// #include "type-traits.h"
62
63// ----------------------------------------------------------------------------
64
65#if defined(__GNUC__)
66#pragma GCC diagnostic push
67#pragma GCC diagnostic ignored "-Waggregate-return"
68#if defined(__clang__)
69#pragma clang diagnostic ignored "-Wc++98-compat"
70#pragma clang diagnostic ignored "-Wc++98-compat-pedantic"
71#endif
72#endif
73
75{
76 // --------------------------------------------------------------------------
77
78 namespace literals
79 {
80
92 template <char... Cs>
93 [[nodiscard]] constexpr auto
94 operator""_i ()
95 {
96 return type_traits::integral_constant<math::num<int, Cs...> ()>{};
97 }
98
110 template <char... Cs>
111 [[nodiscard]] constexpr auto
112 operator""_s ()
113 {
114 return type_traits::integral_constant<math::num<short, Cs...> ()>{};
115 }
116
128 template <char... Cs>
129 [[nodiscard]] constexpr auto
130 operator""_c ()
131 {
132 return type_traits::integral_constant<math::num<char, Cs...> ()>{};
133 }
134
146 template <char... Cs>
147 [[nodiscard]] constexpr auto
148 operator""_sc ()
149 {
151 math::num<signed char, Cs...> ()>{};
152 }
153
165 template <char... Cs>
166 [[nodiscard]] constexpr auto
167 operator""_l ()
168 {
169 return type_traits::integral_constant<math::num<long, Cs...> ()>{};
170 }
171
183 template <char... Cs>
184 [[nodiscard]] constexpr auto
185 operator""_ll ()
186 {
187 return type_traits::integral_constant<math::num<long long, Cs...> ()>{};
188 }
189
201 template <char... Cs>
202 [[nodiscard]] constexpr auto
203 operator""_u ()
204 {
205 return type_traits::integral_constant<math::num<unsigned, Cs...> ()>{};
206 }
207
219 template <char... Cs>
220 [[nodiscard]] constexpr auto
221 operator""_uc ()
222 {
224 math::num<unsigned char, Cs...> ()>{};
225 }
226
238 template <char... Cs>
239 [[nodiscard]] constexpr auto
240 operator""_us ()
241 {
243 math::num<unsigned short, Cs...> ()>{};
244 }
245
257 template <char... Cs>
258 [[nodiscard]] constexpr auto
259 operator""_ul ()
260 {
262 math::num<unsigned long, Cs...> ()>{};
263 }
264
276 template <char... Cs>
277 [[nodiscard]] constexpr auto
278 operator""_ull ()
279 {
281 math::num<unsigned long long, Cs...> ()>{};
282 }
283
295 template <char... Cs>
296 [[nodiscard]] constexpr auto
297 operator""_i8 ()
298 {
300 math::num<std::int8_t, Cs...> ()>{};
301 }
302
314 template <char... Cs>
315 [[nodiscard]] constexpr auto
316 operator""_i16 ()
317 {
319 math::num<std::int16_t, Cs...> ()>{};
320 }
321
333 template <char... Cs>
334 [[nodiscard]] constexpr auto
335 operator""_i32 ()
336 {
338 math::num<std::int32_t, Cs...> ()>{};
339 }
340
352 template <char... Cs>
353 [[nodiscard]] constexpr auto
354 operator""_i64 ()
355 {
357 math::num<std::int64_t, Cs...> ()>{};
358 }
359
371 template <char... Cs>
372 [[nodiscard]] constexpr auto
373 operator""_u8 ()
374 {
376 math::num<std::uint8_t, Cs...> ()>{};
377 }
378
390 template <char... Cs>
391 [[nodiscard]] constexpr auto
392 operator""_u16 ()
393 {
395 math::num<std::uint16_t, Cs...> ()>{};
396 }
397
409 template <char... Cs>
410 [[nodiscard]] constexpr auto
411 operator""_u32 ()
412 {
414 math::num<std::uint32_t, Cs...> ()>{};
415 }
416
428 template <char... Cs>
429 [[nodiscard]] constexpr auto
430 operator""_u64 ()
431 {
433 math::num<std::uint64_t, Cs...> ()>{};
434 }
435
447 template <char... Cs>
448 [[nodiscard]] 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 [[nodiscard]] 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 [[nodiscard]] 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
517 constexpr auto
518 operator""_b (const char* name, decltype (sizeof ("")) size)
519 {
530 struct named : std::string_view, type_traits::op
531 {
535 using value_type = bool;
536
546 [[nodiscard]] constexpr
547 operator value_type () const
548 {
549 return true;
550 }
551
561 [[nodiscard]] constexpr auto
562 operator== (const named&) const
563 {
564 return true;
565 }
566
576 [[nodiscard]] constexpr auto
577 operator== (const bool other) const
578 {
579 return other;
580 }
581 };
582
583 return named{ { name, size }, {} };
584 }
585
586 // ------------------------------------------------------------------------
587 } // namespace literals
588
589 // --------------------------------------------------------------------------
590} // namespace micro_os_plus::micro_test_plus
591
592#if defined(__GNUC__)
593#pragma GCC diagnostic pop
594#endif
595
596// ----------------------------------------------------------------------------
597
598#endif // __cplusplus
599
600// ----------------------------------------------------------------------------
601
602#endif // MICRO_TEST_PLUS_LITERALS_INLINES_H_
603
604// ----------------------------------------------------------------------------

Generated via docusaurus-plugin-doxygen by Doxygen 1.14.0.