Skip to main content

Container Operators

Overloaded operators for container comparison. More...

Operators Index

template <class Lhs_T, class Rhs_T>
constexpr autooperator!= (const Lhs_T &lhs, const Rhs_T &rhs)

Non-equality operator for containers. More...

template <class Lhs_T, class Rhs_T>
constexpr autooperator== (const Lhs_T &lhs, const Rhs_T &rhs)

Equality operator for containers. More...

Description

Overloaded operators for container comparison.

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 }";
 });

Operators

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 containers.

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_T

The left-hand container type, constrained to recognised container types.

Rhs_T

The right-hand container type, constrained to recognised container types.

Parameters
[in] lhs

The left hand side container operand.

[in] rhs

The 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.

124 operator!= (const Lhs_T& lhs, const Rhs_T& rhs)
125 {
126 return detail::ne_{ lhs, rhs };
127 }

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 containers.

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_T

The left-hand container type, constrained to recognised container types.

Rhs_T

The right-hand container type, constrained to recognised container types.

Parameters
[in] lhs

The left hand side container operand.

[in] rhs

The 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.

106 operator== (const Lhs_T& lhs, const Rhs_T& rhs)
107 {
108 return detail::eq_{ lhs, rhs };
109 }

Generated via doxygen2docusaurus 2.2.0 by Doxygen 1.17.0.