Skip to main content

The Operators Reference

Overloaded operators for expressive test comparisons. More...

Functions Index

constexpr autooperator and (const Lhs_T &lhs, const Rhs_T &rhs)

Logical && (and) operator. Matches only if at least one operand is of local type (derived from local op). More...

constexpr autooperator not (const T &t)

Logical ! (not) operator. Matches only if the operand is of local type (derived from local op). More...

constexpr autooperator or (const Lhs_T &lhs, const Rhs_T &rhs)

Logical || (or) operator. Matches only if at least one operand is of local type (derived from local op). More...

constexpr autooperator!= (const Lhs_T &lhs, const Rhs_T &rhs)

Non-equality operator for custom types. Matches only if at least one operand is of local type. More...

constexpr autooperator< (const Lhs_T &lhs, const Rhs_T &rhs)

Less than operator. Matches only if at least one operand is of local type (derived from local op). More...

constexpr autooperator<= (const Lhs_T &lhs, const Rhs_T &rhs)

Less than or equal operator. Matches only if at least one operand is of local type (derived from local op). More...

constexpr autooperator== (const Lhs_T &lhs, const Rhs_T &rhs)

Equality operator for custom types. Matches only if at least one operand is of local type. More...

constexpr autooperator> (const Lhs_T &lhs, const Rhs_T &rhs)

Greater than operator. Matches only if at least one operand is of local type (derived from local op). More...

constexpr autooperator>= (const Lhs_T &lhs, const Rhs_T &rhs)

Greater than or equal operator. Matches only if at least one operand is of local type (derived from local op). More...

Description

The µTest++ framework provides overloaded comparison and logical operators to enable expressive and type-safe test assertions. These operators—such as ==, !=, <, >, <=, and >=—are defined within the dedicated micro_test_plus::operators namespace to avoid conflicts with application-defined operators.

For standard values, the default operators are used, ensuring correct comparisons. However, when using the specialised µTest++ operators with typed operands, failed checks will display both the actual and expected values, greatly improving the clarity of test reports.

These operators are restricted to operands derived from the local detail::op type. For constant values, this is achieved using provided literals (e.g., 1_i), while dynamic values can be wrapped using casts such as mt::to_i{expression}.

Logical operators (&&, ||, !) are also supported and provide enhanced functionality when used with typed operands, allowing for the composition of complex test conditions in a natural and readable manner.

Examples
 mt::test_case ("Operators", [] {
  using namespace micro_test_plus::operators;
  using namespace micro_test_plus::literals;
 
  mt::expect (compute_answer () == 42_i) << "answer is 42 (with literal)";
  mt::expect (mt::to_i {compute_answer ()} == 42) << "answer is 42 (with
 cast)"; mt::expect (compute_answer () != 43_i) << "answer is not 43";
  mt::expect (compute_answer () < 43_i) << "answer is < 43";
  mt::expect (compute_answer () <= 43_i) << "answer is <= 42";
  mt::expect (compute_answer () > 41_i) << "answer is > 43";
  mt::expect (compute_answer () >= 42_i) << "answer is >= 42";
 });

Logical operators

Logical operators may be used in the same way as standard operators, with enhanced reporting available when used with typed operands.

Example
 mt::expect (compute_answer () == 42_i && compute_float () == 42.0_f);

Functions

operator and()

template <class Lhs_T, class Rhs_T, type_traits::requires_t< type_traits::is_op_v< Lhs_T > or type_traits::is_op_v< Rhs_T > > = 0>
auto micro_os_plus::micro_test_plus::operators::operator and (const Lhs_T & lhs, const Rhs_T & rhs)
nodiscardconstexpr

Logical && (and) operator. Matches only if at least one operand is of local type (derived from local op).

Template Parameters
Lhs_TType of the left hand side operand.
Rhs_TType of the right hand side operand.
Parameters
[in] lhsLeft hand side operand.
[in] rhsRight hand side operand.
Returns

A logical conjunction object that evaluates to true if both operands are true.

This overload of the logical && (and) operator enables conjunction between two operands, where at least one is a local type derived from the local op base. It constructs a logical conjunction object that can be used within the µTest++ framework to assert that both operands evaluate to true. This operator is intended for use with the framework's strongly-typed constants, wrappers, or other custom types, ensuring type-safe and expressive test assertions.

Definition at line 431 of file operators.h.

operator not()

template <class T, type_traits::requires_t< type_traits::is_op_v< T > > = 0>
auto micro_os_plus::micro_test_plus::operators::operator not (const T & t)
nodiscardconstexpr

Logical ! (not) operator. Matches only if the operand is of local type (derived from local op).

Template Parameters
TType of the operand, constrained to types derived from the local op base.
Parameters
[in] tOperand to be logically negated.
Returns

A logical negator object that evaluates to true if the operand is false.

This overload of the logical ! (not) operator enables logical negation of an operand, provided it is a local type derived from the local op base. It constructs a logical negator object that can be used within the µTest++ framework to assert that a given condition is false. This operator is intended for use with the framework's strongly-typed constants, wrappers, or other custom types, ensuring type-safe and expressive test assertions.

Definition at line 491 of file operators.h.

operator or()

template <class Lhs_T, class Rhs_T, type_traits::requires_t< type_traits::is_op_v< Lhs_T > or type_traits::is_op_v< Rhs_T > > = 0>
auto micro_os_plus::micro_test_plus::operators::operator or (const Lhs_T & lhs, const Rhs_T & rhs)
nodiscardconstexpr

Logical || (or) operator. Matches only if at least one operand is of local type (derived from local op).

Template Parameters
Lhs_TType of the left hand side operand.
Rhs_TType of the right hand side operand.
Parameters
[in] lhsLeft hand side operand.
[in] rhsRight hand side operand.
Returns

A logical disjunction object that evaluates to true if at least one operand is true.

This overload of the logical || (or) operator enables disjunction between two operands, where at least one is a local type derived from the local op base. It constructs a logical disjunction object that can be used within the µTest++ framework to assert that at least one operand evaluates to true. This operator is intended for use with the framework's strongly-typed constants, wrappers, or other custom types, ensuring type-safe and expressive test assertions.

Definition at line 463 of file operators.h.

operator!=()

template <class Lhs_T, class Rhs_T, type_traits::requires_t< type_traits::is_op_v< Lhs_T > or type_traits::is_op_v< Rhs_T > > = 0>
auto micro_os_plus::micro_test_plus::operators::operator!= (const Lhs_T & lhs, const Rhs_T & rhs)
nodiscardconstexpr

Non-equality operator for custom types. Matches only if at least one operand is of local type.

Template Parameters
Lhs_TType of the left hand side operand.
Rhs_TType of the right hand side operand.
Parameters
[in] lhsLeft hand side operand.
[in] rhsRight hand side operand.
Returns

A comparator object that evaluates to true if the operands are not equal.

This overload of the non-equality operator enables comparison between two operands, where at least one is a local type derived from the local op base. It constructs a comparator object that can be used within the µTest++ framework to assert that the operands are not equal. This operator is intended for use with the framework's strongly-typed constants, wrappers, or other custom types, ensuring type-safe and expressive test assertions.

Definition at line 269 of file operators.h.

operator<()

template <class Lhs_T, class Rhs_T, type_traits::requires_t< type_traits::is_op_v< Lhs_T > or type_traits::is_op_v< Rhs_T > > = 0>
auto micro_os_plus::micro_test_plus::operators::operator< (const Lhs_T & lhs, const Rhs_T & rhs)
nodiscardconstexpr

Less than operator. Matches only if at least one operand is of local type (derived from local op).

Template Parameters
Lhs_TType of the left hand side operand.
Rhs_TType of the right hand side operand.
Parameters
[in] lhsLeft hand side operand.
[in] rhsRight hand side operand.
Returns

A comparator object that evaluates to true if the left hand side operand is less than the right hand side operand.

This overload of the less than operator enables comparison between two operands, where at least one is a local type derived from the local op base. It constructs a comparator object that can be used within the µTest++ framework to assert that the left hand side operand is less than the right hand side operand. This operator is intended for use with the framework's strongly-typed constants, wrappers, or other custom types, ensuring type-safe and expressive test assertions.

Definition at line 365 of file operators.h.

operator<=()

template <class Lhs_T, class Rhs_T, type_traits::requires_t< type_traits::is_op_v< Lhs_T > or type_traits::is_op_v< Rhs_T > > = 0>
auto micro_os_plus::micro_test_plus::operators::operator<= (const Lhs_T & lhs, const Rhs_T & rhs)
nodiscardconstexpr

Less than or equal operator. Matches only if at least one operand is of local type (derived from local op).

Template Parameters
Lhs_TType of the left hand side operand.
Rhs_TType of the right hand side operand.
Parameters
[in] lhsLeft hand side operand.
[in] rhsRight hand side operand.
Returns

A comparator object that evaluates to true if the left hand side operand is less than or equal to the right hand side operand.

This overload of the less than or equal operator enables comparison between two operands, where at least one is a local type derived from the local op base. It constructs a comparator object that can be used within the µTest++ framework to assert that the left hand side operand is less than or equal to the right hand side operand. This operator is intended for use with the framework's strongly-typed constants, wrappers, or other custom types, ensuring type-safe and expressive test assertions.

Definition at line 398 of file operators.h.

operator==()

template <class Lhs_T, class Rhs_T, type_traits::requires_t< type_traits::is_op_v< Lhs_T > or type_traits::is_op_v< Rhs_T > > = 0>
auto micro_os_plus::micro_test_plus::operators::operator== (const Lhs_T & lhs, const Rhs_T & rhs)
nodiscardconstexpr

Equality operator for custom types. Matches only if at least one operand is of local type.

Template Parameters
Lhs_TType of the left hand side operand.
Rhs_TType of the right hand side operand.
Parameters
[in] lhsLeft hand side operand.
[in] rhsRight hand side operand.
Returns

A comparator object that evaluates to true if the operands are equal.

This overload of the equality operator enables comparison between two operands, where at least one is a local type derived from the local op base. It constructs a comparator object that can be used within the µTest++ framework to assert that the operands are equal. This operator is intended for use with the framework's strongly-typed constants, wrappers, or other custom types, ensuring type-safe and expressive test assertions.

Definition at line 237 of file operators.h.

operator>()

template <class Lhs_T, class Rhs_T, type_traits::requires_t< type_traits::is_op_v< Lhs_T > or type_traits::is_op_v< Rhs_T > > = 0>
auto micro_os_plus::micro_test_plus::operators::operator> (const Lhs_T & lhs, const Rhs_T & rhs)
nodiscardconstexpr

Greater than operator. Matches only if at least one operand is of local type (derived from local op).

Template Parameters
Lhs_TType of the left hand side operand.
Rhs_TType of the right hand side operand.
Parameters
[in] lhsLeft hand side operand.
[in] rhsRight hand side operand.
Returns

A comparator object that evaluates to true if the left hand side operand is greater than the right hand side operand.

This overload of the greater than operator enables comparison between two operands, where at least one is a local type derived from the local op base. It constructs a comparator object that can be used within the µTest++ framework to assert that the left hand side operand is greater than the right hand side operand. This operator is intended for use with the framework's strongly-typed constants, wrappers, or other custom types, ensuring type-safe and expressive test assertions.

Definition at line 301 of file operators.h.

operator>=()

template <class Lhs_T, class Rhs_T, type_traits::requires_t< type_traits::is_op_v< Lhs_T > or type_traits::is_op_v< Rhs_T > > = 0>
auto micro_os_plus::micro_test_plus::operators::operator>= (const Lhs_T & lhs, const Rhs_T & rhs)
nodiscardconstexpr

Greater than or equal operator. Matches only if at least one operand is of local type (derived from local op).

Template Parameters
Lhs_TType of the left hand side operand.
Rhs_TType of the right hand side operand.
Parameters
[in] lhsLeft hand side operand.
[in] rhsRight hand side operand.
Returns

A comparator object that evaluates to true if the left hand side operand is greater than or equal to the right hand side operand.

This overload of the greater than or equal operator enables comparison between two operands, where at least one is a local type derived from the local op base. It constructs a comparator object that can be used within the µTest++ framework to assert that the left hand side operand is greater than or equal to the right hand side operand. This operator is intended for use with the framework's strongly-typed constants, wrappers, or other custom types, ensuring type-safe and expressive test assertions.

Definition at line 334 of file operators.h.


Generated via docusaurus-plugin-doxygen by Doxygen 1.14.0.