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
lhs

Left hand side operand.

rhs

Right hand side operand.

Returns

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

Definition at line 225 of file operators-inlines.h.

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

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
t

Operand to be logically negated.

Returns

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

Definition at line 253 of file operators-inlines.h.

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

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
lhs

Left hand side operand.

rhs

Right hand side operand.

Returns

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

Definition at line 239 of file operators-inlines.h.

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

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
lhs

Left hand side operand.

rhs

Right hand side operand.

Returns

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

Definition at line 153 of file operators-inlines.h.

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

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
lhs

Left hand side operand.

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 195 of file operators-inlines.h.

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

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
lhs

Left hand side operand.

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 210 of file operators-inlines.h.

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

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
lhs

Left hand side operand.

rhs

Right hand side operand.

Returns

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

Definition at line 139 of file operators-inlines.h.

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

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
lhs

Left hand side operand.

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 167 of file operators-inlines.h.

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

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
lhs

Left hand side operand.

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 182 of file operators-inlines.h.

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

Generated via doxygen2docusaurus 2.2.2 by Doxygen 1.17.0.