tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
weak_ordering.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2// SPDX-FileCopyrightText: Copyright (C) 2021 Tobias Hienzsch
3
4#ifndef TETL_COMPARE_WEAK_ORDERING_HPP
5#define TETL_COMPARE_WEAK_ORDERING_HPP
6
7#include <etl/_compare/detail.hpp>
8#include <etl/_compare/partial_ordering.hpp>
9#include <etl/_cstddef/nullptr_t.hpp>
10
11namespace etl {
12
13/// \ingroup compare
15 static weak_ordering const less;
17 static weak_ordering const greater;
18
19 constexpr operator partial_ordering() const noexcept
20 {
21 return _value == 0 ? partial_ordering::equivalent
23 }
24
25 [[nodiscard]] friend constexpr auto operator==(weak_ordering, weak_ordering) noexcept -> bool = default;
26
27 [[nodiscard]] friend constexpr auto operator==(weak_ordering v, nullptr_t) noexcept -> bool
28 {
29 return v._value == 0;
30 }
31
32 [[nodiscard]] friend constexpr auto operator<(weak_ordering v, nullptr_t) noexcept -> bool
33 {
34 return v._value < 0;
35 }
36
37 [[nodiscard]] friend constexpr auto operator<=(weak_ordering v, nullptr_t) noexcept -> bool
38 {
39 return v._value <= 0;
40 }
41
42 [[nodiscard]] friend constexpr auto operator>(weak_ordering v, nullptr_t) noexcept -> bool
43 {
44 return v._value > 0;
45 }
46
47 [[nodiscard]] friend constexpr auto operator>=(weak_ordering v, nullptr_t) noexcept -> bool
48 {
49 return v._value >= 0;
50 }
51
52 [[nodiscard]] friend constexpr auto operator<(nullptr_t, weak_ordering v) noexcept -> bool
53 {
54 return 0 < v._value;
55 }
56
57 [[nodiscard]] friend constexpr auto operator<=(nullptr_t, weak_ordering v) noexcept -> bool
58 {
59 return 0 <= v._value;
60 }
61
62 [[nodiscard]] friend constexpr auto operator>(nullptr_t, weak_ordering v) noexcept -> bool
63 {
64 return 0 > v._value;
65 }
66
67 [[nodiscard]] friend constexpr auto operator>=(nullptr_t, weak_ordering v) noexcept -> bool
68 {
69 return 0 >= v._value;
70 }
71
72 [[nodiscard]] friend constexpr auto operator<=>(weak_ordering v, nullptr_t) noexcept -> weak_ordering
73 {
74 return v;
75 }
76
77 [[nodiscard]] friend constexpr auto operator<=>(nullptr_t, weak_ordering v) noexcept -> weak_ordering
78 {
79 return v < nullptr ? weak_ordering::greater : (v > nullptr ? weak_ordering::less : v);
80 }
81
82private:
83 explicit constexpr weak_ordering(detail::order_result v) noexcept
84 : _value{static_cast<int8_t>(v)}
85 {
86 }
87
88 int8_t _value;
89};
90
91inline constexpr weak_ordering weak_ordering::less{detail::order_result::less};
92inline constexpr weak_ordering weak_ordering::equivalent{detail::order_result::equal};
93inline constexpr weak_ordering weak_ordering::greater{detail::order_result::greater};
94
95} // namespace etl
96
97#endif // TETL_COMPARE_WEAK_ORDERING_HPP
Definition adjacent_find.hpp:9
Definition partial_ordering.hpp:13
static partial_ordering const equivalent
Definition partial_ordering.hpp:15
static partial_ordering const greater
Definition partial_ordering.hpp:16
static partial_ordering const less
Definition partial_ordering.hpp:14
Definition weak_ordering.hpp:14
friend constexpr auto operator<(weak_ordering v, nullptr_t) noexcept -> bool
Definition weak_ordering.hpp:32
friend constexpr auto operator<=(nullptr_t, weak_ordering v) noexcept -> bool
Definition weak_ordering.hpp:57
static weak_ordering const greater
Definition weak_ordering.hpp:17
friend constexpr auto operator>=(weak_ordering v, nullptr_t) noexcept -> bool
Definition weak_ordering.hpp:47
friend constexpr auto operator<=(weak_ordering v, nullptr_t) noexcept -> bool
Definition weak_ordering.hpp:37
static weak_ordering const equivalent
Definition weak_ordering.hpp:16
constexpr operator partial_ordering() const noexcept
Definition weak_ordering.hpp:19
friend constexpr auto operator>(weak_ordering v, nullptr_t) noexcept -> bool
Definition weak_ordering.hpp:42
friend constexpr auto operator<=>(weak_ordering v, nullptr_t) noexcept -> weak_ordering
Definition weak_ordering.hpp:72
friend constexpr auto operator<(nullptr_t, weak_ordering v) noexcept -> bool
Definition weak_ordering.hpp:52
friend constexpr auto operator>(nullptr_t, weak_ordering v) noexcept -> bool
Definition weak_ordering.hpp:62
friend constexpr auto operator==(weak_ordering v, nullptr_t) noexcept -> bool
Definition weak_ordering.hpp:27
friend constexpr auto operator>=(nullptr_t, weak_ordering v) noexcept -> bool
Definition weak_ordering.hpp:67
friend constexpr auto operator<=>(nullptr_t, weak_ordering v) noexcept -> weak_ordering
Definition weak_ordering.hpp:77
friend constexpr auto operator==(weak_ordering, weak_ordering) noexcept -> bool=default
static weak_ordering const less
Definition weak_ordering.hpp:15