Skip to main content

compare_op Struct Template

Relational comparator struct template. More...

Declaration​

template <class Lhs_T, class Rhs_T, class Compare_T>
struct micro_os_plus::micro_test_plus::detail::compare_op<Lhs_T, Rhs_T, Compare_T> { ... }

Included Headers​

Base struct​

structbinary_op<Lhs_T, Rhs_T>

Common base struct template for binary comparators. More...

Public Member Typedefs Index​

template <class Lhs_T, class Rhs_T, class Compare_T>
usingop_type = op

Marker identifying the framework expression types. More...

Public Constructors Index​

template <class L, class R>
constexprcompare_op (L &&lhs, R &&rhs, Compare_T)

Constructs a comparator for the given operands. More...

Public Operators Index​

template <class Lhs_T, class Rhs_T, class Compare_T>
constexproperator bool () const

Conversion operator to boolean. More...

Public Member Functions Index​

template <class Lhs_T, class Rhs_T, class Compare_T>
constexpr auto lhs (void) const -> decltype(auto)

Retrieves the left-hand operand. More...

template <class Lhs_T, class Rhs_T, class Compare_T>
constexpr auto rhs (void) const -> decltype(auto)

Retrieves the right-hand operand. More...

Private Member Attributes Index​

template <class Lhs_T, class Rhs_T, class Compare_T>
Lhs_Tlhs_

Stores the left-hand operand. More...

template <class Lhs_T, class Rhs_T, class Compare_T>
Rhs_Trhs_

Stores the right-hand operand. More...

template <class Lhs_T, class Rhs_T, class Compare_T>
const boolvalue_ {}

Stores the result of the comparison. More...

Description​

Relational comparator struct template.

Derived from binary_op, this struct compares the left-hand operand with the right-hand operand, using the operator defined by the tag Compare_T (equal_to, not_equal_to, greater, greater_equal, less, or less_equal). It is used within test expressions to provide human-readable relational checks, with the actual and expected values, and the symbol of the tag, reported upon failure.

The tag is passed as an empty constructor argument, so that all three template arguments are deduced, for example compare_op{ lhs, rhs, equal_to{} }. A factory function would do the same, but at -O0 it adds one function per instantiation.

It is also public, as extension::compare_op, so that the applications can define their own comparisons with their own tags. A tag is an empty struct with:

  • a static constexpr const char* symbol, written between the operands in the failure reports, with the surrounding spaces (for example " divides ");
  • a static apply (lhs, rhs) member function template, which receives the unwrapped operands (the values of the to_* wrappers and of the literals) and returns the result as bool;
  • optionally, a static constexpr bool within_tolerance_result; when present, and an operand is a floating-point wrapper (see extension::has_epsilon), the operands within the tolerance give this result, as for the built-in comparators; when absent, the tolerance is ignored.

The operands are reported as the built-in comparators report them: the stored operands are prepared by as_operand(), so the C strings are written quoted, and the arrays as ranges; the tag still receives the operands as they were passed, without this conversion.

The temporaries are moved into the comparator, and the named operands are copied (see stored_operand_t), so a comparator built in a function from its const& parameters can be returned from it.

Template Parameters
Lhs_T

The type of the stored left-hand operand, either the operand type, or a const reference to it.

Rhs_T

The type of the stored right-hand operand, either the operand type, or a const reference to it.

Compare_T

The tag that defines the comparison. It is stateless, with a static symbol and a static apply(), so a parameter, such as a tolerance, is passed as an operand, usually the right one, and reported with the operands.

Definition at line 886 of file detail.h.

Public Member Typedefs​

op_type​

template <class Lhs_T, class Rhs_T, class Compare_T>
using micro_os_plus::micro_test_plus::detail::op::op_type = op

Marker identifying the framework expression types.

Detected by the extension::is_op concept, and inherited by all types derived from op.

Definition at line 128 of file extension.h.

128 using op_type = op;

Public Constructors​

compare_op()​

template <class L, class R>
micro_os_plus::micro_test_plus::detail::compare_op< Lhs_T, Rhs_T, Compare_T >::compare_op (L && lhs, R && rhs, Compare_T)
constexpr

Constructs a comparator for the given operands.

The result is computed from the arguments, before they are forwarded to the base. The tag argument is used only to deduce Compare_T.

Template Parameters
L

The type of the left-hand operand argument.

R

The type of the right-hand operand argument.

Parameters
lhs

The left-hand operand.

rhs

The right-hand operand.

Evaluates the comparison inside an immediately invoked lambda, which converts the result of Compare_T::apply() to bool, and passes it to the binary_op base class constructor:

  • for the framework constants with static value members (the numeric literals), the two values are compared directly;
  • if at least one operand is a framework floating-point wrapper with an epsilon member, and the tag defines a within_tolerance_result (all the built-in tags do), operands within the tolerance give this result; otherwise the unwrapped values are compared; the tags of the application without it ignore the tolerance;
  • for all other types, the framework wrappers are unwrapped, and the values, including the types of the application, are compared as they are.

Declaration at line 905 of file detail.h, definition at line 855 of file detail-inlines.h.

857 R&& rhs,
858 Compare_T)
859 : binary_op<Lhs_T, Rhs_T>{ detail::as_operand (std::forward<L> (lhs)),
860 detail::as_operand (std::forward<R> (rhs)),
861 [&] () -> bool
862 {
863 // The result is computed before the arguments are moved, since
864 // the base constructor is entered only after all its arguments
865 // are evaluated.
866#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_DEPRECATED_ENABLED)
867 using lhs_type = std::remove_cvref_t<L>;
868 using rhs_type = std::remove_cvref_t<R>;
869
870 if constexpr (detail::has_value<lhs_type>
872 {
873 return Compare_T::apply (lhs_type::value, rhs_type::value);
874 }
875 else if constexpr ((extension::has_epsilon<lhs_type>
877 and requires {
878 Compare_T::within_tolerance_result;
879 })
880 {
882 ? Compare_T::within_tolerance_result
883 : Compare_T::apply (detail::unwrap (lhs),
885 }
886 else
887#endif // defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_DEPRECATED_ENABLED)
888 {
889 return Compare_T::apply (detail::unwrap (lhs),
891 }
892 }() }
893 {

References micro_os_plus::micro_test_plus::detail::binary_op< Lhs_T, Rhs_T >::binary_op, micro_os_plus::micro_test_plus::detail::as_operand, micro_os_plus::micro_test_plus::detail::binary_op< Lhs_T, Rhs_T >::lhs, 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.

Public Operators​

operator bool()​

template <class Lhs_T, class Rhs_T, class Compare_T>
micro_os_plus::micro_test_plus::detail::binary_op< Lhs_T, Rhs_T >::operator bool ()
nodiscard constexpr

Conversion operator to boolean.

Parameters

None.

Returns

The result of the comparison.

Returns the pre-computed boolean result stored by the derived comparator's constructor.

Declaration at line 370 of file detail.h, definition at line 168 of file detail-inlines.h.

168 operator bool () const
169 {
170 return value_;
171 }

References micro_os_plus::micro_test_plus::detail::binary_op< Lhs_T, Rhs_T >::binary_op and micro_os_plus::micro_test_plus::detail::binary_op< Lhs_T, Rhs_T >::value_.

Public Member Functions​

lhs()​

template <class Lhs_T, class Rhs_T, class Compare_T>
decltype(auto) constexpr micro_os_plus::micro_test_plus::detail::binary_op< Lhs_T, Rhs_T >::lhs (void)
nodiscard constexpr

rhs()​

template <class Lhs_T, class Rhs_T, class Compare_T>
decltype(auto) constexpr micro_os_plus::micro_test_plus::detail::binary_op< Lhs_T, Rhs_T >::rhs (void)
nodiscard constexpr

Private Member Attributes​

lhs_​

template <class Lhs_T, class Rhs_T, class Compare_T>
Lhs_T micro_os_plus::micro_test_plus::detail::binary_op< Lhs_T, Rhs_T >::lhs_

Stores the left-hand operand.

A value, moved from a temporary or copied from a named operand, or, for a named operand that cannot be copied, a const reference to it (see stored_operand_t). It is not const, so that a temporary expression can be moved into an enclosing one.

Definition at line 410 of file detail.h.

410 Lhs_T lhs_;

Referenced by micro_os_plus::micro_test_plus::detail::binary_op< Lhs_T, Rhs_T >::binary_op and micro_os_plus::micro_test_plus::detail::binary_op< Lhs_T, Rhs_T >::lhs.

rhs_​

template <class Lhs_T, class Rhs_T, class Compare_T>
Rhs_T micro_os_plus::micro_test_plus::detail::binary_op< Lhs_T, Rhs_T >::rhs_

Stores the right-hand operand.

Stored as the left-hand operand is.

Definition at line 418 of file detail.h.

418 Rhs_T rhs_;

Referenced by micro_os_plus::micro_test_plus::detail::binary_op< Lhs_T, Rhs_T >::binary_op and micro_os_plus::micro_test_plus::detail::binary_op< Lhs_T, Rhs_T >::rhs.

value_​

template <class Lhs_T, class Rhs_T, class Compare_T>
const bool micro_os_plus::micro_test_plus::detail::binary_op< Lhs_T, Rhs_T >::value_ {}

Stores the result of the comparison.

Computed once, by the derived comparator constructor.

Definition at line 426 of file detail.h.

426 const bool value_{};

Referenced by micro_os_plus::micro_test_plus::detail::binary_op< Lhs_T, Rhs_T >::binary_op and micro_os_plus::micro_test_plus::detail::binary_op< Lhs_T, Rhs_T >::operator bool.


The documentation for this struct was generated from the following files:


Generated via doxygen2docusaurus 2.2.8 by Doxygen 1.18.0.