Skip to main content

function-comparators.h File

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

Included Headers​

Namespaces Index​

namespacemicro_os_plus

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

namespacemicro_test_plus

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

Functions Index​

template <class First_T, class Second_T, class... Rest_T>
constexpr autoall_of (First_T &&first, Second_T &&second, Rest_T &&... rest)

Generic logical and operation, for two or more operands. More...

template <class First_T, class Second_T, class... Rest_T>
constexpr autoany_of (First_T &&first, Second_T &&second, Rest_T &&... rest)

Generic logical (inclusive) or operation, for two or more operands. More...

template <class Lhs_T, class Rhs_T, class Epsilon_T>
constexpr autoapprox (Lhs_T &&lhs, Rhs_T &&rhs, Epsilon_T &&epsilon)

Approximate equality comparator, with an explicit tolerance. More...

template <class Lhs_T, class Rhs_T>
constexpr autoeq (Lhs_T &&lhs, Rhs_T &&rhs)

Generic equality comparator. More...

template <class Lhs_T, class Rhs_T>
constexpr autoge (Lhs_T &&lhs, Rhs_T &&rhs)

Generic greater than or equal comparator. More...

template <class Lhs_T, class Rhs_T>
constexpr autogt (Lhs_T &&lhs, Rhs_T &&rhs)

Generic greater than comparator. More...

template <class Lhs_T, class Rhs_T>
constexpr autole (Lhs_T &&lhs, Rhs_T &&rhs)

Generic less than or equal comparator. More...

template <class Lhs_T, class Rhs_T>
constexpr autolt (Lhs_T &&lhs, Rhs_T &&rhs)

Generic less than comparator. More...

template <class Lhs_T, class Rhs_T>
constexpr autone (Lhs_T &&lhs, Rhs_T &&rhs)

Generic non-equality comparator. More...

template <class Expr_T>
constexpr autonegate (Expr_T &&expr)

Generic logical not operation. More...

Description​

C++ header file with declarations for the µTest++ function comparators.

This header provides the declarations for the function comparator templates and logical operators used within the µTest++ framework. It defines the interfaces for the generic comparison functions, including equality, non-equality, greater than, less than, greater than or equal, and less than or equal, and the approximate comparison with an explicit tolerance (approx). Additionally, it declares logical combinators such as conjunction (all_of), disjunction (any_of), and negation (negate); their deprecated v5.0.1 names are declared in deprecated.h.

The C strings (the arrays, including the string literals, and the pointers of the character types) are compared by content, and so are the other arrays (e.g. byte buffers), element by element; the other pointers are compared by address. The temporaries are moved into the returned expressions, and the named operands are copied, so an expression can be returned from the function that builds it, and kept after the operands are destroyed, except for the arrays and the characters of the C strings, which are referred to and must outlive the expression. The copy is made for every check, passing or failing, so a large container or string costs an allocation; compare a std::string_view of a string instead, when the cost matters. The logical combinators have descriptive names, since and, or, and not are alternative tokens and cannot be used as identifiers.

All definitions reside within the micro_os_plus::micro_test_plus namespace.

This file is included by micro-os-plus/micro-test-plus.h, which is the header that the applications include.

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-2026 Liviu Ionescu. All rights reserved.
4 *
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * 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 be
9 * obtained from https://opensource.org/licenses/mit.
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.0 Software License,
13 * which can be obtained from https://www.boost.org/LICENSE_1_0.txt.
14 */
15
16// ----------------------------------------------------------------------------
17
55
56#ifndef MICRO_OS_PLUS_MICRO_TEST_PLUS_FUNCTION_COMPARATORS_H_
57#define MICRO_OS_PLUS_MICRO_TEST_PLUS_FUNCTION_COMPARATORS_H_
58
59// ----------------------------------------------------------------------------
60
61#if defined(__cplusplus)
62
63// ----------------------------------------------------------------------------
64
65#if __has_include("micro-os-plus/project-config.h")
66#include "micro-os-plus/project-config.h"
67#endif // __has_include("micro-os-plus/project-config.h")
68
69#if __has_include("micro-os-plus/micro-test-plus-defines.h")
70#include "micro-os-plus/micro-test-plus-defines.h"
71#endif // __has_include("micro-os-plus/micro-test-plus-defines.h")
72
73#include "detail.h"
74
75// ----------------------------------------------------------------------------
76
77#if defined(__GNUC__)
78#pragma GCC diagnostic push
79
80#pragma GCC diagnostic ignored "-Wpadded"
81#pragma GCC diagnostic ignored "-Waggregate-return"
82#if defined(__clang__)
83#pragma clang diagnostic ignored "-Wc++98-compat"
84#pragma clang diagnostic ignored "-Wpre-c++17-compat"
85#pragma clang diagnostic ignored "-Wunknown-warning-option"
86#endif // defined(__clang__)
87#endif // defined(__GNUC__)
88
89// ===========================================================================
90
92{
93 // --------------------------------------------------------------------------
94
130 template <class Lhs_T, class Rhs_T>
132 Rhs_T>
133 [[nodiscard]] constexpr auto
134 eq (Lhs_T&& lhs, Rhs_T&& rhs);
135
136#if !defined(__DOXYGEN__)
153 template <class Lhs_T, class Rhs_T>
155 Rhs_T>)
156 [[nodiscard]] constexpr bool
157 eq (Lhs_T&& lhs, Rhs_T&& rhs);
158#endif // !defined(__DOXYGEN__)
159
171 template <class Lhs_T, class Rhs_T>
173 Rhs_T>
174 [[nodiscard]] constexpr auto
175 ne (Lhs_T&& lhs, Rhs_T&& rhs);
176
177#if !defined(__DOXYGEN__)
194 template <class Lhs_T, class Rhs_T>
196 Lhs_T, Rhs_T>)
197 [[nodiscard]] constexpr bool
198 ne (Lhs_T&& lhs, Rhs_T&& rhs);
199#endif // !defined(__DOXYGEN__)
200
212 template <class Lhs_T, class Rhs_T>
214 Rhs_T>
215 [[nodiscard]] constexpr auto
216 gt (Lhs_T&& lhs, Rhs_T&& rhs);
217
218#if !defined(__DOXYGEN__)
235 template <class Lhs_T, class Rhs_T>
237 Lhs_T, Rhs_T>)
238 [[nodiscard]] constexpr bool
239 gt (Lhs_T&& lhs, Rhs_T&& rhs);
240#endif // !defined(__DOXYGEN__)
241
254 template <class Lhs_T, class Rhs_T>
256 Lhs_T, Rhs_T>
257 [[nodiscard]] constexpr auto
258 ge (Lhs_T&& lhs, Rhs_T&& rhs);
259
260#if !defined(__DOXYGEN__)
277 template <class Lhs_T, class Rhs_T>
278 requires (not detail::comparable_operands<
280 [[nodiscard]] constexpr bool
281 ge (Lhs_T&& lhs, Rhs_T&& rhs);
282#endif // !defined(__DOXYGEN__)
283
296 template <class Lhs_T, class Rhs_T>
298 Rhs_T>
299 [[nodiscard]] constexpr auto
300 lt (Lhs_T&& lhs, Rhs_T&& rhs);
301
302#if !defined(__DOXYGEN__)
319 template <class Lhs_T, class Rhs_T>
321 Rhs_T>)
322 [[nodiscard]] constexpr bool
323 lt (Lhs_T&& lhs, Rhs_T&& rhs);
324#endif // !defined(__DOXYGEN__)
325
338 template <class Lhs_T, class Rhs_T>
340 Rhs_T>
341 [[nodiscard]] constexpr auto
342 le (Lhs_T&& lhs, Rhs_T&& rhs);
343
344#if !defined(__DOXYGEN__)
361 template <class Lhs_T, class Rhs_T>
363 Lhs_T, Rhs_T>)
364 [[nodiscard]] constexpr bool
365 le (Lhs_T&& lhs, Rhs_T&& rhs);
366#endif // !defined(__DOXYGEN__)
367
406 template <class Lhs_T, class Rhs_T, class Epsilon_T>
410 [[nodiscard]] constexpr auto
411 approx (Lhs_T&& lhs, Rhs_T&& rhs, Epsilon_T&& epsilon);
412
426 template <class Expr_T>
428 [[nodiscard]] constexpr auto
429 negate (Expr_T&& expr);
430
448 template <class First_T, class Second_T, class... Rest_T>
451 and (extension::checkable<std::remove_cvref_t<Rest_T>> and ...))
452 [[nodiscard]] constexpr auto
453 all_of (First_T&& first, Second_T&& second, Rest_T&&... rest);
454
473 template <class First_T, class Second_T, class... Rest_T>
476 and (extension::checkable<std::remove_cvref_t<Rest_T>> and ...))
477 [[nodiscard]] constexpr auto
478 any_of (First_T&& first, Second_T&& second, Rest_T&&... rest);
479
480 // --------------------------------------------------------------------------
481} // namespace micro_os_plus::micro_test_plus
482
483#if defined(__GNUC__)
484#pragma GCC diagnostic pop
485#endif // defined(__GNUC__)
486
487// ----------------------------------------------------------------------------
488
489#endif // defined(__cplusplus)
490
491// ============================================================================
492// Templates, inlines & constexpr implementations.
493
495
496// ----------------------------------------------------------------------------
497
498#endif // MICRO_OS_PLUS_MICRO_TEST_PLUS_FUNCTION_COMPARATORS_H_
499
500// ----------------------------------------------------------------------------

Generated via doxygen2docusaurus 2.2.8 by Doxygen 1.18.0.