tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
strong_ordering.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2
3#ifndef TETL_COMPARE_STRONG_ORDERING_HPP
4#define TETL_COMPARE_STRONG_ORDERING_HPP
5
10
11namespace etl {
12
14struct strong_ordering {
15 static strong_ordering const less;
16 static strong_ordering const equal;
17 static strong_ordering const equivalent;
18 static strong_ordering const greater;
19
20 [[nodiscard]] constexpr operator partial_ordering() const noexcept
21 {
22 return _value == 0 ? partial_ordering::equivalent
24 }
25
26 [[nodiscard]] constexpr operator weak_ordering() const noexcept
27 {
28 return _value == 0 ? weak_ordering::equivalent : (_value < 0 ? weak_ordering::less : weak_ordering::greater);
29 }
30
31 [[nodiscard]] friend constexpr auto operator==(strong_ordering, strong_ordering) noexcept -> bool = default;
32
33 [[nodiscard]] friend constexpr auto operator==(strong_ordering v, nullptr_t) noexcept -> bool
34 {
35 return v._value == 0;
36 }
37
38 [[nodiscard]] friend constexpr auto operator<(strong_ordering v, nullptr_t) noexcept -> bool
39 {
40 return v._value < 0;
41 }
42
43 [[nodiscard]] friend constexpr auto operator<=(strong_ordering v, nullptr_t) noexcept -> bool
44 {
45 return v._value <= 0;
46 }
47
48 [[nodiscard]] friend constexpr auto operator>(strong_ordering v, nullptr_t) noexcept -> bool
49 {
50 return v._value > 0;
51 }
52
53 [[nodiscard]] friend constexpr auto operator>=(strong_ordering v, nullptr_t) noexcept -> bool
54 {
55 return v._value >= 0;
56 }
57
58 [[nodiscard]] friend constexpr auto operator<(nullptr_t, strong_ordering v) noexcept -> bool
59 {
60 return 0 < v._value;
61 }
62
63 [[nodiscard]] friend constexpr auto operator<=(nullptr_t, strong_ordering v) noexcept -> bool
64 {
65 return 0 <= v._value;
66 }
67
68 [[nodiscard]] friend constexpr auto operator>(nullptr_t, strong_ordering v) noexcept -> bool
69 {
70 return 0 > v._value;
71 }
72
73 [[nodiscard]] friend constexpr auto operator>=(nullptr_t, strong_ordering v) noexcept -> bool
74 {
75 return 0 >= v._value;
76 }
77
78 [[nodiscard]] friend constexpr auto operator<=>(strong_ordering v, nullptr_t) noexcept -> strong_ordering
79 {
80 return v;
81 }
82
83 [[nodiscard]] friend constexpr auto operator<=>(nullptr_t, strong_ordering v) noexcept -> strong_ordering
84 {
85 return v < nullptr ? strong_ordering::greater : (v > nullptr ? strong_ordering::less : v);
86 }
87
88private:
89 constexpr explicit strong_ordering(detail::order_result v) noexcept
90 : _value{static_cast<int8_t>(v)}
91 {
92 }
93
94 int8_t _value;
95};
96
97inline constexpr strong_ordering strong_ordering::less{detail::order_result::less};
98inline constexpr strong_ordering strong_ordering::equal{detail::order_result::equal};
99inline constexpr strong_ordering strong_ordering::equivalent{detail::order_result::equal};
100inline constexpr strong_ordering strong_ordering::greater{detail::order_result::greater};
101
102} // namespace etl
103
104#endif // TETL_COMPARE_STRONG_ORDERING_HPP
Definition adjacent_find.hpp:8
TETL_BUILTIN_INT8 int8_t
Signed integer type with width of exactly 8 bits.
Definition int_t.hpp:11
decltype(nullptr) nullptr_t
etl::nullptr_t is the type of the null pointer literal, nullptr. It is a distinct type that is not it...
Definition nullptr_t.hpp:13
Definition partial_ordering.hpp:12
static partial_ordering const equivalent
Definition partial_ordering.hpp:14
static partial_ordering const greater
Definition partial_ordering.hpp:15
static partial_ordering const less
Definition partial_ordering.hpp:13
Definition strong_ordering.hpp:14
friend constexpr auto operator==(strong_ordering, strong_ordering) noexcept -> bool=default
friend constexpr auto operator<=(nullptr_t, strong_ordering v) noexcept -> bool
Definition strong_ordering.hpp:63
friend constexpr auto operator<=>(strong_ordering v, nullptr_t) noexcept -> strong_ordering
Definition strong_ordering.hpp:78
friend constexpr auto operator>=(nullptr_t, strong_ordering v) noexcept -> bool
Definition strong_ordering.hpp:73
static strong_ordering const less
Definition strong_ordering.hpp:15
friend constexpr auto operator<=>(nullptr_t, strong_ordering v) noexcept -> strong_ordering
Definition strong_ordering.hpp:83
friend constexpr auto operator<(strong_ordering v, nullptr_t) noexcept -> bool
Definition strong_ordering.hpp:38
static strong_ordering const greater
Definition strong_ordering.hpp:18
static strong_ordering const equivalent
Definition strong_ordering.hpp:17
static strong_ordering const equal
Definition strong_ordering.hpp:16
friend constexpr auto operator>(nullptr_t, strong_ordering v) noexcept -> bool
Definition strong_ordering.hpp:68
friend constexpr auto operator>(strong_ordering v, nullptr_t) noexcept -> bool
Definition strong_ordering.hpp:48
friend constexpr auto operator==(strong_ordering v, nullptr_t) noexcept -> bool
Definition strong_ordering.hpp:33
friend constexpr auto operator<(nullptr_t, strong_ordering v) noexcept -> bool
Definition strong_ordering.hpp:58
friend constexpr auto operator>=(strong_ordering v, nullptr_t) noexcept -> bool
Definition strong_ordering.hpp:53
friend constexpr auto operator<=(strong_ordering v, nullptr_t) noexcept -> bool
Definition strong_ordering.hpp:43
Definition weak_ordering.hpp:13
static weak_ordering const greater
Definition weak_ordering.hpp:17
static weak_ordering const equivalent
Definition weak_ordering.hpp:16
static weak_ordering const less
Definition weak_ordering.hpp:15