Skip to main content

The operators.h File Reference

C++ header file with declarations for the µTest++ operators. More...

Included Headers

#include <string_view>
#include "detail.h"

Namespaces Index

namespacemicro_os_plus

The primary namespace for the µOS++ framework. More...

namespacemicro_os_plus::micro_test_plus

Primary namespace for the µTest++ testing framework. More...

namespacemicro_os_plus::micro_test_plus::operators

Custom operator overloads for expressive and type-safe test assertions. More...

Functions Index

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

constexpr autooperator not (const T &t)

Logical ! (not) operator. Matches only if the operand is of local type (derived from local op). More...

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

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

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

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

constexpr autooperator!= (T &&lhs, T &&rhs)

Non-equality operator for containers. More...

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

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

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

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

Equality operator for string_view objects. More...

constexpr autooperator== (T &&lhs, T &&rhs)

Equality operator for containers. More...

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

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

C++ header file with declarations for the µTest++ operators.

This header provides the declarations for the custom operator overloads used within the µTest++ framework. It defines interfaces for equality, inequality, relational, and logical operators tailored for use with the framework’s strongly-typed constants, wrappers, containers, and string views.

These operator overloads enable expressive, concise, and type-safe test assertions, supporting both compile-time and run-time evaluation. The operators are selectively enabled for types recognised by the framework, minimising the risk of conflicts with user-defined or standard operators.

All definitions reside within the micro_os_plus::micro_test_plus::operators namespace, ensuring clear separation from user code and minimising the risk of naming conflicts.

The header files are organised within the include/micro-os-plus/micro-test-plus folder to maintain a structured and modular codebase.

This file is intended solely for internal use within the framework and should not be included directly by user code.

File Listing

The file content with the documentation metadata removed is:

1/*
2 * This file is part of the µOS++ project (https://micro-os-plus.github.io/).
3 * Copyright (c) 2021 Liviu Ionescu. All rights reserved.
4 *
5 * Permission to use, copy, modify, and/or distribute this software
6 * for any purpose is hereby granted, under the terms of the MIT license.
7 *
8 * If a copy of the license was not distributed with this file, it can
10 *
11 * Major parts of the code are inspired from v1.1.8 of the Boost UT project,
12 * released under the terms of the Boost Version 1 Software License,
13 * which can be obtained from https://www.boost.org/LICENSE&#95;1&#95;0.txt.
14 */
15
16// ----------------------------------------------------------------------------
17
45
46#ifndef MICRO_TEST_PLUS_OPERATORS_H_
47#define MICRO_TEST_PLUS_OPERATORS_H_
48
49// ----------------------------------------------------------------------------
50
51#ifdef __cplusplus
52
53// ----------------------------------------------------------------------------
54
55#include <string_view>
56
57#include "detail.h"
58
59// ----------------------------------------------------------------------------
60
61#if defined(__GNUC__)
62#pragma GCC diagnostic push
63#pragma GCC diagnostic ignored "-Wpadded"
64#pragma GCC diagnostic ignored "-Waggregate-return"
65#if defined(__clang__)
66#pragma clang diagnostic ignored "-Wc++98-compat"
67#pragma clang diagnostic ignored "-Wunknown-warning-option"
68#endif
69#endif
70
72{
73 // --------------------------------------------------------------------------
74
107 namespace operators
108 {
109 // In order to simplify things and use the return type `auto`,
110 // the definition must be included before any use.
111
127 [[nodiscard]] constexpr auto
128 operator==(std::string_view lhs, std::string_view rhs)
129 {
130 return detail::eq_{ lhs, rhs };
131 }
132
148 [[nodiscard]] constexpr auto
149 operator!=(std::string_view lhs, std::string_view rhs)
150 {
151 return detail::ne_{ lhs, rhs };
152 }
153
174 template <class T,
176 [[nodiscard]] constexpr auto
177 operator==(T&& lhs, T&& rhs)
178 {
179 return detail::eq_{ static_cast<T&&> (lhs), static_cast<T&&> (rhs) };
180 }
181
202 template <class T,
204 [[nodiscard]] constexpr auto
205 operator!=(T&& lhs, T&& rhs)
206 {
207 return detail::ne_{ static_cast<T&&> (lhs), static_cast<T&&> (rhs) };
208 }
209
232 template <class Lhs_T, class Rhs_T,
235 = 0>
236 [[nodiscard]] constexpr auto
237 operator==(const Lhs_T& lhs, const Rhs_T& rhs)
238 {
239 return detail::eq_{ lhs, rhs };
240 }
241
264 template <class Lhs_T, class Rhs_T,
267 = 0>
268 [[nodiscard]] constexpr auto
269 operator!=(const Lhs_T& lhs, const Rhs_T& rhs)
270 {
271 return detail::ne_{ lhs, rhs };
272 }
273
296 template <class Lhs_T, class Rhs_T,
299 = 0>
300 [[nodiscard]] constexpr auto
301 operator>(const Lhs_T& lhs, const Rhs_T& rhs)
302 {
303 return detail::gt_{ lhs, rhs };
304 }
305
329 template <class Lhs_T, class Rhs_T,
332 = 0>
333 [[nodiscard]] constexpr auto
334 operator>=(const Lhs_T& lhs, const Rhs_T& rhs)
335 {
336 return detail::ge_{ lhs, rhs };
337 }
338
361 template <class Lhs_T, class Rhs_T,
364 = 0>
365 [[nodiscard]] constexpr auto
366 operator<(const Lhs_T& lhs, const Rhs_T& rhs)
367 {
368 return detail::lt_{ lhs, rhs };
369 }
370
394 template <class Lhs_T, class Rhs_T,
397 = 0>
398 [[nodiscard]] constexpr auto
399 operator<=(const Lhs_T& lhs, const Rhs_T& rhs)
400 {
401 return detail::le_{ lhs, rhs };
402 }
403
426 template <class Lhs_T, class Rhs_T,
429 = 0>
430 [[nodiscard]] constexpr auto
431 operator and (const Lhs_T& lhs, const Rhs_T& rhs)
432 {
433 return detail::and_{ lhs, rhs };
434 }
435
458 template <class Lhs_T, class Rhs_T,
461 = 0>
462 [[nodiscard]] constexpr auto
463 operator or (const Lhs_T& lhs, const Rhs_T& rhs)
464 {
465 return detail::or_{ lhs, rhs };
466 }
467
489 template <class T, type_traits::requires_t<type_traits::is_op_v<T>> = 0>
490 [[nodiscard]] constexpr auto
491 operator not(const T& t)
492 {
493 return detail::not_{ t };
494 }
495
496 // ------------------------------------------------------------------------
497 } // namespace operators
498
499 // --------------------------------------------------------------------------
500} // namespace micro_os_plus::micro_test_plus
501
502#if defined(__GNUC__)
503#pragma GCC diagnostic pop
504#endif
505
506// ----------------------------------------------------------------------------
507
508#endif // __cplusplus
509
510// ----------------------------------------------------------------------------
511
512#endif // MICRO_TEST_PLUS_OPERATORS_H_
513
514// ----------------------------------------------------------------------------

Generated via docusaurus-plugin-doxygen by Doxygen 1.14.0.