micro-test-plus 4.1.0
µTest++ Testing Framework
Loading...
Searching...
No Matches
Container Operators

Overloaded operators for container comparison. More...

Functions

template<class Lhs_T, class Rhs_T>
requires (type_traits::container_like<Lhs_T> and type_traits::container_like<Rhs_T>)
constexpr auto micro_os_plus::micro_test_plus::operators::operator!= (const Lhs_T &lhs, const Rhs_T &rhs)
 Non-equality operator for containers.
template<class Lhs_T, class Rhs_T>
requires (type_traits::container_like<Lhs_T> and type_traits::container_like<Rhs_T>)
constexpr auto micro_os_plus::micro_test_plus::operators::operator== (const Lhs_T &lhs, const Rhs_T &rhs)
 Equality operator for containers.

Detailed Description

Within test cases, overloaded operators support direct and expressive comparison of standard containers, such as vectors and strings. These operators enable clear, concise assertions when verifying equality or inequality of container contents.

In addition to generic operators, specialised equality and inequality operators are available for container types where dedicated handling improves correctness or efficiency, while preserving modern C++ semantics.

Examples
#include <vector>
// ...
ts.test ("Check containers with operators", [] (auto& t) {
using namespace mt::operators;
t.expect (std::vector<int>{ 1, 2 } == std::vector<int>{ 1, 2 })
<< "vector{ 1, 2 } == vector{ 1, 2 }";
t.expect (std::vector<int>{ 1, 2, 3 } != std::vector<int>{ 1, 2, 4 })
<< "vector{ 1, 2, 3 } != vector{ 1, 2, 4 }";
});
Primary namespace for the µTest++ testing framework.

Function Documentation

◆ operator!=()

template<class Lhs_T, class Rhs_T>
requires (type_traits::container_like<Lhs_T> and type_traits::container_like<Rhs_T>)
auto micro_os_plus::micro_test_plus::operators::operator!= ( const Lhs_T & lhs,
const Rhs_T & rhs )
nodiscardconstexpr

Constructs an ne_ comparator object from the two container operands and returns it. The comparator evaluates to true if the containers are not equal in content or order.

The operator is enabled only for types recognised as containers by the framework's type traits.

Template Parameters
Lhs_TThe left-hand container type, constrained to recognised container types.
Rhs_TThe right-hand container type, constrained to recognised container types.
Parameters
[in]lhsThe left hand side container operand.
[in]rhsThe right hand side container operand.
Returns
A comparator object that evaluates to true if the containers are not equal.

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

125 {
126 return detail::ne_{ lhs, rhs };
127 }
Non-equality comparator struct template.
Definition detail.h:338

◆ operator==()

template<class Lhs_T, class Rhs_T>
requires (type_traits::container_like<Lhs_T> and type_traits::container_like<Rhs_T>)
auto micro_os_plus::micro_test_plus::operators::operator== ( const Lhs_T & lhs,
const Rhs_T & rhs )
nodiscardconstexpr

Constructs an eq_ comparator object from the two container operands and returns it. The comparator evaluates to true if the containers are equal in content and order.

The operator is enabled only for types recognised as containers by the framework's type traits.

Template Parameters
Lhs_TThe left-hand container type, constrained to recognised container types.
Rhs_TThe right-hand container type, constrained to recognised container types.
Parameters
[in]lhsThe left hand side container operand.
[in]rhsThe right hand side container operand.
Returns
A comparator object that evaluates to true if the containers are equal.

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

107 {
108 return detail::eq_{ lhs, rhs };
109 }
Equality comparator struct template.
Definition detail.h:306