micro-test-plus 3.2.2
µTest++ Testing Framework
Loading...
Searching...
No Matches
operators.h
Go to the documentation of this file.
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
9 * be 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
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// ----------------------------------------------------------------------------
C++ header file with declarations for the µTest++ internals.
constexpr auto operator>=(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 l...
Definition operators.h:334
constexpr auto operator<=(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 loca...
Definition operators.h:399
constexpr auto operator>(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).
Definition operators.h:301
constexpr auto operator<(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).
Definition operators.h:366
constexpr auto operator!=(std::string_view lhs, std::string_view rhs)
Non-equality operator for string_view objects.
Definition operators.h:149
constexpr auto operator==(std::string_view lhs, std::string_view rhs)
Equality operator for string_view objects.
Definition operators.h:128
Custom operator overloads for expressive and type-safe test assertions.
typename requires_< Cond >::type requires_t
Alias template for extracting the type member from requires_.
constexpr auto is_op_v
Variable template to determine if a type derives from op.
Primary namespace for the µTest++ testing framework.
Logical AND comparator struct template.
Definition detail.h:1178
Equality comparator struct template.
Definition detail.h:260
Greater than or equal comparator struct template.
Definition detail.h:738
Greater than comparator struct template.
Definition detail.h:593
Less than or equal comparator struct template.
Definition detail.h:1031
Less than comparator struct template.
Definition detail.h:885
Non-equality comparator struct template.
Definition detail.h:432
Logical NOT comparator struct template.
Definition detail.h:1415
Logical OR comparator struct template.
Definition detail.h:1297