Skip to main content

eq_ Struct Template

Equality comparator struct template. More...

Declaration

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

Included Headers

Base struct

structbinary_op_<Lhs_T, Rhs_T>

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

Public Constructors Index

template <class Lhs_T, class Rhs_T>
constexpreq_ (const Lhs_T &lhs={}, const Rhs_T &rhs={})

Constructs an equality comparator for the given operands. More...

Public Operators Index

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

Conversion operator to boolean. More...

Public Member Functions Index

template <class Lhs_T, class Rhs_T>
constexpr autolhs (void) const

Retrieves the left-hand operand. More...

template <class Lhs_T, class Rhs_T>
constexpr autorhs (void) const

Retrieves the right-hand operand. More...

Private Member Attributes Index

template <class Lhs_T, class Rhs_T>
const Lhs_Tlhs_ {}

Stores the left-hand operand. More...

template <class Lhs_T, class Rhs_T>
const Rhs_Trhs_ {}

Stores the right-hand operand. More...

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

Stores the result of the comparison. More...

Description

Equality comparator struct template.

Derived from binary_op_, this struct checks whether the left-hand operand is equal to the right-hand operand. It is used within test expressions to provide human-readable equality assertions with enhanced reporting of the actual and expected values upon failure.

Template Parameters
Lhs_T

The type of the left-hand operand.

Rhs_T

The type of the right-hand operand.

Definition at line 314 of file detail.h.

Public Constructors

eq_()

template <class Lhs_T, class Rhs_T>
micro_os_plus::micro_test_plus::detail::eq_< Lhs_T, Rhs_T >::eq_ (const Lhs_T & lhs={}, const Rhs_T & rhs={})
constexpr

Constructs an equality comparator for the given operands.

Parameters
lhs

The left-hand operand.

rhs

The right-hand operand.

Evaluates the equality of lhs and rhs inside an immediately invoked lambda and passes the boolean result to the binary_op_ base class constructor. Supports types with static value members, types with an epsilon precision member, and generic types.

Declaration at line 322 of file detail.h, definition at line 191 of file detail-inlines.h.

191 constexpr eq_<Lhs_T, Rhs_T>::eq_ (const Lhs_T& lhs, const Rhs_T& rhs)
192 : binary_op_<Lhs_T, Rhs_T>{ lhs, rhs, [&]
193 {
194 // This lambda is called in the constructor to evaluate the
195 // comparison. Its result is implicitly converted to bool via
196 // the operator bool() of whatever type the branch returns.
197 // This is intentional: all result types (integral_constant,
198 // comparator objects, plain bool) define operator bool().
199 using std::operator==;
200 using std::operator<;
201
202#if defined(__GNUC__)
203#pragma GCC diagnostic push
204
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"
212#endif // defined(__clang__)
213#endif // defined(__GNUC__)
214
217 {
218 // If both types have values (like numeric constants),
219 // compare them directly.
220 return Lhs_T::value == Rhs_T::value;
221 }
222 else if constexpr (type_traits::has_epsilon<Lhs_T>
224 {
225 // If both values have precision, compare them using
226 // the smallest precision.
227 return math::abs (get (lhs) - get (rhs))
228 < math::min_value (lhs.epsilon, rhs.epsilon);
229 }
230 else if constexpr (type_traits::has_epsilon<Lhs_T>)
231 {
232 // If only the left operand has precision, use it.
233 return math::abs (get (lhs) - get (rhs)) < lhs.epsilon;
234 }
235 else if constexpr (type_traits::has_epsilon<Rhs_T>)
236 {
237 // If only the right operand has precision, use it.
238 return math::abs (get (lhs) - get (rhs)) < rhs.epsilon;
239 }
240 else
241 {
242 // Call the generic getters, which might
243 // either call the type get() or return the value.
244 return get (lhs) == get (rhs);
245 }
246
247#if defined(__GNUC__)
248#pragma GCC diagnostic pop
249#endif // defined(__GNUC__)
250 }() }
251 {
252 }

References micro_os_plus::micro_test_plus::detail::binary_op_< Lhs_T, Rhs_T >::binary_op_, micro_os_plus::micro_test_plus::math::abs, micro_os_plus::micro_test_plus::detail::get, micro_os_plus::micro_test_plus::detail::binary_op_< Lhs_T, Rhs_T >::lhs, micro_os_plus::micro_test_plus::math::min_value and micro_os_plus::micro_test_plus::detail::binary_op_< Lhs_T, Rhs_T >::rhs.

Public Operators

operator bool()

template <class Lhs_T, class Rhs_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 252 of file detail.h, definition at line 150 of file detail-inlines.h.

150 operator bool () const
151 {
152 return value_;
153 }

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>
auto micro_os_plus::micro_test_plus::detail::binary_op_< Lhs_T, Rhs_T >::lhs (void)
nodiscard constexpr

Retrieves the left-hand operand.

Parameters

None.

Returns

The extracted left-hand operand.

Returns the value of the left-hand operand, applying the generic getter to ensure correct extraction for both custom and standard types.

Declaration at line 262 of file detail.h, definition at line 163 of file detail-inlines.h.

164 {
165 return get (lhs_);
166 }

References micro_os_plus::micro_test_plus::detail::get and micro_os_plus::micro_test_plus::detail::binary_op_< Lhs_T, Rhs_T >::lhs_.

Referenced by micro_os_plus::micro_test_plus::detail::and_< Lhs_T, Rhs_T >::and_, micro_os_plus::micro_test_plus::detail::binary_op_< Lhs_T, Rhs_T >::binary_op_, 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::or_< Lhs_T, Rhs_T >::or_, 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::detail::expression_formatter::operator<<.

rhs()

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

Retrieves the right-hand operand.

Parameters

None.

Returns

The extracted right-hand operand.

Returns the value of the right-hand operand, applying the generic getter to ensure correct extraction for both custom and standard types.

Declaration at line 272 of file detail.h, definition at line 176 of file detail-inlines.h.

177 {
178 return get (rhs_);
179 }

References micro_os_plus::micro_test_plus::detail::get and micro_os_plus::micro_test_plus::detail::binary_op_< Lhs_T, Rhs_T >::rhs_.

Referenced by micro_os_plus::micro_test_plus::detail::and_< Lhs_T, Rhs_T >::and_, micro_os_plus::micro_test_plus::detail::binary_op_< Lhs_T, Rhs_T >::binary_op_, 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::or_< Lhs_T, Rhs_T >::or_, 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::detail::expression_formatter::operator<<.

Private Member Attributes

lhs_

template <class Lhs_T, class Rhs_T>
const Lhs_T micro_os_plus::micro_test_plus::detail::binary_op_< Lhs_T, Rhs_T >::lhs_ {}

Stores the left-hand operand.

info

Operands are stored by value; passing a large container will copy it into this member.

Definition at line 281 of file detail.h.

281 const 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>
const Rhs_T micro_os_plus::micro_test_plus::detail::binary_op_< Lhs_T, Rhs_T >::rhs_ {}

Stores the right-hand operand.

info

Operands are stored by value; passing a large container will copy it into this member.

Definition at line 289 of file detail.h.

289 const 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>
const bool micro_os_plus::micro_test_plus::detail::binary_op_< Lhs_T, Rhs_T >::value_ {}

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


Generated via doxygen2docusaurus 2.2.2 by Doxygen 1.17.0.