Operators
Overloaded operators for expressive test comparisons. More...
Operators Index
template <class Lhs_T, class Rhs_T> | |
| constexpr auto | operator 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... | |
template <class T> | |
| constexpr auto | operator not (const T &t) |
|
Logical ! (not) operator. Matches only if the operand is of local type (derived from local op). More... | |
template <class Lhs_T, class Rhs_T> | |
| constexpr auto | operator 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... | |
template <class Lhs_T, class Rhs_T> | |
| constexpr auto | operator!= (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... | |
template <class Lhs_T, class Rhs_T> | |
| constexpr auto | operator< (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... | |
template <class Lhs_T, class Rhs_T> | |
| constexpr auto | operator<= (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... | |
template <class Lhs_T, class Rhs_T> | |
| constexpr auto | operator== (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... | |
template <class Lhs_T, class Rhs_T> | |
| constexpr auto | operator> (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... | |
template <class Lhs_T, class Rhs_T> | |
| constexpr auto | operator>= (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
Overloaded operators for expressive test comparisons.
These overloads enable expressive, type-safe test assertions. Operators such as ==, !=, <, >, <=, and >= are defined in 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 specialised µTest++ operators are used with typed operands, failed checks display both actual and expected values, greatly improving report clarity.
These operators are restricted to operands derived from the local detail::op type. For constant values, this is achieved with provided literals (for example, 1_i), whilst dynamic values can be wrapped with converters such as mt::to_i{expression}.
Logical operators (&&, ||, !) are also supported and provide enhanced functionality when used with typed operands, allowing complex test conditions to be composed naturally and readably.
- Examples
- Logical Operators
Logical operators provide enhanced reporting when used with typed operands, allowing complex test conditions to be composed naturally and readably.
- Example
Operators
operator and()
| nodiscard constexpr |
Logical && (and) operator. Matches only if at least one operand is of local type (derived from local op).
Constructs an and_ logical conjunction object from the two operands and returns it. The object evaluates to true if both operands are true. At least one operand must derive from the local op base.
- Template Parameters
-
Lhs_T Type of the left hand side operand.
Rhs_T Type of the right hand side operand.
- Parameters
-
[in] lhs Left hand side operand.
[in] rhs Right hand side operand.
- Returns
A logical conjunction object that evaluates to true if both operands are true.
Definition at line 224 of file operators-inlines.h.
operator not()
| nodiscard constexpr |
Logical ! (not) operator. Matches only if the operand is of local type (derived from local op).
Constructs a not_ logical negator object from the operand and returns it. The object evaluates to true if the operand is false. The operand must derive from the local op base.
- Template Parameters
-
T Type of the operand, constrained to types derived from the local op base.
- Parameters
-
[in] t Operand to be logically negated.
- Returns
A logical negator object that evaluates to true if the operand is false.
Definition at line 252 of file operators-inlines.h.
operator or()
| nodiscard constexpr |
Logical || (or) operator. Matches only if at least one operand is of local type (derived from local op).
Constructs an or_ logical disjunction object from the two operands and returns it. The object evaluates to true if at least one operand is true. At least one operand must derive from the local op base.
- Template Parameters
-
Lhs_T Type of the left hand side operand.
Rhs_T Type of the right hand side operand.
- Parameters
-
[in] lhs Left hand side operand.
[in] rhs Right hand side operand.
- Returns
A logical disjunction object that evaluates to true if at least one operand is true.
Definition at line 238 of file operators-inlines.h.
operator!=()
| nodiscard constexpr |
Non-equality operator for custom types. Matches only if at least one operand is of local type.
Constructs an ne_ comparator object from the two operands and returns it. The comparator evaluates to true if the operands are not equal. At least one operand must derive from the local op base.
- Template Parameters
-
Lhs_T Type of the left hand side operand.
Rhs_T Type of the right hand side operand.
- Parameters
-
[in] lhs Left hand side operand.
[in] rhs Right hand side operand.
- Returns
A comparator object that evaluates to true if the operands are not equal.
Definition at line 152 of file operators-inlines.h.
operator<()
| nodiscard constexpr |
Less than operator. Matches only if at least one operand is of local type (derived from local op).
Constructs an lt_ comparator object from the two operands and returns it. The comparator evaluates to true if lhs is less than rhs. At least one operand must derive from the local op base.
- Template Parameters
-
Lhs_T Type of the left hand side operand.
Rhs_T Type of the right hand side operand.
- Parameters
-
[in] lhs Left hand side operand.
[in] rhs Right 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.
Definition at line 194 of file operators-inlines.h.
operator<=()
| nodiscard constexpr |
Less than or equal operator. Matches only if at least one operand is of local type (derived from local op).
Constructs an le_ comparator object from the two operands and returns it. The comparator evaluates to true if lhs is less than or equal to rhs. At least one operand must derive from the local op base.
- Template Parameters
-
Lhs_T Type of the left hand side operand.
Rhs_T Type of the right hand side operand.
- Parameters
-
[in] lhs Left hand side operand.
[in] rhs Right 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.
Definition at line 209 of file operators-inlines.h.
operator==()
| nodiscard constexpr |
Equality operator for custom types. Matches only if at least one operand is of local type.
Constructs an eq_ comparator object from the two operands and returns it. The comparator evaluates to true if the operands are equal. At least one operand must derive from the local op base.
- Template Parameters
-
Lhs_T Type of the left hand side operand.
Rhs_T Type of the right hand side operand.
- Parameters
-
[in] lhs Left hand side operand.
[in] rhs Right hand side operand.
- Returns
A comparator object that evaluates to true if the operands are equal.
Definition at line 138 of file operators-inlines.h.
operator>()
| nodiscard constexpr |
Greater than operator. Matches only if at least one operand is of local type (derived from local op).
Constructs a gt_ comparator object from the two operands and returns it. The comparator evaluates to true if lhs is greater than rhs. At least one operand must derive from the local op base.
- Template Parameters
-
Lhs_T Type of the left hand side operand.
Rhs_T Type of the right hand side operand.
- Parameters
-
[in] lhs Left hand side operand.
[in] rhs Right 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.
Definition at line 166 of file operators-inlines.h.
operator>=()
| nodiscard constexpr |
Greater than or equal operator. Matches only if at least one operand is of local type (derived from local op).
Constructs a ge_ comparator object from the two operands and returns it. The comparator evaluates to true if lhs is greater than or equal to rhs. At least one operand must derive from the local op base.
- Template Parameters
-
Lhs_T Type of the left hand side operand.
Rhs_T Type of the right hand side operand.
- Parameters
-
[in] lhs Left hand side operand.
[in] rhs Right 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.
Definition at line 181 of file operators-inlines.h.
Generated via doxygen2docusaurus 2.2.0 by Doxygen 1.17.0.