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

structop

Empty base struct for all operator types. 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...

Public 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 equality comparison. More...

Description

Equality comparator struct template.

Template Parameters
Lhs_T

The type of the left-hand operand.

Rhs_T

The type of the right-hand operand.

The eq_ struct template provides a type-safe mechanism for evaluating equality between two operands within the framework.

This comparator supports a variety of operand types, including those with static values, types with precision (epsilon), and generic types. For types with static values, the comparison is performed directly. For types supporting precision, the comparison accounts for the smallest epsilon to ensure accuracy, particularly for floating-point types. For all other types, the generic getter is used to retrieve and compare the values.

The implementation is optimised for use in embedded environments and supports both compile-time and run-time evaluation.

All definitions are intended for internal use within the framework and are implemented in the include/micro-os-plus/micro-test-plus folder to maintain a structured and modular codebase.

Definition at line 259 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={})
inline constexpr

Constructs an equality comparator for the given operands.

Parameters
lhs

The left-hand operand.

rhs

The right-hand operand.

Evaluates the equality of the provided operands at construction, supporting static values, types with precision, and generic types. The result is stored in the value_ member for efficient access.

Definition at line 272 of file detail.h.

272 constexpr eq_ (const Lhs_T& lhs = {}, const Rhs_T& rhs = {})
273 : lhs_{ lhs }, rhs_{ rhs }, value_{
274 [&]
275 {
276 // This lambda is called in the constructor to
277 // evaluate the comparison.
278 using std::operator==;
279 using std::operator<;
280
281#if defined(__GNUC__)
282#pragma GCC diagnostic push
283#pragma GCC diagnostic ignored "-Wfloat-equal"
284#pragma GCC diagnostic ignored "-Wconversion"
285#pragma GCC diagnostic ignored "-Wdouble-promotion"
286#pragma GCC diagnostic ignored "-Wsign-compare"
287#if defined(__clang__)
288#pragma clang diagnostic ignored "-Wimplicit-int-float-conversion"
289#pragma clang diagnostic ignored "-Wpedantic"
290#endif
291#endif
294 {
295 // If both types have values (like numeric constants),
296 // compare them directly.
297 return Lhs_T::value == Rhs_T::value;
298 }
299 else if constexpr (type_traits::has_epsilon_v<Lhs_T>
301 {
302 // If both values have precision, compare them using
303 // the smalles precision.
304 return math::abs (get (lhs) - get (rhs))
305 < math::min_value (Lhs_T::epsilon,
306 Rhs_T::epsilon);
307 }
308 else if constexpr (type_traits::has_epsilon_v<Lhs_T>)
309 {
310 // If only the left operand has precision, use it.
311 return math::abs (get (lhs) - get (rhs))
312 < Lhs_T::epsilon;
313 }
314 else if constexpr (type_traits::has_epsilon_v<Rhs_T>)
315 {
316 // If only the right operand has precision, use it.
317 return math::abs (get (lhs) - get (rhs))
318 < Rhs_T::epsilon;
319 }
320 else
321 {
322 // Call the generic getters, which might
323 // either call the type get() or return the value.
324 return get (lhs) == get (rhs);
325 }
326#if defined(__GNUC__)
327#pragma GCC diagnostic pop
328#endif
329 }()
330 }
331 {
332 }

Reference micro_os_plus::micro_test_plus::detail::eq_< Lhs_T, Rhs_T >::lhs.

Public Operators

operator bool()

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

Conversion operator to boolean.

Parameters

None.

Return Values
true

The operands are considered equal.

false

The operands are not equal.

Returns the result of the equality comparison.

Definition at line 346 of file detail.h.

346 operator bool () const
347 {
348 return value_;
349 }

Reference micro_os_plus::micro_test_plus::detail::eq_< Lhs_T, Rhs_T >::value_.

Public Member Functions

lhs()

template <class Lhs_T, class Rhs_T>
auto micro_os_plus::micro_test_plus::detail::eq_< Lhs_T, Rhs_T >::lhs (void)
inline 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.

Definition at line 364 of file detail.h.

364 lhs (void) const
365 {
366 return get (lhs_);
367 }

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

Referenced by micro_os_plus::micro_test_plus::detail::eq_< Lhs_T, Rhs_T >::eq_ and micro_os_plus::micro_test_plus::test_reporter::operator<<.

rhs()

template <class Lhs_T, class Rhs_T>
auto micro_os_plus::micro_test_plus::detail::eq_< Lhs_T, Rhs_T >::rhs (void)
inline 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.

Definition at line 382 of file detail.h.

382 rhs (void) const
383 {
384 return get (rhs_);
385 }

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

Referenced by micro_os_plus::micro_test_plus::test_reporter::operator<<.

Public Member Attributes

lhs_

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

Stores the left-hand operand.

Definition at line 390 of file detail.h.

390 const Lhs_T lhs_{};

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

rhs_

template <class Lhs_T, class Rhs_T>
const Rhs_T micro_os_plus::micro_test_plus::detail::eq_< Lhs_T, Rhs_T >::rhs_ {}

Stores the right-hand operand.

Definition at line 395 of file detail.h.

395 const Rhs_T rhs_{};

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

value_

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

Stores the result of the equality comparison.

Definition at line 400 of file detail.h.

400 const bool value_{};

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


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


Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.14.0.