Skip to main content

String Operators

Overloaded operators for string comparison. More...

Operators Index

constexpr autooperator!= (std::string_view lhs, std::string_view rhs)

Non-equality operator for string_view objects. More...

constexpr autooperator== (std::string_view lhs, std::string_view rhs)

Equality operator for string_view objects. More...

Description

Overloaded operators for string comparison.

Operators are provided specifically for comparing string types, such as std::string_view. These operators enable clear, expressive assertions when verifying string values in test cases, supporting both equality and inequality checks.

Using these dedicated operators ensures concise, readable tests that accurately reflect intended logic. The framework ensures correct string comparisons and reports failed checks with both actual and expected values for clear diagnostics.

Examples
 #include <string_view>
 using namespace std::literals; // For the "sv" literal.
 // ...
 
 ts.test ("Check strings with operators", [] (auto& t) {
  using namespace mt::operators;
 
  t.expect (std::string_view{ compute_ultimate_answer () } == "forty-two"sv)
  << "ultimate answer == 'forty-two'";
 });

Operators

operator!=()

auto micro_os_plus::micro_test_plus::operators::operator!= (std::string_view lhs, std::string_view rhs)
nodiscard constexpr

Non-equality operator for string_view objects.

Constructs an ne_ comparator object from the two string_view operands and returns it. The comparator evaluates to true if the string views are not equal.

Parameters
[in] lhs

The left hand side std::string_view operand.

[in] rhs

The right hand side std::string_view operand.

Returns

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

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

88 operator!=(std::string_view lhs, std::string_view rhs)
89 {
90 return detail::ne_{ lhs, rhs };
91 }

operator==()

auto micro_os_plus::micro_test_plus::operators::operator== (std::string_view lhs, std::string_view rhs)
nodiscard constexpr

Equality operator for string_view objects.

Constructs an eq_ comparator object from the two string_view operands and returns it. The comparator evaluates to true if the string views are equal.

Parameters
[in] lhs

The left hand side std::string_view operand.

[in] rhs

The right hand side std::string_view operand.

Returns

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

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

76 operator==(std::string_view lhs, std::string_view rhs)
77 {
78 return detail::eq_{ lhs, rhs };
79 }

Generated via doxygen2docusaurus 2.2.0 by Doxygen 1.17.0.