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 653 of file detail-inlines.h.
654 {
655 char buf[32];
656 if constexpr (std::is_same_v<T, long double>)
657 {
658#if defined(_WIN32) \
659 || (defined(__SIZEOF_LONG_DOUBLE__) \
660 && __SIZEOF_LONG_DOUBLE__ == __SIZEOF_DOUBLE__)
661
662
663
664
665
666 const auto [ptr, ec] = std::to_chars (buf, buf + sizeof (buf),
667 static_cast<double> (v));
668 if (ec == std::errc{})
669 buffer.append (buf, ptr);
670#else
671
672
673
674
675 snprintf (buf, sizeof (buf), "%Lg", v);
676 buffer.append (buf);
677#endif
678 }
679 else
680 {
681 const auto [ptr, ec] = std::to_chars (buf, buf + sizeof (buf), v);
682 if (ec == std::errc{})
683 buffer.append (buf, ptr);
684 }
685 }
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 81 of file detail-inlines.h.
82 {
83 if constexpr (requires { t.get (); })
84 return t.get ();
85 else
86 return t;
87 }
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 "-Wc++98-compat"
60#pragma clang diagnostic ignored "-Wc++98-compat-pedantic"
83 if constexpr (requires { t.get (); })
109 operator bool () const
133 template <class Lhs_T, class Rhs_T>
146 template <class Lhs_T, class Rhs_T>
148 operator bool () const
159 template <class Lhs_T, class Rhs_T>
172 template <class Lhs_T, class Rhs_T>
188 template <class Lhs_T, class Rhs_T>
197 using std::operator==;
198 using std::operator<;
201#pragma GCC diagnostic push
202#pragma GCC diagnostic ignored "-Wfloat-equal"
203#pragma GCC diagnostic ignored "-Wconversion"
204#pragma GCC diagnostic ignored "-Wdouble-promotion"
205#pragma GCC diagnostic ignored "-Wsign-compare"
206#if defined(__clang__)
207#pragma clang diagnostic ignored "-Wimplicit-int-float-conversion"
208#pragma clang diagnostic ignored "-Wpedantic"
216 return Lhs_T::value == Rhs_T::value;
243#pragma GCC diagnostic pop
258 template <class Lhs_T, class Rhs_T>
262 using std::operator==;
263 using std::operator!=;
264 using std::operator>;
267#pragma GCC diagnostic push
268#pragma GCC diagnostic ignored "-Wfloat-equal"
269#pragma GCC diagnostic ignored "-Wconversion"
270#pragma GCC diagnostic ignored "-Wdouble-promotion"
271#pragma GCC diagnostic ignored "-Wsign-compare"
272#if defined(__clang__)
273#pragma clang diagnostic ignored "-Wimplicit-int-float-conversion"
274#pragma clang diagnostic ignored "-Wpedantic"
280 return Lhs_T::value != Rhs_T::value;
301#pragma GCC diagnostic pop
316 template <class Lhs_T, class Rhs_T>
320 using std::operator>;
323#pragma GCC diagnostic push
324#pragma GCC diagnostic ignored "-Wconversion"
325#pragma GCC diagnostic ignored "-Wdouble-promotion"
326#pragma GCC diagnostic ignored "-Wsign-compare"
327#if defined(__clang__)
328#pragma clang diagnostic ignored "-Wimplicit-int-float-conversion"
329#pragma clang diagnostic ignored "-Wpedantic"
335 return Lhs_T::value > Rhs_T::value;
342#pragma GCC diagnostic pop
357 template <class Lhs_T, class Rhs_T>
361 using std::operator>=;
364#pragma GCC diagnostic push
365#pragma GCC diagnostic ignored "-Wconversion"
366#pragma GCC diagnostic ignored "-Wdouble-promotion"
367#pragma GCC diagnostic ignored "-Wsign-compare"
368#if defined(__clang__)
369#pragma clang diagnostic ignored "-Wimplicit-int-float-conversion"
370#pragma clang diagnostic ignored "-Wpedantic"
376 return Lhs_T::value >= Rhs_T::value;
383#pragma GCC diagnostic pop
398 template <class Lhs_T, class Rhs_T>
402 using std::operator<;
405#pragma GCC diagnostic push
406#pragma GCC diagnostic ignored "-Wconversion"
407#pragma GCC diagnostic ignored "-Wdouble-promotion"
408#pragma GCC diagnostic ignored "-Wsign-compare"
409#if defined(__clang__)
410#pragma clang diagnostic ignored "-Wimplicit-int-float-conversion"
411#pragma clang diagnostic ignored "-Wpedantic"
417 return Lhs_T::value < Rhs_T::value;
424#pragma GCC diagnostic pop
439 template <class Lhs_T, class Rhs_T>
443 using std::operator<=;
446#pragma GCC diagnostic push
447#pragma GCC diagnostic ignored "-Wconversion"
448#pragma GCC diagnostic ignored "-Wdouble-promotion"
449#pragma GCC diagnostic ignored "-Wsign-compare"
450#if defined(__clang__)
451#pragma clang diagnostic ignored "-Wimplicit-int-float-conversion"
452#pragma clang diagnostic ignored "-Wpedantic"
458 return Lhs_T::value <= Rhs_T::value;
465#pragma GCC diagnostic pop
479 template <class Lhs_T, class Rhs_T>
482 lhs, rhs, static_cast<bool> (lhs) and static_cast<bool> (rhs)
495 template <class Lhs_T, class Rhs_T>
498 lhs, rhs, static_cast<bool> (lhs) or static_cast<bool> (rhs)
512 : unary_op_<T>{ t, not static_cast<bool> (t) }
518#if defined(__cpp_exceptions)
534 constexpr callable_op_::
535 operator bool () const
550 template <class Callable_T, class Exception_T>
552 const Callable_T& func)
559 catch (const Exception_T&)
581 template <class Callable_T>
607 template <class Callable_T>
629#pragma GCC diagnostic push
630#if defined(__clang__)
631#pragma clang diagnostic ignored "-Wunsafe-buffer-usage"
632#pragma clang diagnostic ignored "-Wunsafe-buffer-usage-in-libc-call"
651 requires std::is_arithmetic_v<T>
656 if constexpr (std::is_same_v<T, long double>)
659 || (defined(__SIZEOF_LONG_DOUBLE__) \
660 && __SIZEOF_LONG_DOUBLE__ == __SIZEOF_DOUBLE__)
666 const auto [ptr, ec] = std::to_chars (buf, buf + sizeof (buf),
667 static_cast<double> (v));
668 if (ec == std::errc{})
669 buffer.append (buf, ptr);
675 snprintf (buf, sizeof (buf), "%Lg", v);
681 const auto [ptr, ec] = std::to_chars (buf, buf + sizeof (buf), v);
682 if (ec == std::errc{})
683 buffer.append (buf, ptr);
688#pragma GCC diagnostic pop
700#pragma GCC diagnostic pop
Generated via doxygen2docusaurus 2.2.0 by Doxygen 1.17.0.