micro-test-plus 3.2.2
µTest++ Testing Framework
Loading...
Searching...
No Matches
literals-inlines.h
Go to the documentation of this file.
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
9 * be 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.0 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// #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// ----------------------------------------------------------------------------
type_traits::value< std::uint16_t > _u16
Strongly-typed wrapper for std::uint16_t values.
Definition literals.h:587
type_traits::value< unsigned long long > _ull
Strongly-typed wrapper for unsigned long long values.
Definition literals.h:545
type_traits::value< short > _s
Strongly-typed wrapper for short values.
Definition literals.h:489
type_traits::value< int > _i
Strongly-typed wrapper for int values.
Definition literals.h:496
type_traits::value< unsigned char > _uc
Strongly-typed wrapper for unsigned char values.
Definition literals.h:524
type_traits::value< std::uint8_t > _u8
Strongly-typed wrapper for std::uint8_t values.
Definition literals.h:580
type_traits::value< std::int8_t > _i8
Strongly-typed wrapper for std::int8_t values.
Definition literals.h:552
type_traits::value< std::int32_t > _i32
Strongly-typed wrapper for std::int32_t values.
Definition literals.h:566
type_traits::value< unsigned short > _us
Strongly-typed wrapper for unsigned short values.
Definition literals.h:531
type_traits::value< double > _d
Strongly-typed wrapper for double values.
Definition literals.h:613
type_traits::value< long long > _ll
Strongly-typed wrapper for long long values.
Definition literals.h:510
type_traits::value< unsigned > _u
Strongly-typed wrapper for unsigned values.
Definition literals.h:517
type_traits::value< bool > _b
Strongly-typed wrapper for bool values.
Definition literals.h:468
type_traits::value< long double > _ld
Strongly-typed wrapper for long double values.
Definition literals.h:620
type_traits::value< unsigned long > _ul
Strongly-typed wrapper for unsigned long values.
Definition literals.h:538
type_traits::value< long > _l
Strongly-typed wrapper for long values.
Definition literals.h:503
type_traits::value< char > _c
Strongly-typed wrapper for char values.
Definition literals.h:475
type_traits::value< std::uint64_t > _u64
Strongly-typed wrapper for std::uint64_t values.
Definition literals.h:601
type_traits::value< signed char > _sc
Strongly-typed wrapper for signed char values.
Definition literals.h:482
type_traits::value< float > _f
Strongly-typed wrapper for float values.
Definition literals.h:607
type_traits::value< std::int64_t > _i64
Strongly-typed wrapper for std::int64_t values.
Definition literals.h:573
type_traits::value< std::int16_t > _i16
Strongly-typed wrapper for std::int16_t values.
Definition literals.h:559
type_traits::value< std::uint32_t > _u32
Strongly-typed wrapper for std::uint32_t values.
Definition literals.h:594
User-defined literals and type wrappers for the µTest++ testing framework.
constexpr auto den(void) -> T
Computes the decimal part of a number represented as an array of characters.
constexpr auto den_size(void) -> T
Computes the number of decimal places in a number represented as an array of characters.
constexpr auto num(void) -> T
Computes the integral value of a number represented as an array of characters.
Primary namespace for the µTest++ testing framework.
Struct template representing a generic floating point constant with custom size and precision.
Struct template representing a generic integral constant.
Empty base struct for all operator types.