C++ header file with inline implementations for the µTest++ internal detail namespace. More...
#include <charconv>
Namespaces Index
Functions Index
template <class T> |
| void | append_number_ (std::string &buffer, T v) |
|
Appends the string representation of a numeric value to a buffer, using std::to_chars for allocation-free, locale-independent formatting. More...
|
|
template <class T> |
| constexpr auto | get (const T &t) |
|
Generic getter function template for value retrieval. 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 generic getter, the unary and binary operator base class templates, all relational and logical comparator constructors, and the callable operator types (throws_, nothrow_).
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, ensuring clear separation from user code and minimising the risk of naming conflicts.
This file is intended solely for internal use within the framework and should not be included directly by user code.
Functions
append_number_()
template <class T>
| void micro_os_plus::micro_test_plus::detail::append_number_ (std::string & buffer, T v) |
|
Appends the string representation of a numeric value to a buffer, using std::to_chars for allocation-free, locale-independent formatting.
- Template Parameters
-
| T | The numeric type to format. |
- Parameters
-
| buffer | The string to append to. |
| v | The value to format. |
- Returns
Nothing.
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., ARM, RISC-V), the value is cast to double and formatted with std::to_chars.
- On x86-64 Linux/macOS with 80-bit extended precision, snprintf with Lg is used as a portable fallback because std::to_chars for long double may be unavailable when linking with lld.
For all other numeric types, std::to_chars is called directly, providing locale-independent, allocation-free formatting.
Definition at line 654 of file detail-inlines.h.
655 {
656 char buf[32];
657 if constexpr (std::is_same_v<T, long double>)
658 {
659#if defined(_WIN32) \
660 || (defined(__SIZEOF_LONG_DOUBLE__) \
661 && __SIZEOF_LONG_DOUBLE__ == __SIZEOF_DOUBLE__)
662
663
664
665
666
667 const auto [ptr, ec] = std::to_chars (buf, buf + sizeof (buf),
668 static_cast<double> (v));
669 if (ec == std::errc{})
670 buffer.append (buf, ptr);
671#else
672
673
674
675
676 snprintf (buf, sizeof (buf), "%Lg", v);
677 buffer.append (buf);
678#endif
679 }
680 else
681 {
682 const auto [ptr, ec] = std::to_chars (buf, buf + sizeof (buf), v);
683 if (ec == std::errc{})
684 buffer.append (buf, ptr);
685 }
686 }
Referenced by 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::reporter::operator<<.
get()
template <class T>
| auto micro_os_plus::micro_test_plus::detail::get (const T & t) |
|
nodiscard
constexpr
|
Generic getter function template for value retrieval.
- Template Parameters
-
| T | The type from which the value is to be retrieved. |
- Parameters
-
| t | The object or value to be accessed. |
- Returns
The value obtained via the relevant getter implementation.
If the type T provides a get() member function, it is invoked and its result returned. Otherwise the argument itself is returned unchanged. The selection is performed at compile time via if constexpr with an inline requires expression.
Definition at line 82 of file detail-inlines.h.
83 {
84 if constexpr (requires { t.get (); })
85 return t.get ();
86 else
87 return t;
88 }
Referenced by micro_os_plus::micro_test_plus::detail::eq_< Lhs_T, Rhs_T >::eq_, micro_os_plus::micro_test_plus::detail::ge_< Lhs_T, Rhs_T >::ge_, micro_os_plus::micro_test_plus::detail::gt_< Lhs_T, Rhs_T >::gt_, micro_os_plus::micro_test_plus::detail::le_< Lhs_T, Rhs_T >::le_, micro_os_plus::micro_test_plus::detail::lt_< Lhs_T, Rhs_T >::lt_, micro_os_plus::micro_test_plus::detail::ne_< Lhs_T, Rhs_T >::ne_, 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<< and micro_os_plus::micro_test_plus::detail::binary_op_< Lhs_T, Rhs_T >::rhs.
File Listing
The file content with the documentation metadata removed is:
42#ifndef MICRO_TEST_PLUS_DETAIL_INLINES_H_
43#define MICRO_TEST_PLUS_DETAIL_INLINES_H_
56#pragma GCC diagnostic push
57#pragma GCC diagnostic ignored "-Waggregate-return"
59#pragma clang diagnostic ignored "-Wunknown-warning-option"
60#pragma clang diagnostic ignored "-Wc++98-compat"
61#pragma clang diagnostic ignored "-Wc++98-compat-pedantic"
84 if constexpr (requires { t.get (); })
110 operator bool () const
134 template <class Lhs_T, class Rhs_T>
147 template <class Lhs_T, class Rhs_T>
149 operator bool () const
160 template <class Lhs_T, class Rhs_T>
173 template <class Lhs_T, class Rhs_T>
189 template <class Lhs_T, class Rhs_T>
198 using std::operator==;
199 using std::operator<;
202#pragma GCC diagnostic push
203#pragma GCC diagnostic ignored "-Wfloat-equal"
204#pragma GCC diagnostic ignored "-Wconversion"
205#pragma GCC diagnostic ignored "-Wdouble-promotion"
206#pragma GCC diagnostic ignored "-Wsign-compare"
207#if defined(__clang__)
208#pragma clang diagnostic ignored "-Wimplicit-int-float-conversion"
209#pragma clang diagnostic ignored "-Wpedantic"
217 return Lhs_T::value == Rhs_T::value;
244#pragma GCC diagnostic pop
259 template <class Lhs_T, class Rhs_T>
263 using std::operator==;
264 using std::operator!=;
265 using std::operator>;
268#pragma GCC diagnostic push
269#pragma GCC diagnostic ignored "-Wfloat-equal"
270#pragma GCC diagnostic ignored "-Wconversion"
271#pragma GCC diagnostic ignored "-Wdouble-promotion"
272#pragma GCC diagnostic ignored "-Wsign-compare"
273#if defined(__clang__)
274#pragma clang diagnostic ignored "-Wimplicit-int-float-conversion"
275#pragma clang diagnostic ignored "-Wpedantic"
281 return Lhs_T::value != Rhs_T::value;
302#pragma GCC diagnostic pop
317 template <class Lhs_T, class Rhs_T>
321 using std::operator>;
324#pragma GCC diagnostic push
325#pragma GCC diagnostic ignored "-Wconversion"
326#pragma GCC diagnostic ignored "-Wdouble-promotion"
327#pragma GCC diagnostic ignored "-Wsign-compare"
328#if defined(__clang__)
329#pragma clang diagnostic ignored "-Wimplicit-int-float-conversion"
330#pragma clang diagnostic ignored "-Wpedantic"
336 return Lhs_T::value > Rhs_T::value;
343#pragma GCC diagnostic pop
358 template <class Lhs_T, class Rhs_T>
362 using std::operator>=;
365#pragma GCC diagnostic push
366#pragma GCC diagnostic ignored "-Wconversion"
367#pragma GCC diagnostic ignored "-Wdouble-promotion"
368#pragma GCC diagnostic ignored "-Wsign-compare"
369#if defined(__clang__)
370#pragma clang diagnostic ignored "-Wimplicit-int-float-conversion"
371#pragma clang diagnostic ignored "-Wpedantic"
377 return Lhs_T::value >= Rhs_T::value;
384#pragma GCC diagnostic pop
399 template <class Lhs_T, class Rhs_T>
403 using std::operator<;
406#pragma GCC diagnostic push
407#pragma GCC diagnostic ignored "-Wconversion"
408#pragma GCC diagnostic ignored "-Wdouble-promotion"
409#pragma GCC diagnostic ignored "-Wsign-compare"
410#if defined(__clang__)
411#pragma clang diagnostic ignored "-Wimplicit-int-float-conversion"
412#pragma clang diagnostic ignored "-Wpedantic"
418 return Lhs_T::value < Rhs_T::value;
425#pragma GCC diagnostic pop
440 template <class Lhs_T, class Rhs_T>
444 using std::operator<=;
447#pragma GCC diagnostic push
448#pragma GCC diagnostic ignored "-Wconversion"
449#pragma GCC diagnostic ignored "-Wdouble-promotion"
450#pragma GCC diagnostic ignored "-Wsign-compare"
451#if defined(__clang__)
452#pragma clang diagnostic ignored "-Wimplicit-int-float-conversion"
453#pragma clang diagnostic ignored "-Wpedantic"
459 return Lhs_T::value <= Rhs_T::value;
466#pragma GCC diagnostic pop
480 template <class Lhs_T, class Rhs_T>
483 lhs, rhs, static_cast<bool> (lhs) and static_cast<bool> (rhs)
496 template <class Lhs_T, class Rhs_T>
499 lhs, rhs, static_cast<bool> (lhs) or static_cast<bool> (rhs)
513 : unary_op_<T>{ t, not static_cast<bool> (t) }
519#if defined(__cpp_exceptions)
535 constexpr callable_op_::
536 operator bool () const
551 template <class Callable_T, class Exception_T>
553 const Callable_T& func)
560 catch (const Exception_T&)
582 template <class Callable_T>
608 template <class Callable_T>
630#pragma GCC diagnostic push
631#if defined(__clang__)
632#pragma clang diagnostic ignored "-Wunsafe-buffer-usage"
633#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
652 requires std::is_arithmetic_v<T>
657 if constexpr (std::is_same_v<T, long double>)
660 || (defined(__SIZEOF_LONG_DOUBLE__) \
661 && __SIZEOF_LONG_DOUBLE__ == __SIZEOF_DOUBLE__)
667 const auto [ptr, ec] = std::to_chars (buf, buf + sizeof (buf),
668 static_cast<double> (v));
669 if (ec == std::errc{})
670 buffer.append (buf, ptr);
676 snprintf (buf, sizeof (buf), "%Lg", v);
682 const auto [ptr, ec] = std::to_chars (buf, buf + sizeof (buf), v);
683 if (ec == std::errc{})
684 buffer.append (buf, ptr);
689#pragma GCC diagnostic pop
701#pragma GCC diagnostic pop
Generated via doxygen2docusaurus 2.2.1 by Doxygen 1.17.0.