17#ifndef MICRO_TEST_PLUS_DETAIL_H_
18#define MICRO_TEST_PLUS_DETAIL_H_
31#pragma GCC diagnostic push
32#pragma GCC diagnostic ignored "-Wpadded"
33#pragma GCC diagnostic ignored "-Waggregate-return"
35#pragma clang diagnostic ignored "-Wc++98-compat"
52 template <
class Expr_T>
67 [[nodiscard]]
constexpr auto
68 get_impl (
const T& t,
int) ->
decltype (t.get ())
78 [[nodiscard]]
constexpr auto
88 [[nodiscard]]
constexpr auto
101 template <
class Lhs_T,
class Rhs_T>
104 constexpr eq_ (
const Lhs_T&
lhs = {},
const Rhs_T&
rhs = {})
108 using std::operator==;
109 using std::operator<;
112#pragma GCC diagnostic push
113#pragma GCC diagnostic ignored "-Wfloat-equal"
114#pragma GCC diagnostic ignored "-Wconversion"
115#pragma GCC diagnostic ignored "-Wdouble-promotion"
116#pragma GCC diagnostic ignored "-Wsign-compare"
117#if defined(__clang__)
118#pragma clang diagnostic ignored "-Wimplicit-int-float-conversion"
119#pragma clang diagnostic ignored "-Wpedantic"
127 return Lhs_T::value == Rhs_T::value;
154#pragma GCC diagnostic pop
160 [[nodiscard]]
constexpr
161 operator bool ()
const
166 [[nodiscard]]
constexpr auto
172 [[nodiscard]]
constexpr auto
187 template <
class Lhs_T,
class Rhs_T>
190 constexpr ne_ (
const Lhs_T& lhs = {},
const Rhs_T& rhs = {})
191 : lhs_{ lhs }, rhs_{ rhs }, value_{ [&] {
192 using std::operator==;
193 using std::operator!=;
194 using std::operator>;
197#pragma GCC diagnostic push
198#pragma GCC diagnostic ignored "-Wfloat-equal"
199#pragma GCC diagnostic ignored "-Wconversion"
200#pragma GCC diagnostic ignored "-Wdouble-promotion"
201#pragma GCC diagnostic ignored "-Wsign-compare"
202#if defined(__clang__)
203#pragma clang diagnostic ignored "-Wimplicit-int-float-conversion"
204#pragma clang diagnostic ignored "-Wpedantic"
207 if constexpr (type_traits::has_value_v<Lhs_T>
208 and type_traits::has_value_v<Rhs_T>)
210 return Lhs_T::value != Rhs_T::value;
212 else if constexpr (type_traits::has_epsilon_v<Lhs_T>
213 and type_traits::has_epsilon_v<Rhs_T>)
215 return math::abs (get (lhs_) - get (rhs_))
216 > math::min_value (Lhs_T::epsilon, Rhs_T::epsilon);
218 else if constexpr (type_traits::has_epsilon_v<Lhs_T>)
220 return math::abs (get (lhs_) - get (rhs_)) > Lhs_T::epsilon;
222 else if constexpr (type_traits::has_epsilon_v<Rhs_T>)
224 return math::abs (get (lhs_) - get (rhs_)) > Rhs_T::epsilon;
228 return get (lhs_) !=
get (rhs_);
231#pragma GCC diagnostic pop
237 [[nodiscard]]
constexpr
238 operator bool ()
const
242 [[nodiscard]]
constexpr auto
247 [[nodiscard]]
constexpr auto
262 template <
class Lhs_T,
class Rhs_T>
265 constexpr gt_ (
const Lhs_T& lhs = {},
const Rhs_T& rhs = {})
266 : lhs_{ lhs }, rhs_{ rhs }, value_{ [&] {
267 using std::operator>;
270#pragma GCC diagnostic push
271#pragma GCC diagnostic ignored "-Wconversion"
272#pragma GCC diagnostic ignored "-Wdouble-promotion"
273#pragma GCC diagnostic ignored "-Wsign-compare"
274#if defined(__clang__)
275#pragma clang diagnostic ignored "-Wimplicit-int-float-conversion"
276#pragma clang diagnostic ignored "-Wpedantic"
279 if constexpr (type_traits::has_value_v<Lhs_T>
280 and type_traits::has_value_v<Rhs_T>)
282 return Lhs_T::value > Rhs_T::value;
286 return get (lhs_) > get (rhs_);
289#pragma GCC diagnostic pop
295 [[nodiscard]]
constexpr
296 operator bool ()
const
300 [[nodiscard]]
constexpr auto
305 [[nodiscard]]
constexpr auto
320 template <
class Lhs_T,
class Rhs_T>
323 constexpr ge_ (
const Lhs_T& lhs = {},
const Rhs_T& rhs = {})
324 : lhs_{ lhs }, rhs_{ rhs }, value_{ [&] {
325 using std::operator>=;
328#pragma GCC diagnostic push
329#pragma GCC diagnostic ignored "-Wconversion"
330#pragma GCC diagnostic ignored "-Wdouble-promotion"
331#pragma GCC diagnostic ignored "-Wsign-compare"
332#if defined(__clang__)
333#pragma clang diagnostic ignored "-Wimplicit-int-float-conversion"
334#pragma clang diagnostic ignored "-Wpedantic"
337 if constexpr (type_traits::has_value_v<Lhs_T>
338 and type_traits::has_value_v<Rhs_T>)
340 return Lhs_T::value >= Rhs_T::value;
344 return get (lhs_) >= get (rhs_);
347#pragma GCC diagnostic pop
353 [[nodiscard]]
constexpr
354 operator bool ()
const
358 [[nodiscard]]
constexpr auto
363 [[nodiscard]]
constexpr auto
378 template <
class Lhs_T,
class Rhs_T>
381 constexpr lt_ (
const Lhs_T& lhs = {},
const Rhs_T& rhs = {})
382 : lhs_{ lhs }, rhs_{ rhs }, value_{ [&] {
383 using std::operator<;
386#pragma GCC diagnostic push
387#pragma GCC diagnostic ignored "-Wconversion"
388#pragma GCC diagnostic ignored "-Wdouble-promotion"
389#pragma GCC diagnostic ignored "-Wsign-compare"
390#if defined(__clang__)
391#pragma clang diagnostic ignored "-Wimplicit-int-float-conversion"
392#pragma clang diagnostic ignored "-Wpedantic"
395 if constexpr (type_traits::has_value_v<Lhs_T>
396 and type_traits::has_value_v<Rhs_T>)
398 return Lhs_T::value < Rhs_T::value;
402 return get (lhs_) < get (rhs_);
405#pragma GCC diagnostic pop
411 [[nodiscard]]
constexpr
412 operator bool ()
const
416 [[nodiscard]]
constexpr auto
421 [[nodiscard]]
constexpr auto
437 template <
class Lhs_T,
class Rhs_T>
440 constexpr le_ (
const Lhs_T& lhs = {},
const Rhs_T& rhs = {})
441 : lhs_{ lhs }, rhs_{ rhs }, value_{ [&] {
442 using std::operator<=;
445#pragma GCC diagnostic push
446#pragma GCC diagnostic ignored "-Wconversion"
447#pragma GCC diagnostic ignored "-Wdouble-promotion"
448#pragma GCC diagnostic ignored "-Wsign-compare"
449#if defined(__clang__)
450#pragma clang diagnostic ignored "-Wimplicit-int-float-conversion"
451#pragma clang diagnostic ignored "-Wpedantic"
454 if constexpr (type_traits::has_value_v<Lhs_T>
455 and type_traits::has_value_v<Rhs_T>)
457 return Lhs_T::value <= Rhs_T::value;
461 return get (lhs_) <= get (rhs_);
464#pragma GCC diagnostic pop
470 [[nodiscard]]
constexpr
471 operator bool ()
const
476 [[nodiscard]]
constexpr auto
482 [[nodiscard]]
constexpr auto
497 template <
class Lhs_T,
class Rhs_T>
500 constexpr and_ (
const Lhs_T& lhs = {},
const Rhs_T& rhs = {})
501 : lhs_{ lhs }, rhs_{ rhs },
502 value_{ static_cast<bool> (lhs) and static_cast<bool> (rhs) }
506 [[nodiscard]]
constexpr
507 operator bool ()
const
512 [[nodiscard]]
constexpr auto
518 [[nodiscard]]
constexpr auto
533 template <
class Lhs_T,
class Rhs_T>
536 constexpr or_ (
const Lhs_T& lhs = {},
const Rhs_T& rhs = {})
537 : lhs_{ lhs }, rhs_{ rhs },
538 value_{ static_cast<bool> (lhs) or static_cast<bool> (rhs) }
542 [[nodiscard]]
constexpr
543 operator bool ()
const
548 [[nodiscard]]
constexpr auto
554 [[nodiscard]]
constexpr auto
572 explicit constexpr not_ (
const T& t = {})
573 : t_{ t }, value_{ not static_cast<bool> (t) }
577 [[nodiscard]]
constexpr
578 operator bool ()
const
583 [[nodiscard]]
constexpr auto
593#if defined(__cpp_exceptions)
598 template <
class Callable_T,
class Exception_T =
void>
601 constexpr explicit throws_ (
const Callable_T& func)
607 catch (
const Exception_T&)
620 [[nodiscard]]
constexpr
621 operator bool ()
const
633 template <
class Callable_T>
636 constexpr explicit throws_ (
const Callable_T& func)
651 [[nodiscard]]
constexpr
652 operator bool ()
const
664 template <
class Callable_T>
667 constexpr explicit nothrow_ (
const Callable_T& func)
682 [[nodiscard]]
constexpr
683 operator bool ()
const
709 operator<< (
const T& msg);
711 [[nodiscard]]
constexpr bool
726 std::string message_{};
734 template <
class Expr_T>
739 const Expr_T& expr,
bool abort,
745 const Expr_T expr_{};
755#pragma GCC diagnostic pop
Base class for a deferred reporter, that collects the messages into a string.
constexpr bool value() const
Class template for a deferred reporter specific to an expression.
Local implementation of the std::source_location.
constexpr auto get_impl(const T &t, int) -> decltype(t.get())
Generic getter implementation. If the type has a get() method, call it. It is recommended for custom ...
constexpr auto get(const T &t)
Generic getter, calling the getter implementation.
constexpr auto abs(const T t) -> T
Generic absolute of any value.
constexpr auto min_value(const T &lhs, const T &rhs) -> const T &
Generic minimum of two values.
static constexpr auto has_value_v
constexpr auto lhs() const
constexpr and_(const Lhs_T &lhs={}, const Rhs_T &rhs={})
constexpr auto rhs() const
An object used to pass assertion parameters to the evaluator.
reflection::source_location location
constexpr auto rhs() const
constexpr eq_(const Lhs_T &lhs={}, const Rhs_T &rhs={})
constexpr auto lhs() const
Greater than or equal comparator.
constexpr auto rhs() const
constexpr ge_(const Lhs_T &lhs={}, const Rhs_T &rhs={})
constexpr auto lhs() const
constexpr gt_(const Lhs_T &lhs={}, const Rhs_T &rhs={})
constexpr auto rhs() const
constexpr auto lhs() const
Less than or equal comparator.
constexpr auto lhs() const
constexpr auto rhs() const
constexpr le_(const Lhs_T &lhs={}, const Rhs_T &rhs={})
constexpr auto rhs() const
constexpr auto lhs() const
constexpr lt_(const Lhs_T &lhs={}, const Rhs_T &rhs={})
constexpr ne_(const Lhs_T &lhs={}, const Rhs_T &rhs={})
constexpr auto lhs() const
constexpr auto rhs() const
constexpr auto value() const
constexpr not_(const T &t={})
Operator to check if the expression does not throw any exception.
constexpr nothrow_(const Callable_T &func)
constexpr auto lhs() const
constexpr auto rhs() const
constexpr or_(const Lhs_T &lhs={}, const Rhs_T &rhs={})
constexpr throws_(const Callable_T &func)
Operator to check if the expression throws a specific exception.
constexpr throws_(const Callable_T &func)
Empty base class of all operators.