detail-inlines.h File
C++ header file with inline implementations for the µTest++ internal detail namespace. More...
Included Headers
Namespaces Index
| namespace | micro_os_plus |
|
The primary namespace for the µOS++ framework. More... | |
| namespace | micro_test_plus |
|
Primary namespace for the µTest++ testing framework. More... | |
| namespace | detail |
|
Internal implementation details for the µTest++ framework. More... | |
| namespace | comparison_lookup |
|
Names for the checks of the comparison operators, looked up as the apply() functions look them up. More... | |
Classes Index
| struct | comparison_integer<T> |
|
The integer type used to compare a value of type T. More... | |
| struct | comparison_integer<T> |
|
The integer type used to compare a character type. More... | |
Concepts Index
| concept | comparable |
|
Concept satisfied when two operands can be compared by the comparator selected by Op. More... | |
| concept | comparable_operands |
|
Concept satisfied when the operands of a comparator can be written and compared. More... | |
| concept | can_compare |
|
Satisfied if the comparison selected by Op of two const objects is well-formed. More... | |
| concept | function_pointer_pair |
|
Concept satisfied by two pointers, one of which points to a function. More... | |
| concept | sign_mixed_integers |
|
Concept satisfied by two integer types of different signedness. More... | |
| concept | tag_has_symbol |
|
Concept satisfied when the tag of a comparator or of a predicate has a symbol that can be written. More... | |
Typedefs Index
template <class T> | |
| using | comparison_integer_t = typename comparison_integer< T >::type |
|
Alias of the integer type used to compare the type T. More... | |
template <class T> | |
| using | comparison_operand_t = unwrapped_t< decltype(detail::as_operand(std::declval< T >()))> |
|
The type with which an operand of a comparator is compared. More... | |
Enumerations Index
| enum class | comparison : unsigned char { ... } |
|
The comparison operators, as the template argument of the comparable concept. More... | |
Operators Index
template <class T, class R> | |
| constexpr auto | operator<=> (const array_operand< T > &lhs, const R &rhs) |
|
Orders an array operand and a range lexicographically. More... | |
template <character Char_T> | |
| constexpr std::strong_ordering | operator<=> (const basic_c_string< Char_T > &lhs, const basic_c_string< Char_T > &rhs) noexcept |
|
Orders two C string operands. More... | |
template <character Char_T> | |
| constexpr std::strong_ordering | operator<=> (const basic_c_string< Char_T > &lhs, std::type_identity_t< std::basic_string_view< Char_T > > rhs) noexcept |
|
Orders a C string operand and a string. More... | |
template <class T, class R> | |
| constexpr bool | operator== (const array_operand< T > &lhs, const R &rhs) |
|
Compares an array operand with a range for equality. More... | |
template <character Char_T> | |
| constexpr bool | operator== (const basic_c_string< Char_T > &lhs, const basic_c_string< Char_T > &rhs) noexcept |
|
Compares two C string operands for equality. More... | |
template <character Char_T> | |
| constexpr bool | operator== (const basic_c_string< Char_T > &lhs, std::nullptr_t) noexcept |
|
Checks whether a C string operand is a null pointer. More... | |
template <character Char_T> | |
| constexpr bool | operator== (const basic_c_string< Char_T > &lhs, std::type_identity_t< std::basic_string_view< Char_T > > rhs) noexcept |
|
Compares a C string operand with a string. More... | |
Functions Index
template <class T> | |
| void | append_number (std::string &buffer, T v) |
|
Appends the shortest decimal representation of a numeric value to a buffer. More... | |
template <class T> | |
| void | append_pointer (std::string &buffer, T *v) |
|
Appends the hexadecimal address of a pointer to a buffer. More... | |
template <class T> | |
| constexpr auto | as_comparison_integer (const T value) noexcept -> comparison_integer_t< T > |
|
Converts an integer or a character to the type used to compare it. More... | |
template <class T> | |
| constexpr auto | as_operand (T &&t) noexcept -> decltype(auto) |
|
Prepares an operand of a comparator. More... | |
template <class Lhs_T, class Rhs_T, class Epsilon_T> | |
| constexpr bool | differ_by_at_most (Lhs_T lhs, Rhs_T rhs, Epsilon_T epsilon) |
|
Tells whether two numbers differ by at most a tolerance. More... | |
template <class Tag_T> | |
| constexpr void | reject_compare_tag (void) noexcept |
|
Stops the compilation of a compare_op whose tag is rejected, with a message that tells why. More... | |
template <comparison Op, class Lhs_T, class Rhs_T> | |
| constexpr void | reject_comparison (void) noexcept |
|
Stops the compilation of a comparator whose operands are rejected, with a message that tells why. More... | |
template <class Tag_T> | |
| constexpr void | reject_predicate_tag (void) noexcept |
|
Stops the compilation of a predicate_op whose tag is rejected, with a message that tells why. More... | |
template <class T> | |
| constexpr auto | unwrap (const T &t) -> decltype(auto) |
|
Returns the value wrapped by a framework type, or the operand itself. More... | |
template <class Lhs_T, class Rhs_T> | |
| constexpr bool | within_tolerance (const Lhs_T &lhs, const Rhs_T &rhs) |
|
Deprecated check whether two operands are equal within the tolerance of the floating-point wrappers. More... | |
Description
C++ header file with inline implementations for the µTest++ internal detail namespace.
This header provides the out-of-line template and inline implementations for all types declared in detail.h. It defines the bodies of the unwrap() helper, the unary and binary operator base class templates, the comparison tags, all relational, approximate, and logical comparator constructors, the predicate constructor, the tolerance helpers (within_tolerance(), differ_by_at_most()), the callable operator types (throws_op, nothrow_op), the append_number() and append_pointer() formatting helpers, the basic_c_string operand and its operators, and as_operand().
Separating the implementations from the declarations keeps detail.h concise and focused on the interface, whilst grouping the complex lambda-based constructor bodies here for maintainability.
All definitions reside within the micro_os_plus::micro_test_plus::detail namespace.
This file is included by detail.h; the applications include micro-os-plus/micro-test-plus.h, not this file.
Typedefs
comparison_integer_t
|
Alias of the integer type used to compare the type T.
Used by sign_mixed_integers, to tell the signedness, and by as_comparison_integer(), to convert the operands.
- Template Parameters
-
T The type of the operand.
Definition at line 326 of file detail-inlines.h.
comparison_operand_t
|
The type with which an operand of a comparator is compared.
The type of the operand after as_operand() and unwrap(), without references and qualifiers; for example detail::basic_c_string<char> for a string literal.
- Template Parameters
-
T The type deduced for the operand, possibly a reference.
Definition at line 386 of file detail-inlines.h.
Enumerations
comparison
| strong |
The comparison operators, as the template argument of the comparable concept.
- Enumeration values
-
equal The == operator, checked by eq() not_equal The != operator, checked by ne() greater The > operator, checked by gt() greater_equal The >= operator, checked by ge() less The < operator, checked by lt() less_equal The <= operator, checked by le()
A single concept, parametrised by the operator, checks the operands of all the comparators (eq(), ne(), gt(), ge(), lt(), and le()).
Definition at line 416 of file detail-inlines.h.
Operators
operator<=>()
| nodiscard constexpr |
Orders an array operand and a range lexicographically.
- Template Parameters
-
T The element type of the array operand.
R The type of the range.
- Parameters
-
lhs The array operand.
rhs The range, which may be another array operand.
- Returns
The lexicographic order of the elements.
A range that is a prefix of the other is the lesser one.
Definition at line 1696 of file detail-inlines.h.
References micro_os_plus::micro_test_plus::detail::array_operand< T >::begin, micro_os_plus::micro_test_plus::detail::array_operand< T >::end and micro_os_plus::micro_test_plus::detail::operator<=>.
operator<=>()
| nodiscard constexpr noexcept |
Orders two C string operands.
- Template Parameters
-
Char_T The character type.
- Parameters
-
lhs The left operand.
rhs The right operand.
- Returns
The lexicographic order of the characters; a null pointer is equal to another null pointer and less than any string.
A null pointer orders before any string.
Definition at line 1594 of file detail-inlines.h.
Referenced by micro_os_plus::micro_test_plus::detail::operator<=>.
operator<=>()
| nodiscard constexpr noexcept |
Orders a C string operand and a string.
- Template Parameters
-
Char_T The character type.
- Parameters
-
lhs The C string operand.
rhs The string.
- Returns
The lexicographic order of the characters; a null pointer is less than any string.
A null pointer orders before any string.
Definition at line 1610 of file detail-inlines.h.
operator==()
| nodiscard constexpr |
Compares an array operand with a range for equality.
- Template Parameters
-
T The element type of the array operand.
R The type of the range.
- Parameters
-
lhs The array operand.
rhs The range, which may be another array operand.
- Return Values
-
true The ranges have the same size and equal elements.
false Otherwise.
Ranges of different sizes are not equal, without comparing any element. The elements are compared as the scalar operands of eq() are, with equal_to::apply(), so that integers of different signedness are compared by value, not by converting the signed one to the unsigned type.
Definition at line 1681 of file detail-inlines.h.
References micro_os_plus::micro_test_plus::detail::array_operand< T >::begin and micro_os_plus::micro_test_plus::detail::array_operand< T >::end.
operator==()
| nodiscard constexpr noexcept |
Compares two C string operands for equality.
- Template Parameters
-
Char_T The character type.
- Parameters
-
lhs The left operand.
rhs The right operand.
- Return Values
-
true Both are null, or both are strings with the same characters.
false Otherwise.
Two null pointers are equal; a null pointer is not equal to any string, not even an empty one.
Definition at line 1555 of file detail-inlines.h.
operator==()
| nodiscard constexpr noexcept |
Checks whether a C string operand is a null pointer.
- Template Parameters
-
Char_T The character type.
- Parameters
-
lhs The C string operand.
- Return Values
-
true The operand is a null pointer.
false Otherwise.
Returns whether the operand is a null pointer.
Definition at line 1584 of file detail-inlines.h.
operator==()
| nodiscard constexpr noexcept |
Compares a C string operand with a string.
Also used for the standard strings of the same character type, which convert to the string view, and, as a rewritten candidate, with the operands in the reverse order.
- Template Parameters
-
Char_T The character type.
- Parameters
-
lhs The C string operand.
rhs The string.
- Return Values
-
true The operand is not null and has the same characters.
false Otherwise.
A null pointer is not equal to any string.
Definition at line 1571 of file detail-inlines.h.
Functions
append_number()
|
Appends the shortest decimal representation of a numeric value to a buffer.
- Template Parameters
-
T The numeric type to format.
- Parameters
-
buffer The string to append to.
v The value to format.
- Returns
Nothing.
The value is formatted into a local buffer, which is then appended to buffer.
For long double, a platform-specific path is chosen:
- On Windows and on platforms where long double has the same storage width as double (e.g. 32-bit Arm), the value is cast to double and formatted with std::to_chars.
- On all other platforms (e.g. x86-64 Linux/macOS with 80-bit extended precision, or AArch64 and RISC-V with 128-bit quad precision), snprintf with %.*Lg is used as a portable fallback, because std::to_chars for long double may be unavailable (e.g. when linking with lld). The precision starts at LDBL_DIG and is increased until the text reads back, with strtold, as the same value, up to LDBL_DECIMAL_DIG, which always reads back exactly. This gives the shortest exact form, as std::to_chars gives for the other types; a shorter form would need fewer than LDBL_DIG digits, and Lg removes the trailing zeros, so starting at LDBL_DIG does not lose it. For zero and the subnormal values, which have fewer significant digits, the precision starts at 1. The value of errno, which strtold may set for subnormal values, is preserved. If no precision reads back exactly, the C library handles long double with the precision of double (e.g. newlib on AArch64 and RISC-V), and the value is cast to double and formatted with std::to_chars, as above.
For all other numeric types, std::to_chars is called directly, providing locale-independent formatting. The snprintf() path uses the decimal point of the C locale, which is . unless the application changes it with setlocale().
Definition at line 1348 of file detail-inlines.h.
Reference micro_os_plus::micro_test_plus::detail::append_number.
Referenced by micro_os_plus::micro_test_plus::detail::expression_formatter::append_first_difference, micro_os_plus::micro_test_plus::detail::append_number, micro_os_plus::micro_test_plus::detail::expression_formatter::operator<<, micro_os_plus::micro_test_plus::detail::expression_formatter::operator<<, micro_os_plus::micro_test_plus::detail::expression_formatter::operator<<, micro_os_plus::micro_test_plus::detail::expression_formatter::operator<<, micro_os_plus::micro_test_plus::detail::expression_formatter::operator<<, micro_os_plus::micro_test_plus::detail::expression_formatter::operator<<, micro_os_plus::micro_test_plus::detail::expression_formatter::operator<<, micro_os_plus::micro_test_plus::detail::expression_formatter::operator<<, micro_os_plus::micro_test_plus::detail::expression_formatter::operator<<, micro_os_plus::micro_test_plus::detail::expression_formatter::operator<<, micro_os_plus::micro_test_plus::detail::expression_formatter::operator<<, micro_os_plus::micro_test_plus::detail::expression_formatter::operator<<, micro_os_plus::micro_test_plus::detail::expression_formatter::operator<<, micro_os_plus::micro_test_plus::detail::expression_formatter::operator<< and micro_os_plus::micro_test_plus::detail::reporter::operator<<.
append_pointer()
|
Appends the hexadecimal address of a pointer to a buffer.
Shared by the reporter and the expression_formatter, so that the pointers are displayed identically in the messages and in the expressions. Pointers to const or volatile objects, and function pointers, are accepted too.
- Template Parameters
-
T The type pointed to (an object or a function type).
- Parameters
-
buffer The string to append to.
v The pointer.
- Returns
Nothing.
Null pointers are rendered as "0x0", regardless of the platform, avoiding platform-specific representations such as "(nil)" on Linux/glibc. Non-null pointers are formatted with snprintf(), using the p specifier.
The p specifier expects a void*. Object pointers are converted implicitly to const volatile void*, which accepts any qualification, and the qualifiers are then removed with const_cast; a reinterpret_cast to void* would not compile for pointers to const objects. The object is not accessed. Function pointers, which do not convert to void* implicitly, use reinterpret_cast.
Definition at line 1454 of file detail-inlines.h.
Reference micro_os_plus::micro_test_plus::detail::append_pointer.
Referenced by micro_os_plus::micro_test_plus::detail::append_pointer, micro_os_plus::micro_test_plus::detail::expression_formatter::operator<< and micro_os_plus::micro_test_plus::detail::reporter::operator<<.
as_comparison_integer()
| nodiscard constexpr noexcept |
Converts an integer or a character to the type used to compare it.
The conversion keeps the value, since the type has the same size and signedness. Applied to both operands of the std::cmp_*() functions, which do not accept the character types.
- Template Parameters
-
T The type of the operand.
- Parameters
-
value The operand.
- Returns
The value, as comparison_integer_t<T>.
Definition at line 343 of file detail-inlines.h.
Reference micro_os_plus::micro_test_plus::detail::as_comparison_integer.
Referenced by micro_os_plus::micro_test_plus::detail::equal_to::apply, micro_os_plus::micro_test_plus::detail::greater::apply, micro_os_plus::micro_test_plus::detail::greater_equal::apply, micro_os_plus::micro_test_plus::detail::less::apply, micro_os_plus::micro_test_plus::detail::less_equal::apply, micro_os_plus::micro_test_plus::detail::not_equal_to::apply and micro_os_plus::micro_test_plus::detail::as_comparison_integer.
as_operand()
| nodiscard constexpr noexcept |
Prepares an operand of a comparator.
The arrays and the pointers of the character types (char, wchar_t, char8_t, char16_t, and char32_t, but not signed char or unsigned char, which are byte buffers) are converted to basic_c_string, so that they are compared by content; the other arrays, including those of volatile characters, are converted to array_operand, so that they are compared element by element, the functions to function pointers, and all other operands are returned unchanged, so the other pointers, including the pointers to volatile characters, and the functions are compared by address.
The other operands are forwarded, so that the comparator moves a temporary, and refers to a named operand.
- Template Parameters
-
T The type deduced for the forwarding reference.
- Parameters
-
t The operand.
- Returns
A basic_c_string for the C strings, an array_operand for the other arrays, otherwise t, forwarded.
Arrays of the character types are converted using their size as a bound, pointers to them using the null terminator; the const qualifier of the characters is ignored. The volatile characters are not strings, since basic_c_string cannot refer to them: an array of them is converted to array_operand, like the other arrays, and compared element by element, and a pointer to them is forwarded, and compared by address, like the other pointers. The functions are converted to function pointers. Every other operand is forwarded, unchanged, as an lvalue or an rvalue reference.
The qualifiers of an array are those of its elements, so the element type is taken from the type of the argument, not from the type without qualifiers, which would lose the volatile of the elements, and the conversion to the pointer to const elements would not compile.
Definition at line 1725 of file detail-inlines.h.
Reference micro_os_plus::micro_test_plus::detail::as_operand.
Referenced by micro_os_plus::micro_test_plus::detail::compare_op< Lhs_T, Rhs_T, Compare_T >::compare_op, micro_os_plus::micro_test_plus::detail::predicate_op< T, Predicate_T >::predicate_op, micro_os_plus::micro_test_plus::detail::as_operand, micro_os_plus::micro_test_plus::detail::compare_op, micro_os_plus::micro_test_plus::eq, micro_os_plus::micro_test_plus::ge, micro_os_plus::micro_test_plus::gt, micro_os_plus::micro_test_plus::le, micro_os_plus::micro_test_plus::lt and micro_os_plus::micro_test_plus::ne.
differ_by_at_most()
| nodiscard constexpr |
Tells whether two numbers differ by at most a tolerance.
If the three values are integers, the distance is computed exactly, as an unsigned value, also for operands of mixed signedness, and compared with the tolerance with std::cmp_less_equal(), so that neither overflows nor wraps around. Otherwise, the values are converted to their common floating-point type, and the absolute value of the difference is compared with the tolerance. A negative tolerance, or a NaN, makes the result false.
- Template Parameters
-
Lhs_T The arithmetic type of the first value.
Rhs_T The arithmetic type of the second value.
Epsilon_T The arithmetic type of the tolerance.
- Parameters
-
lhs The first value.
rhs The second value.
epsilon The tolerance.
- Return Values
-
true The distance between the values is less than or equal to the tolerance.
false Otherwise.
For the integers, the larger value is selected with std::cmp_less(), and the distance is computed in std::uintmax_t: when both values have the same sign, as the modular difference of their conversions, which is exact; otherwise, as the sum of the larger value and of the magnitude of the negative one. A sum that does not fit in std::uintmax_t is flagged as an overflow, and gives false, since the true distance is larger than any tolerance. The tolerance is compared with std::cmp_less_equal(), so a negative one gives false.
For the other types, the values are converted to their common type, which is a floating-point one, so std::int64_t values compared with a float tolerance lose precision; the comparison is inclusive, so a distance equal to the tolerance succeeds. Two equal values, including two infinities of the same sign, whose difference would be NaN, are at the distance zero; a NaN operand always fails.
Definition at line 940 of file detail-inlines.h.
References micro_os_plus::micro_test_plus::detail::math::abs and micro_os_plus::micro_test_plus::detail::differ_by_at_most.
Referenced by micro_os_plus::micro_test_plus::detail::approx_op< Lhs_T, Rhs_T, Epsilon_T >::approx_op, micro_os_plus::micro_test_plus::detail::compare_op and micro_os_plus::micro_test_plus::detail::differ_by_at_most.
reject_compare_tag()
| constexpr noexcept |
Stops the compilation of a compare_op whose tag is rejected, with a message that tells why.
Always fails the static assertion that applies, since it is called only when extension::compare_tag is not satisfied: the missing or unprintable symbol is reported first, then the apply() that cannot be called with the operands, or whose result is not convertible to bool.
- Template Parameters
-
Tag_T The tag of the comparator.
- Parameters
None.
- Returns
Nothing.
Definition at line 778 of file detail-inlines.h.
Reference micro_os_plus::micro_test_plus::detail::reject_compare_tag.
Referenced by micro_os_plus::micro_test_plus::detail::reject_compare_tag.
reject_comparison()
| constexpr noexcept |
Stops the compilation of a comparator whose operands are rejected, with a message that tells why.
Always fails the static assertion that applies, since it is called only when comparable_operands is not satisfied: an operand that cannot be written is reported first, then the operator that the operands do not support. Called by the overloads of the comparators that accept the rejected operands, so that the compiler shows this message instead of a list of the unsatisfied constraints.
- Template Parameters
-
Op The comparison of the comparator.
Lhs_T The type of the left operand.
Rhs_T The type of the right operand.
- Parameters
None.
- Returns
Nothing.
Definition at line 557 of file detail-inlines.h.
References micro_os_plus::micro_test_plus::detail::equal, micro_os_plus::micro_test_plus::detail::greater, micro_os_plus::micro_test_plus::detail::greater_equal, micro_os_plus::micro_test_plus::detail::less, micro_os_plus::micro_test_plus::detail::not_equal and micro_os_plus::micro_test_plus::detail::reject_comparison.
Referenced by micro_os_plus::micro_test_plus::detail::reject_comparison.
reject_predicate_tag()
| constexpr noexcept |
Stops the compilation of a predicate_op whose tag is rejected, with a message that tells why.
As reject_compare_tag(), for the tag of a predicate, whose apply() takes one operand; called only when extension::predicate_tag is not satisfied.
- Template Parameters
-
Tag_T The tag of the predicate.
- Parameters
None.
- Returns
Nothing.
Definition at line 815 of file detail-inlines.h.
Reference micro_os_plus::micro_test_plus::detail::reject_predicate_tag.
Referenced by micro_os_plus::micro_test_plus::detail::reject_predicate_tag.
unwrap()
| nodiscard constexpr |
Returns the value wrapped by a framework type, or the operand itself.
If the type T is a framework expression type (see extension::is_op) that provides a get() member function, it is invoked and its result returned. Otherwise a reference to the argument itself is returned, so that the types of the application, even those with a get() member function, are compared with their own operators, without a copy. The selection is performed at compile time via if constexpr with an inline requires expression; the return type is deduced with decltype (auto) from the selected branch.
Always call it qualified, as detail::unwrap(), so that argument-dependent lookup cannot select a function of the application, defined in the namespace of an operand.
The operand is returned by reference, without a copy; the result is valid only as long as the operand.
- Template Parameters
-
T The type of the operand.
- Parameters
-
t The operand.
- Returns
The value returned by t.get() for the framework wrappers (the literals and the to_* wrappers), otherwise a reference to t.
Definition at line 98 of file detail-inlines.h.
Reference micro_os_plus::micro_test_plus::detail::unwrap.
Referenced by micro_os_plus::micro_test_plus::detail::approx_op< Lhs_T, Rhs_T, Epsilon_T >::approx_op, micro_os_plus::micro_test_plus::detail::compare_op< Lhs_T, Rhs_T, Compare_T >::compare_op, micro_os_plus::micro_test_plus::detail::predicate_op< T, Predicate_T >::predicate_op, micro_os_plus::micro_test_plus::detail::approx_op< Lhs_T, Rhs_T, Epsilon_T >::epsilon, micro_os_plus::micro_test_plus::detail::binary_op< Lhs_T, Rhs_T >::lhs, micro_os_plus::micro_test_plus::detail::unary_op< T >::operand, micro_os_plus::micro_test_plus::detail::expression_formatter::operator<<, micro_os_plus::micro_test_plus::detail::binary_op< Lhs_T, Rhs_T >::rhs, micro_os_plus::micro_test_plus::detail::unwrap and micro_os_plus::micro_test_plus::detail::within_tolerance.
File Listing
The file content with the documentation metadata removed is:
Generated via doxygen2docusaurus 2.2.8 by Doxygen 1.18.0.