Skip to main content

The detail.h File Reference

C++ header file with declarations for the µTest++ internals. More...

Included Headers

#include <stdio.h>
#include <string>

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::detail

Internal implementation details for the µTest++ framework. More...

Classes Index

structand_<Lhs_T, Rhs_T>

Logical AND comparator struct template. More...

structassertion<Expr_T>

Assertion struct template for parameter passing to the evaluator. More...

classdeferred_reporter<Expr_T>

Deferred reporter class template for a specific expression. More...

classdeferred_reporter_base

Base class for a deferred reporter that collects messages into a string. More...

structeq_<Lhs_T, Rhs_T>

Equality comparator struct template. More...

structge_<Lhs_T, Rhs_T>

Greater than or equal comparator struct template. More...

structgt_<Lhs_T, Rhs_T>

Greater than comparator struct template. More...

structle_<Lhs_T, Rhs_T>

Less than or equal comparator struct template. More...

structlt_<Lhs_T, Rhs_T>

Less than comparator struct template. More...

structne_<Lhs_T, Rhs_T>

Non-equality comparator struct template. More...

structnot_<T>

Logical NOT comparator struct template. More...

structnothrow_<Callable_T>

Operator struct template to check if an expression does not throw any exception. More...

structor_<Lhs_T, Rhs_T>

Logical OR comparator struct template. More...

structthrows_<Callable_T, Exception_T>

Operator struct template to check if an expression throws a specific exception. More...

structthrows_<Callable_T, void>

Operator struct template to check if an expression throws any exception. More...

Functions Index

 and_ (const Lhs_T &, const Rhs_T &) -> and_< Lhs_T, Rhs_T >
 eq_ (const Lhs_T &, const Rhs_T &) -> eq_< Lhs_T, Rhs_T >
 ge_ (const Lhs_T &, const Rhs_T &) -> ge_< Lhs_T, Rhs_T >
constexpr autoget (const T &t)

Generic getter function template for value retrieval. More...

constexpr auto get_impl (const T &t, int) -> decltype(t.get())

Generic getter function template for value retrieval. More...

constexpr auto get_impl (const T &t,...) -> decltype(auto)

Fallback variadic getter function template. More...

 gt_ (const Lhs_T &, const Rhs_T &) -> gt_< Lhs_T, Rhs_T >
 le_ (const Lhs_T &, const Rhs_T &) -> le_< Lhs_T, Rhs_T >
 lt_ (const Lhs_T &, const Rhs_T &) -> lt_< Lhs_T, Rhs_T >
 ne_ (const Lhs_T &, const Rhs_T &) -> ne_< Lhs_T, Rhs_T >
 not_ (const T &) -> not_< T >
 or_ (const Lhs_T &, const Rhs_T &) -> or_< Lhs_T, Rhs_T >

Description

C++ header file with declarations for the µTest++ internals.

This header provides the declarations for the internal components of the µTest++ framework, encapsulated within the micro_os_plus::micro_test_plus::detail namespace. It defines the core mechanisms, helper structures, and utility templates that underpin the framework's assertion handling, value retrieval, comparator logic, deferred reporting, and exception checking facilities.

All definitions reside within the micro_os_plus::micro_test_plus::detail 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.

Functions

and_()

template <typename Lhs_T, typename Rhs_T>
micro_os_plus::micro_test_plus::detail::and_ (const Lhs_T &, const Rhs_T &)

Definition at line 1267 of file detail.h.

eq_()

template <typename Lhs_T, typename Rhs_T>
micro_os_plus::micro_test_plus::detail::eq_ (const Lhs_T &, const Rhs_T &)

Definition at line 399 of file detail.h.

ge_()

template <typename Lhs_T, typename Rhs_T>
micro_os_plus::micro_test_plus::detail::ge_ (const Lhs_T &, const Rhs_T &)

Definition at line 854 of file detail.h.

get()

template <class T>
auto micro_os_plus::micro_test_plus::detail::get (const T & t)
nodiscardconstexpr

Generic getter function template for value retrieval.

Template Parameters
TThe type from which the value is to be retrieved.
Parameters
tThe object or value to be accessed.
Returns

The value obtained via the relevant getter implementation.

The get function template invokes the appropriate getter implementation to retrieve the value from the provided object or type. This function ensures consistent access to values for both custom and standard types within the framework.

The primary implementation attempts to invoke a get() method if it exists, which is recommended for user-defined types to ensure consistent value access. If the type does not provide a get() method, the fallback variadic implementation simply returns the original argument.

The get function template delegates to these implementations, enabling seamless support for a wide range of types in test expressions and comparators.

All definitions are intended for internal use within the framework and are implemented in the include/micro-os-plus/micro-test-plus folder to maintain a structured and modular codebase.

Definition at line 223 of file detail.h.

get_impl()

template <class T>
decltype(t.get()) micro_os_plus::micro_test_plus::detail::get_impl (const T & t, int)
nodiscardconstexpr

Generic getter function template for value retrieval.

Template Parameters
TThe type from which the value is to be retrieved.
Parameters
tThe object or value to be accessed.
Returns

The value obtained via the relevant getter implementation.

The get function template invokes the appropriate getter implementation to retrieve the value from the provided object or type. This function ensures consistent access to values for both custom and standard types within the framework.

The primary implementation attempts to invoke a get() method if it exists, which is recommended for user-defined types to ensure consistent value access. If the type does not provide a get() method, the fallback variadic implementation simply returns the original argument.

The get function template delegates to these implementations, enabling seamless support for a wide range of types in test expressions and comparators.

All definitions are intended for internal use within the framework and are implemented in the include/micro-os-plus/micro-test-plus folder to maintain a structured and modular codebase.

Definition at line 160 of file detail.h.

get_impl()

template <class T>
decltype(auto) micro_os_plus::micro_test_plus::detail::get_impl (const T & t, ...)
nodiscardconstexpr

Fallback variadic getter function template.

Template Parameters
TThe type from which the value is to be retrieved.
Parameters
tThe object or value to be accessed.
Returns

The original argument t.

The get_impl function template serves as a fallback mechanism for value retrieval when the provided type does not implement a get() member function. It simply returns the first argument, discarding any additional parameters.

This approach ensures that both custom types (with a get() method) and standard types (without a get() method) are supported seamlessly within the framework's generic getter utilities.

All definitions are intended for internal use within the framework and are implemented in the include/micro-os-plus/micro-test-plus folder to maintain a structured and modular codebase.

Definition at line 189 of file detail.h.

gt_()

template <typename Lhs_T, typename Rhs_T>
micro_os_plus::micro_test_plus::detail::gt_ (const Lhs_T &, const Rhs_T &)

Definition at line 707 of file detail.h.

le_()

template <typename Lhs_T, typename Rhs_T>
micro_os_plus::micro_test_plus::detail::le_ (const Lhs_T &, const Rhs_T &)

Definition at line 1148 of file detail.h.

lt_()

template <typename Lhs_T, typename Rhs_T>
micro_os_plus::micro_test_plus::detail::lt_ (const Lhs_T &, const Rhs_T &)

Definition at line 1000 of file detail.h.

ne_()

template <typename Lhs_T, typename Rhs_T>
micro_os_plus::micro_test_plus::detail::ne_ (const Lhs_T &, const Rhs_T &)

Definition at line 562 of file detail.h.

not_()

template <typename T>
micro_os_plus::micro_test_plus::detail::not_ (const T &)

Definition at line 1478 of file detail.h.

or_()

template <typename Lhs_T, typename Rhs_T>
micro_os_plus::micro_test_plus::detail::or_ (const Lhs_T &, const Rhs_T &)

Definition at line 1386 of file detail.h.

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
41
42#ifndef MICRO_TEST_PLUS_DETAIL_H_
43#define MICRO_TEST_PLUS_DETAIL_H_
44
45// ----------------------------------------------------------------------------
46
47#ifdef __cplusplus
48
49// ----------------------------------------------------------------------------
50
51#include <stdio.h>
52#include <string>
53
54// ----------------------------------------------------------------------------
55
56#if defined(__GNUC__)
57#pragma GCC diagnostic push
58#pragma GCC diagnostic ignored "-Wpadded"
59#pragma GCC diagnostic ignored "-Waggregate-return"
60#if defined(__clang__)
61#pragma clang diagnostic ignored "-Wc++98-compat"
62#endif
63#endif
64
66{
67 // --------------------------------------------------------------------------
68
92 namespace detail
93 {
111 template <class Expr_T>
112 struct assertion
113 {
117 Expr_T expr{};
118
123 };
124
125 // ------------------------------------------------------------------------
126
127 // in C++14/17/20, a function template with a deduced return type
128 // (auto) cannot be used before its definition is visible.
129 // Therefore it is not possible to split definitions.
130
158 template <class T>
159 [[nodiscard]] constexpr auto
160 get_impl (const T& t, int) -> decltype (t.get ())
161 {
162 return t.get ();
163 }
164
187 template <class T>
188 [[nodiscard]] constexpr auto
189 get_impl (const T& t, ...) -> decltype (auto)
190 {
191 return t;
192 }
193
221 template <class T>
222 [[nodiscard]] constexpr auto
223 get (const T& t)
224 {
225 // Call the variadic function, basically to force it return `t`.
226 return get_impl<T> (t, 0);
227 }
228
229 // ------------------------------------------------------------------------
230
258 template <class Lhs_T, class Rhs_T>
260 {
272 constexpr eq_ (const Lhs_T& lhs = {}, const Rhs_T& rhs = {})
273 : lhs_{ lhs }, rhs_{ rhs }, value_{ [&] {
274 // This lambda is called in the constructor to
275 // evaluate the comparison.
276 using std::operator==;
277 using std::operator<;
278
279#if defined(__GNUC__)
280#pragma GCC diagnostic push
281#pragma GCC diagnostic ignored "-Wfloat-equal"
282#pragma GCC diagnostic ignored "-Wconversion"
283#pragma GCC diagnostic ignored "-Wdouble-promotion"
284#pragma GCC diagnostic ignored "-Wsign-compare"
285#if defined(__clang__)
286#pragma clang diagnostic ignored "-Wimplicit-int-float-conversion"
287#pragma clang diagnostic ignored "-Wpedantic"
288#endif
289#endif
292 {
293 // If both types have values (like numeric constants),
294 // compare them directly.
295 return Lhs_T::value == Rhs_T::value;
296 }
297 else if constexpr (type_traits::has_epsilon_v<Lhs_T>
299 {
300 // If both values have precision, compare them using
301 // the smalles precision.
302 return math::abs (get (lhs) - get (rhs))
303 < math::min_value (Lhs_T::epsilon, Rhs_T::epsilon);
304 }
305 else if constexpr (type_traits::has_epsilon_v<Lhs_T>)
306 {
307 // If only the left operand has precision, use it.
308 return math::abs (get (lhs) - get (rhs)) < Lhs_T::epsilon;
309 }
310 else if constexpr (type_traits::has_epsilon_v<Rhs_T>)
311 {
312 // If only the right operand has precision, use it.
313 return math::abs (get (lhs) - get (rhs)) < Rhs_T::epsilon;
314 }
315 else
316 {
317 // Call the generic getters, which might
318 // either call the type get() or return the value.
319 return get (lhs) == get (rhs);
320 }
321#if defined(__GNUC__)
322#pragma GCC diagnostic pop
323#endif
324 }() }
325 {
326 }
327
339 [[nodiscard]] constexpr
340 operator bool () const
341 {
342 return value_;
343 }
344
357 [[nodiscard]] constexpr auto
358 lhs (void) const
359 {
360 return get (lhs_);
361 }
362
375 [[nodiscard]] constexpr auto
376 rhs (void) const
377 {
378 return get (rhs_);
379 }
380
384 const Lhs_T lhs_{};
385
389 const Rhs_T rhs_{};
390
394 const bool value_{};
395 };
396
397 // Deduction guide.
398 template <typename Lhs_T, typename Rhs_T>
399 eq_ (const Lhs_T&, const Rhs_T&) -> eq_<Lhs_T, Rhs_T>;
400
401 // ------------------------------------------------------------------------
402
430 template <class Lhs_T, class Rhs_T>
432 {
444 constexpr ne_ (const Lhs_T& lhs = {}, const Rhs_T& rhs = {})
445 : lhs_{ lhs }, rhs_{ rhs }, value_{ [&] {
446 using std::operator==;
447 using std::operator!=;
448 using std::operator>;
449
450#if defined(__GNUC__)
451#pragma GCC diagnostic push
452#pragma GCC diagnostic ignored "-Wfloat-equal"
453#pragma GCC diagnostic ignored "-Wconversion"
454#pragma GCC diagnostic ignored "-Wdouble-promotion"
455#pragma GCC diagnostic ignored "-Wsign-compare"
456#if defined(__clang__)
457#pragma clang diagnostic ignored "-Wimplicit-int-float-conversion"
458#pragma clang diagnostic ignored "-Wpedantic"
459#endif
460#endif
463 {
464 return Lhs_T::value != Rhs_T::value;
465 }
466 else if constexpr (type_traits::has_epsilon_v<Lhs_T>
467 and type_traits::has_epsilon_v<Rhs_T>)
468 {
469 return math::abs (get (lhs_) - get (rhs_))
470 > math::min_value (Lhs_T::epsilon, Rhs_T::epsilon);
471 }
472 else if constexpr (type_traits::has_epsilon_v<Lhs_T>)
473 {
474 return math::abs (get (lhs_) - get (rhs_)) > Lhs_T::epsilon;
475 }
476 else if constexpr (type_traits::has_epsilon_v<Rhs_T>)
477 {
478 return math::abs (get (lhs_) - get (rhs_)) > Rhs_T::epsilon;
479 }
480 else
481 {
482 return get (lhs_) != get (rhs_);
483 }
484#if defined(__GNUC__)
485#pragma GCC diagnostic pop
486#endif
487 }() }
488 {
489 }
490
502 [[nodiscard]] constexpr
503 operator bool () const
504 {
505 return value_;
506 }
507
520 [[nodiscard]] constexpr auto
521 lhs (void) const
522 {
523 return get (lhs_);
524 }
525
538 [[nodiscard]] constexpr auto
539 rhs (void) const
540 {
541 return get (rhs_);
542 }
543
547 const Lhs_T lhs_{};
548
552 const Rhs_T rhs_{};
553
557 const bool value_{};
558 };
559
560 // Deduction guide.
561 template <typename Lhs_T, typename Rhs_T>
562 ne_ (const Lhs_T&, const Rhs_T&) -> ne_<Lhs_T, Rhs_T>;
563
564 // ------------------------------------------------------------------------
565
591 template <class Lhs_T, class Rhs_T>
593 {
605 constexpr gt_ (const Lhs_T& lhs = {}, const Rhs_T& rhs = {})
606 : lhs_{ lhs }, rhs_{ rhs }, value_{ [&] {
607 using std::operator>;
608
609#if defined(__GNUC__)
610#pragma GCC diagnostic push
611#pragma GCC diagnostic ignored "-Wconversion"
612#pragma GCC diagnostic ignored "-Wdouble-promotion"
613#pragma GCC diagnostic ignored "-Wsign-compare"
614#if defined(__clang__)
615#pragma clang diagnostic ignored "-Wimplicit-int-float-conversion"
616#pragma clang diagnostic ignored "-Wpedantic"
617#endif
618#endif
621 {
622 return Lhs_T::value > Rhs_T::value;
623 }
624 else
625 {
626 return get (lhs_) > get (rhs_);
627 }
628#if defined(__GNUC__)
629#pragma GCC diagnostic pop
630#endif
631 }() }
632 {
633 }
634
647 [[nodiscard]] constexpr
648 operator bool () const
649 {
650 return value_;
651 }
652
665 [[nodiscard]] constexpr auto
666 lhs (void) const
667 {
668 return get (lhs_);
669 }
670 [[nodiscard]] constexpr auto
671
684 rhs (void) const
685 {
686 return get (rhs_);
687 }
688
692 const Lhs_T lhs_{};
693
697 const Rhs_T rhs_{};
698
702 const bool value_{};
703 };
704
705 // Deduction guide.
706 template <typename Lhs_T, typename Rhs_T>
707 gt_ (const Lhs_T&, const Rhs_T&) -> gt_<Lhs_T, Rhs_T>;
708
709 // ------------------------------------------------------------------------
710
736 template <class Lhs_T, class Rhs_T>
738 {
752 constexpr ge_ (const Lhs_T& lhs = {}, const Rhs_T& rhs = {})
753 : lhs_{ lhs }, rhs_{ rhs }, value_{ [&] {
754 using std::operator>=;
755
756#if defined(__GNUC__)
757#pragma GCC diagnostic push
758#pragma GCC diagnostic ignored "-Wconversion"
759#pragma GCC diagnostic ignored "-Wdouble-promotion"
760#pragma GCC diagnostic ignored "-Wsign-compare"
761#if defined(__clang__)
762#pragma clang diagnostic ignored "-Wimplicit-int-float-conversion"
763#pragma clang diagnostic ignored "-Wpedantic"
764#endif
765#endif
768 {
769 return Lhs_T::value >= Rhs_T::value;
770 }
771 else
772 {
773 return get (lhs_) >= get (rhs_);
774 }
775#if defined(__GNUC__)
776#pragma GCC diagnostic pop
777#endif
778 }() }
779 {
780 }
781
794 [[nodiscard]] constexpr
795 operator bool () const
796 {
797 return value_;
798 }
799
812 [[nodiscard]] constexpr auto
813 lhs (void) const
814 {
815 return get (lhs_);
816 }
817
830 [[nodiscard]] constexpr auto
831 rhs (void) const
832 {
833 return get (rhs_);
834 }
835
839 const Lhs_T lhs_{};
840
844 const Rhs_T rhs_{};
845
849 const bool value_{};
850 };
851
852 // Deduction guide.
853 template <typename Lhs_T, typename Rhs_T>
854 ge_ (const Lhs_T&, const Rhs_T&) -> ge_<Lhs_T, Rhs_T>;
855
856 // ------------------------------------------------------------------------
857
883 template <class Lhs_T, class Rhs_T>
885 {
897 constexpr lt_ (const Lhs_T& lhs = {}, const Rhs_T& rhs = {})
898 : lhs_{ lhs }, rhs_{ rhs }, value_{ [&] {
899 using std::operator<;
900
901#if defined(__GNUC__)
902#pragma GCC diagnostic push
903#pragma GCC diagnostic ignored "-Wconversion"
904#pragma GCC diagnostic ignored "-Wdouble-promotion"
905#pragma GCC diagnostic ignored "-Wsign-compare"
906#if defined(__clang__)
907#pragma clang diagnostic ignored "-Wimplicit-int-float-conversion"
908#pragma clang diagnostic ignored "-Wpedantic"
909#endif
910#endif
913 {
914 return Lhs_T::value < Rhs_T::value;
915 }
916 else
917 {
918 return get (lhs_) < get (rhs_);
919 }
920#if defined(__GNUC__)
921#pragma GCC diagnostic pop
922#endif
923 }() }
924 {
925 }
926
939 [[nodiscard]] constexpr
940 operator bool () const
941 {
942 return value_;
943 }
944
957 [[nodiscard]] constexpr auto
958 lhs (void) const
959 {
960 return get (lhs_);
961 }
962
975 [[nodiscard]] constexpr auto
976 rhs (void) const
977 {
978 return get (rhs_);
979 }
980
981 private:
985 const Lhs_T lhs_{};
986
990 const Rhs_T rhs_{};
991
995 const bool value_{};
996 };
997
998 // Deduction guide.
999 template <typename Lhs_T, typename Rhs_T>
1000 lt_ (const Lhs_T&, const Rhs_T&) -> lt_<Lhs_T, Rhs_T>;
1001
1002 // ------------------------------------------------------------------------
1003
1029 template <class Lhs_T, class Rhs_T>
1031 {
1045 constexpr le_ (const Lhs_T& lhs = {}, const Rhs_T& rhs = {})
1046 : lhs_{ lhs }, rhs_{ rhs }, value_{ [&] {
1047 using std::operator<=;
1048
1049#if defined(__GNUC__)
1050#pragma GCC diagnostic push
1051#pragma GCC diagnostic ignored "-Wconversion"
1052#pragma GCC diagnostic ignored "-Wdouble-promotion"
1053#pragma GCC diagnostic ignored "-Wsign-compare"
1054#if defined(__clang__)
1055#pragma clang diagnostic ignored "-Wimplicit-int-float-conversion"
1056#pragma clang diagnostic ignored "-Wpedantic"
1057#endif
1058#endif
1061 {
1062 return Lhs_T::value <= Rhs_T::value;
1063 }
1064 else
1065 {
1066 return get (lhs_) <= get (rhs_);
1067 }
1068#if defined(__GNUC__)
1069#pragma GCC diagnostic pop
1070#endif
1071 }() }
1072 {
1073 }
1074
1087 [[nodiscard]] constexpr
1088 operator bool () const
1089 {
1090 return value_;
1091 }
1092
1105
1106 [[nodiscard]] constexpr auto
1107 lhs (void) const
1108 {
1109 return get (lhs_);
1110 }
1111
1124 [[nodiscard]] constexpr auto
1125 rhs (void) const
1126 {
1127 return get (rhs_);
1128 }
1129
1133 const Lhs_T lhs_{};
1134
1138 const Rhs_T rhs_{};
1139
1143 const bool value_{};
1144 };
1145
1146 // Deduction guide.
1147 template <typename Lhs_T, typename Rhs_T>
1148 le_ (const Lhs_T&, const Rhs_T&) -> le_<Lhs_T, Rhs_T>;
1149
1150 // ------------------------------------------------------------------------
1151
1176 template <class Lhs_T, class Rhs_T>
1178 {
1190 constexpr and_ (const Lhs_T& lhs = {}, const Rhs_T& rhs = {})
1191 : lhs_{ lhs }, rhs_{ rhs },
1192 value_{ static_cast<bool> (lhs) and static_cast<bool> (rhs) }
1193 {
1194 }
1195
1207 [[nodiscard]] constexpr
1208 operator bool () const
1209 {
1210 return value_;
1211 }
1212
1225 [[nodiscard]] constexpr auto
1226 lhs (void) const
1227 {
1228 return get (lhs_);
1229 }
1230
1243 [[nodiscard]] constexpr auto
1244 rhs (void) const
1245 {
1246 return get (rhs_);
1247 }
1248
1252 const Lhs_T lhs_{};
1253
1257 const Rhs_T rhs_{};
1258
1262 const bool value_{};
1263 };
1264
1265 // Deduction guide.
1266 template <typename Lhs_T, typename Rhs_T>
1267 and_ (const Lhs_T&, const Rhs_T&) -> and_<Lhs_T, Rhs_T>;
1268
1269 // ------------------------------------------------------------------------
1270
1295 template <class Lhs_T, class Rhs_T>
1297 {
1309 constexpr or_ (const Lhs_T& lhs = {}, const Rhs_T& rhs = {})
1310 : lhs_{ lhs }, rhs_{ rhs },
1311 value_{ static_cast<bool> (lhs) or static_cast<bool> (rhs) }
1312 {
1313 }
1314
1326 [[nodiscard]] constexpr
1327 operator bool () const
1328 {
1329 return value_;
1330 }
1331
1344 [[nodiscard]] constexpr auto
1345 lhs (void) const
1346 {
1347 return get (lhs_);
1348 }
1349
1362 [[nodiscard]] constexpr auto
1363 rhs (void) const
1364 {
1365 return get (rhs_);
1366 }
1367
1371 const Lhs_T lhs_{};
1372
1376 const Rhs_T rhs_{};
1377
1381 const bool value_{};
1382 };
1383
1384 // Deduction guide.
1385 template <typename Lhs_T, typename Rhs_T>
1386 or_ (const Lhs_T&, const Rhs_T&) -> or_<Lhs_T, Rhs_T>;
1387
1388 // ------------------------------------------------------------------------
1389
1413 template <class T>
1415 {
1426 explicit constexpr not_ (const T& t = {})
1427 : t_{ t }, value_{ not static_cast<bool> (t) }
1428 {
1429 }
1430
1442 [[nodiscard]] constexpr
1443 operator bool () const
1444 {
1445 return value_;
1446 }
1447
1459 [[nodiscard]] constexpr auto
1460 value () const
1461 {
1462 return get (t_);
1463 }
1464
1468 const T t_{};
1469
1473 const bool value_{};
1474 };
1475
1476 // Deduction guide.
1477 template <typename T>
1478 not_ (const T&) -> not_<T>;
1479
1480 // ------------------------------------------------------------------------
1481
1482#if defined(__cpp_exceptions)
1483
1510 template <class Callable_T, class Exception_T = void>
1512 {
1524 constexpr explicit throws_ (const Callable_T& func)
1525 : value_{ [&func] {
1526 try
1527 {
1528 func ();
1529 }
1530 catch (const Exception_T&)
1531 {
1532 return true;
1533 }
1534 catch (...)
1535 {
1536 return false;
1537 }
1538 return false;
1539 }() }
1540 {
1541 }
1542
1555 [[nodiscard]] constexpr
1556 operator bool () const
1557 {
1558 return value_;
1559 }
1560
1564 const bool value_{};
1565 };
1566
1567 // ------------------------------------------------------------------------
1568
1593 template <class Callable_T>
1594 struct throws_<Callable_T, void> : type_traits::op
1595 {
1607 constexpr explicit throws_ (const Callable_T& func)
1608 : value_{ [&func] {
1609 try
1610 {
1611 func ();
1612 }
1613 catch (...)
1614 {
1615 return true;
1616 }
1617 return false;
1618 }() }
1619 {
1620 }
1621
1633 [[nodiscard]] constexpr
1634 operator bool () const
1635 {
1636 return value_;
1637 }
1638
1642 const bool value_{};
1643 };
1644
1645 // ------------------------------------------------------------------------
1646
1671 template <class Callable_T>
1673 {
1684 constexpr explicit nothrow_ (const Callable_T& func)
1685 : value_{ [&func] {
1686 try
1687 {
1688 func ();
1689 }
1690 catch (...)
1691 {
1692 return false;
1693 }
1694 return true;
1695 }() }
1696 {
1697 }
1698
1710 [[nodiscard]] constexpr
1711 operator bool () const
1712 {
1713 return value_;
1714 }
1715
1719 const bool value_{};
1720 };
1721
1722#endif
1723
1724 // ------------------------------------------------------------------------
1725
1745 {
1746 public:
1754 const reflection::source_location location);
1755
1760
1769 template <class T>
1770 auto&
1771 operator<< (const T& msg);
1772
1785 [[nodiscard]] constexpr bool
1786 value () const
1787 {
1788 return value_;
1789 }
1790
1791 protected:
1795 bool value_{};
1796
1801 bool abort_ = false;
1802
1807
1812 std::string message_{};
1813 };
1814
1815 // ------------------------------------------------------------------------
1816
1835 template <class Expr_T>
1837 {
1838 public:
1851 constexpr explicit deferred_reporter (
1852 const Expr_T& expr, bool abort,
1853 const reflection::source_location& location);
1854
1859
1860 protected:
1864 const Expr_T expr_{};
1865 };
1866
1867 // ------------------------------------------------------------------------
1868 } // namespace detail
1869
1870 // --------------------------------------------------------------------------
1871} // namespace micro_os_plus::micro_test_plus
1872
1873#if defined(__GNUC__)
1874#pragma GCC diagnostic pop
1875#endif
1876
1877// ----------------------------------------------------------------------------
1878
1879#endif // __cplusplus
1880
1881// ----------------------------------------------------------------------------
1882
1883#endif // MICRO_TEST_PLUS_DETAIL_H_
1884
1885// ----------------------------------------------------------------------------

Generated via docusaurus-plugin-doxygen by Doxygen 1.14.0.