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 674 of file detail-inlines.h.
675 {
676 char buf[32];
677 if constexpr (std::is_same_v<T, long double>)
678 {
679#if defined(_WIN32) \
680 || (defined(__SIZEOF_LONG_DOUBLE__) \
681 && __SIZEOF_LONG_DOUBLE__ == __SIZEOF_DOUBLE__)
682
683
684
685
686
687 const auto [ptr, ec] = std::to_chars (buf, buf + sizeof (buf),
688 static_cast<double> (v));
689 if (ec == std::errc{})
690 buffer.append (buf, ptr);
691#else
692
693
694
695
696 snprintf (buf, sizeof (buf), "%Lg", v);
697 buffer.append (buf);
698#endif
699 }
700 else
701 {
702 const auto [ptr, ec] = std::to_chars (buf, buf + sizeof (buf), v);
703 if (ec == std::errc{})
704 buffer.append (buf, ptr);
705 }
706 }
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 83 of file detail-inlines.h.
84 {
85 if constexpr (requires { t.get (); })
86 return t.get ();
87 else
88 return t;
89 }
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_OS_PLUS_MICRO_TEST_PLUS_INLINES_DETAIL_INLINES_H_
43#define MICRO_OS_PLUS_MICRO_TEST_PLUS_INLINES_DETAIL_INLINES_H_
47#if defined(__cplusplus)
56#pragma GCC diagnostic push
58#pragma GCC diagnostic ignored "-Waggregate-return"
60#pragma clang diagnostic ignored "-Wunknown-warning-option"
61#pragma clang diagnostic ignored "-Wc++98-compat"
62#pragma clang diagnostic ignored "-Wc++98-compat-pedantic"
85 if constexpr (requires { t.get (); })
111 operator bool () const
135 template <class Lhs_T, class Rhs_T>
148 template <class Lhs_T, class Rhs_T>
150 operator bool () const
161 template <class Lhs_T, class Rhs_T>
174 template <class Lhs_T, class Rhs_T>
190 template <class Lhs_T, class Rhs_T>
199 using std::operator==;
200 using std::operator<;
203#pragma GCC diagnostic push
205#pragma GCC diagnostic ignored "-Wfloat-equal"
206#pragma GCC diagnostic ignored "-Wconversion"
207#pragma GCC diagnostic ignored "-Wdouble-promotion"
208#pragma GCC diagnostic ignored "-Wsign-compare"
209#if defined(__clang__)
210#pragma clang diagnostic ignored "-Wimplicit-int-float-conversion"
211#pragma clang diagnostic ignored "-Wpedantic"
220 return Lhs_T::value == Rhs_T::value;
248#pragma GCC diagnostic pop
263 template <class Lhs_T, class Rhs_T>
267 using std::operator==;
268 using std::operator!=;
269 using std::operator>;
272#pragma GCC diagnostic push
274#pragma GCC diagnostic ignored "-Wfloat-equal"
275#pragma GCC diagnostic ignored "-Wconversion"
276#pragma GCC diagnostic ignored "-Wdouble-promotion"
277#pragma GCC diagnostic ignored "-Wsign-compare"
278#if defined(__clang__)
279#pragma clang diagnostic ignored "-Wimplicit-int-float-conversion"
280#pragma clang diagnostic ignored "-Wpedantic"
287 return Lhs_T::value != Rhs_T::value;
309#pragma GCC diagnostic pop
324 template <class Lhs_T, class Rhs_T>
328 using std::operator>;
331#pragma GCC diagnostic push
333#pragma GCC diagnostic ignored "-Wconversion"
334#pragma GCC diagnostic ignored "-Wdouble-promotion"
335#pragma GCC diagnostic ignored "-Wsign-compare"
336#if defined(__clang__)
337#pragma clang diagnostic ignored "-Wimplicit-int-float-conversion"
338#pragma clang diagnostic ignored "-Wpedantic"
345 return Lhs_T::value > Rhs_T::value;
353#pragma GCC diagnostic pop
368 template <class Lhs_T, class Rhs_T>
372 using std::operator>=;
375#pragma GCC diagnostic push
377#pragma GCC diagnostic ignored "-Wconversion"
378#pragma GCC diagnostic ignored "-Wdouble-promotion"
379#pragma GCC diagnostic ignored "-Wsign-compare"
380#if defined(__clang__)
381#pragma clang diagnostic ignored "-Wimplicit-int-float-conversion"
382#pragma clang diagnostic ignored "-Wpedantic"
389 return Lhs_T::value >= Rhs_T::value;
397#pragma GCC diagnostic pop
412 template <class Lhs_T, class Rhs_T>
416 using std::operator<;
419#pragma GCC diagnostic push
421#pragma GCC diagnostic ignored "-Wconversion"
422#pragma GCC diagnostic ignored "-Wdouble-promotion"
423#pragma GCC diagnostic ignored "-Wsign-compare"
424#if defined(__clang__)
425#pragma clang diagnostic ignored "-Wimplicit-int-float-conversion"
426#pragma clang diagnostic ignored "-Wpedantic"
433 return Lhs_T::value < Rhs_T::value;
441#pragma GCC diagnostic pop
456 template <class Lhs_T, class Rhs_T>
460 using std::operator<=;
463#pragma GCC diagnostic push
465#pragma GCC diagnostic ignored "-Wconversion"
466#pragma GCC diagnostic ignored "-Wdouble-promotion"
467#pragma GCC diagnostic ignored "-Wsign-compare"
468#if defined(__clang__)
469#pragma clang diagnostic ignored "-Wimplicit-int-float-conversion"
470#pragma clang diagnostic ignored "-Wpedantic"
477 return Lhs_T::value <= Rhs_T::value;
485#pragma GCC diagnostic pop
499 template <class Lhs_T, class Rhs_T>
502 lhs, rhs, static_cast<bool> (lhs) and static_cast<bool> (rhs)
515 template <class Lhs_T, class Rhs_T>
518 lhs, rhs, static_cast<bool> (lhs) or static_cast<bool> (rhs)
532 : unary_op_<T>{ t, not static_cast<bool> (t) }
538#if defined(__cpp_exceptions)
554 constexpr callable_op_::
555 operator bool () const
570 template <class Callable_T, class Exception_T>
572 const Callable_T& func)
579 catch (const Exception_T&)
601 template <class Callable_T>
627 template <class Callable_T>
649#pragma GCC diagnostic push
651#if defined(__clang__)
652#pragma clang diagnostic ignored "-Wunsafe-buffer-usage"
653#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
672 requires std::is_arithmetic_v<T>
677 if constexpr (std::is_same_v<T, long double>)
680 || (defined(__SIZEOF_LONG_DOUBLE__) \
681 && __SIZEOF_LONG_DOUBLE__ == __SIZEOF_DOUBLE__)
687 const auto [ptr, ec] = std::to_chars (buf, buf + sizeof (buf),
688 static_cast<double> (v));
689 if (ec == std::errc{})
690 buffer.append (buf, ptr);
696 snprintf (buf, sizeof (buf), "%Lg", v);
702 const auto [ptr, ec] = std::to_chars (buf, buf + sizeof (buf), v);
703 if (ec == std::errc{})
704 buffer.append (buf, ptr);
709#pragma GCC diagnostic pop
721#pragma GCC diagnostic pop
Generated via doxygen2docusaurus 2.2.2 by Doxygen 1.17.0.