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

Overloaded operators for container comparison. More...

Functions

template<class T, type_traits::requires_t< type_traits::is_container_v< T > > = 0>
constexpr auto micro_os_plus::micro_test_plus::operators::operator!= (T &&lhs, T &&rhs)
 Non-equality operator for containers.
template<class T, type_traits::requires_t< type_traits::is_container_v< T > > = 0>
constexpr auto micro_os_plus::micro_test_plus::operators::operator== (T &&lhs, T &&rhs)
 Equality operator for containers.

Detailed Description

The µTest++ framework provides overloaded operators to facilitate direct and expressive comparison of standard containers, such as vectors and strings, within test cases. These operators enable developers to write clear and concise assertions when verifying the equality or inequality of container contents.

In addition to the generic operators, specialised equality and inequality operators are provided for containers, ensuring accurate and efficient comparison semantics that align with modern C++ practices.

Examples
#include <string_view>
using namespace std::literals; // For the "sv" literal.
// ...
mt::test_case ("Operators", [] {
using namespace micro_test_plus::operators;
mt::expect (std::vector<int>{ 1, 2 } == std::vector<int>{ 1, 2 })
<< "vector{ 1, 2 } == vector{ 1, 2 }";
mt::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 T, type_traits::requires_t< type_traits::is_container_v< T > > = 0>
auto micro_os_plus::micro_test_plus::operators::operator!= ( T && lhs,
T && rhs )
nodiscardconstexpr
Template Parameters
TThe 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.

This overload of the non-equality operator enables direct comparison of two container objects within the µTest++ framework. It constructs a comparator object that can be used in test expectations and assertions to verify that two containers are not equal in content or order.

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

Definition at line 205 of file operators.h.

◆ operator==()

template<class T, type_traits::requires_t< type_traits::is_container_v< T > > = 0>
auto micro_os_plus::micro_test_plus::operators::operator== ( T && lhs,
T && rhs )
nodiscardconstexpr
Template Parameters
TThe 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.

This overload of the equality operator enables direct comparison of two container objects within the µTest++ framework. It constructs a comparator object that can be used in test expectations and assertions to verify that two containers are equal in content and order.

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

Definition at line 177 of file operators.h.