Skip to main content

Operators

Overloaded operators for expressive test comparisons. More...

Operators Index

template <class Lhs_T, class Rhs_T>
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...

template <class T>
constexpr autooperator 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 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...

template <class Lhs_T, class Rhs_T>
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...

template <class Lhs_T, class Rhs_T>
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...

template <class Lhs_T, class Rhs_T>
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...

template <class Lhs_T, class Rhs_T>
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...

template <class Lhs_T, class Rhs_T>
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...

template <class Lhs_T, class Rhs_T>
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

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
 ts.test ("Operators", [] (auto& t) {
  using namespace micro_test_plus::operators;
  using namespace micro_test_plus::literals;
 
  t.expect (compute_answer () == 42_i) << "answer is 42 (with literal)";
  t.expect (mt::to_i {compute_answer ()} == 42) << "answer is 42 (with cast)";
  t.expect (compute_answer () != 43_i) << "answer is not 43";
  t.expect (compute_answer () < 43_i) << "answer is < 43";
  t.expect (compute_answer () <= 43_i) << "answer is <= 43";
  t.expect (compute_answer () > 41_i) << "answer is > 41";
  t.expect (compute_answer () >= 42_i) << "answer is >= 42";
 });
Logical Operators

Logical operators provide enhanced reporting when used with typed operands, allowing complex test conditions to be composed naturally and readably.

Example
 ts.test ("Logical operators", [] (auto& t) {
  using namespace micro_test_plus::operators;
  using namespace micro_test_plus::literals;
 
  t.expect (compute_answer () == 42_i && compute_float () == 42.0_f);
 });

Operators

operator and()

template <class Lhs_T, class Rhs_T>
auto micro_os_plus::micro_test_plus::operators::operator and (const Lhs_T & lhs, const Rhs_T & rhs)
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.

224 operator and (const Lhs_T& lhs, const Rhs_T& rhs)
225 {
226 return detail::and_{ lhs, rhs };
227 }

operator not()

template <class T>
auto micro_os_plus::micro_test_plus::operators::operator not (const T & t)
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.

252 operator not(const T& t)
253 {
254 return detail::not_{ t };
255 }

operator or()

template <class Lhs_T, class Rhs_T>
auto micro_os_plus::micro_test_plus::operators::operator or (const Lhs_T & lhs, const Rhs_T & rhs)
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.

238 operator or (const Lhs_T& lhs, const Rhs_T& rhs)
239 {
240 return detail::or_{ lhs, rhs };
241 }

operator!=()

template <class Lhs_T, class Rhs_T>
auto micro_os_plus::micro_test_plus::operators::operator!= (const Lhs_T & lhs, const Rhs_T & rhs)
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.

152 operator!=(const Lhs_T& lhs, const Rhs_T& rhs)
153 {
154 return detail::ne_{ lhs, rhs };
155 }

operator<()

template <class Lhs_T, class Rhs_T>
auto micro_os_plus::micro_test_plus::operators::operator< (const Lhs_T & lhs, const Rhs_T & rhs)
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.

195 operator<(const Lhs_T& lhs, const Rhs_T& rhs)
196 {
197 return detail::lt_{ lhs, rhs };
198 }

operator<=()

template <class Lhs_T, class Rhs_T>
auto micro_os_plus::micro_test_plus::operators::operator<= (const Lhs_T & lhs, const Rhs_T & rhs)
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.

210 operator<=(const Lhs_T& lhs, const Rhs_T& rhs)
211 {
212 return detail::le_{ lhs, rhs };
213 }

operator==()

template <class Lhs_T, class Rhs_T>
auto micro_os_plus::micro_test_plus::operators::operator== (const Lhs_T & lhs, const Rhs_T & rhs)
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.

138 operator==(const Lhs_T& lhs, const Rhs_T& rhs)
139 {
140 return detail::eq_{ lhs, rhs };
141 }

operator>()

template <class Lhs_T, class Rhs_T>
auto micro_os_plus::micro_test_plus::operators::operator> (const Lhs_T & lhs, const Rhs_T & rhs)
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.

166 operator>(const Lhs_T& lhs, const Rhs_T& rhs)
167 {
168 return detail::gt_{ lhs, rhs };
169 }

operator>=()

template <class Lhs_T, class Rhs_T>
auto micro_os_plus::micro_test_plus::operators::operator>= (const Lhs_T & lhs, const Rhs_T & rhs)
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.

181 operator>=(const Lhs_T& lhs, const Rhs_T& rhs)
182 {
183 return detail::ge_{ lhs, rhs };
184 }

Generated via doxygen2docusaurus 2.2.0 by Doxygen 1.17.0.