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
3#ifndef TETL_COMPARE_WEAK_ORDERING_HPP
4#define TETL_COMPARE_WEAK_ORDERING_HPP
5
9
10namespace etl {
11
13struct weak_ordering {
14
15 static weak_ordering const less;
16 static weak_ordering const equivalent;
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 { return v._value < 0; }
33
34 [[nodiscard]] friend constexpr auto operator<=(weak_ordering v, nullptr_t) noexcept -> bool
35 {
36 return v._value <= 0;
37 }
38
39 [[nodiscard]] friend constexpr auto operator>(weak_ordering v, nullptr_t) noexcept -> bool { return v._value > 0; }
40
41 [[nodiscard]] friend constexpr auto operator>=(weak_ordering v, nullptr_t) noexcept -> bool
42 {
43 return v._value >= 0;
44 }
45
46 [[nodiscard]] friend constexpr auto operator<(nullptr_t, weak_ordering v) noexcept -> bool { return 0 < v._value; }
47
48 [[nodiscard]] friend constexpr auto operator<=(nullptr_t, weak_ordering v) noexcept -> bool
49 {
50 return 0 <= v._value;
51 }
52
53 [[nodiscard]] friend constexpr auto operator>(nullptr_t, weak_ordering v) noexcept -> bool { return 0 > v._value; }
54
55 [[nodiscard]] friend constexpr auto operator>=(nullptr_t, weak_ordering v) noexcept -> bool
56 {
57 return 0 >= v._value;
58 }
59
60 [[nodiscard]] friend constexpr auto operator<=>(weak_ordering v, nullptr_t) noexcept -> weak_ordering { return v; }
61
62 [[nodiscard]] friend constexpr auto operator<=>(nullptr_t, weak_ordering v) noexcept -> weak_ordering
63 {
64 return v < nullptr ? weak_ordering::greater : (v > nullptr ? weak_ordering::less : v);
65 }
66
67private:
68 explicit constexpr weak_ordering(detail::order_result v) noexcept
69 : _value{static_cast<int8_t>(v)}
70 {
71 }
72
73 int8_t _value;
74};
75
76inline constexpr weak_ordering weak_ordering::less{detail::order_result::less};
77inline constexpr weak_ordering weak_ordering::equivalent{detail::order_result::equal};
78inline constexpr weak_ordering weak_ordering::greater{detail::order_result::greater};
79
80} // namespace etl
81
82#endif // TETL_COMPARE_WEAK_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 weak_ordering.hpp:13
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:48
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:41
friend constexpr auto operator<=(weak_ordering v, nullptr_t) noexcept -> bool
Definition weak_ordering.hpp:34
static weak_ordering const equivalent
Definition weak_ordering.hpp:16
friend constexpr auto operator>(weak_ordering v, nullptr_t) noexcept -> bool
Definition weak_ordering.hpp:39
friend constexpr auto operator<=>(weak_ordering v, nullptr_t) noexcept -> weak_ordering
Definition weak_ordering.hpp:60
friend constexpr auto operator<(nullptr_t, weak_ordering v) noexcept -> bool
Definition weak_ordering.hpp:46
friend constexpr auto operator>(nullptr_t, weak_ordering v) noexcept -> bool
Definition weak_ordering.hpp:53
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:55
friend constexpr auto operator<=>(nullptr_t, weak_ordering v) noexcept -> weak_ordering
Definition weak_ordering.hpp:62
friend constexpr auto operator==(weak_ordering, weak_ordering) noexcept -> bool=default
static weak_ordering const less
Definition weak_ordering.hpp:15