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// SPDX-FileCopyrightText: Copyright (C) 2021 Tobias Hienzsch
3
4#ifndef TETL_COMPARE_STRONG_ORDERING_HPP
5#define TETL_COMPARE_STRONG_ORDERING_HPP
6
7#include <etl/_compare/detail.hpp>
8#include <etl/_compare/partial_ordering.hpp>
9#include <etl/_compare/weak_ordering.hpp>
10#include <etl/_cstddef/nullptr_t.hpp>
11
12namespace etl {
13
14/// \ingroup compare
16 static strong_ordering const less;
17 static strong_ordering const equal;
20
21 [[nodiscard]] constexpr operator partial_ordering() const noexcept
22 {
23 return _value == 0 ? partial_ordering::equivalent
25 }
26
27 [[nodiscard]] constexpr operator weak_ordering() const noexcept
28 {
29 return _value == 0 ? weak_ordering::equivalent : (_value < 0 ? weak_ordering::less : weak_ordering::greater);
30 }
31
32 [[nodiscard]] friend constexpr auto operator==(strong_ordering, strong_ordering) noexcept -> bool = default;
33
34 [[nodiscard]] friend constexpr auto operator==(strong_ordering v, nullptr_t) noexcept -> bool
35 {
36 return v._value == 0;
37 }
38
39 [[nodiscard]] friend constexpr auto operator<(strong_ordering v, nullptr_t) noexcept -> bool
40 {
41 return v._value < 0;
42 }
43
44 [[nodiscard]] friend constexpr auto operator<=(strong_ordering v, nullptr_t) noexcept -> bool
45 {
46 return v._value <= 0;
47 }
48
49 [[nodiscard]] friend constexpr auto operator>(strong_ordering v, nullptr_t) noexcept -> bool
50 {
51 return v._value > 0;
52 }
53
54 [[nodiscard]] friend constexpr auto operator>=(strong_ordering v, nullptr_t) noexcept -> bool
55 {
56 return v._value >= 0;
57 }
58
59 [[nodiscard]] friend constexpr auto operator<(nullptr_t, strong_ordering v) noexcept -> bool
60 {
61 return 0 < v._value;
62 }
63
64 [[nodiscard]] friend constexpr auto operator<=(nullptr_t, strong_ordering v) noexcept -> bool
65 {
66 return 0 <= v._value;
67 }
68
69 [[nodiscard]] friend constexpr auto operator>(nullptr_t, strong_ordering v) noexcept -> bool
70 {
71 return 0 > v._value;
72 }
73
74 [[nodiscard]] friend constexpr auto operator>=(nullptr_t, strong_ordering v) noexcept -> bool
75 {
76 return 0 >= v._value;
77 }
78
79 [[nodiscard]] friend constexpr auto operator<=>(strong_ordering v, nullptr_t) noexcept -> strong_ordering
80 {
81 return v;
82 }
83
84 [[nodiscard]] friend constexpr auto operator<=>(nullptr_t, strong_ordering v) noexcept -> strong_ordering
85 {
86 return v < nullptr ? strong_ordering::greater : (v > nullptr ? strong_ordering::less : v);
87 }
88
89private:
90 constexpr explicit strong_ordering(detail::order_result v) noexcept
91 : _value{static_cast<int8_t>(v)}
92 {
93 }
94
95 int8_t _value;
96};
97
98inline constexpr strong_ordering strong_ordering::less{detail::order_result::less};
99inline constexpr strong_ordering strong_ordering::equal{detail::order_result::equal};
100inline constexpr strong_ordering strong_ordering::equivalent{detail::order_result::equal};
101inline constexpr strong_ordering strong_ordering::greater{detail::order_result::greater};
102
103} // namespace etl
104
105#endif // TETL_COMPARE_STRONG_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 strong_ordering.hpp:15
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:64
friend constexpr auto operator<=>(strong_ordering v, nullptr_t) noexcept -> strong_ordering
Definition strong_ordering.hpp:79
friend constexpr auto operator>=(nullptr_t, strong_ordering v) noexcept -> bool
Definition strong_ordering.hpp:74
static strong_ordering const less
Definition strong_ordering.hpp:16
friend constexpr auto operator<=>(nullptr_t, strong_ordering v) noexcept -> strong_ordering
Definition strong_ordering.hpp:84
constexpr operator partial_ordering() const noexcept
Definition strong_ordering.hpp:21
friend constexpr auto operator<(strong_ordering v, nullptr_t) noexcept -> bool
Definition strong_ordering.hpp:39
static strong_ordering const greater
Definition strong_ordering.hpp:19
static strong_ordering const equivalent
Definition strong_ordering.hpp:18
static strong_ordering const equal
Definition strong_ordering.hpp:17
constexpr operator weak_ordering() const noexcept
Definition strong_ordering.hpp:27
friend constexpr auto operator>(nullptr_t, strong_ordering v) noexcept -> bool
Definition strong_ordering.hpp:69
friend constexpr auto operator>(strong_ordering v, nullptr_t) noexcept -> bool
Definition strong_ordering.hpp:49
friend constexpr auto operator==(strong_ordering v, nullptr_t) noexcept -> bool
Definition strong_ordering.hpp:34
friend constexpr auto operator<(nullptr_t, strong_ordering v) noexcept -> bool
Definition strong_ordering.hpp:59
friend constexpr auto operator>=(strong_ordering v, nullptr_t) noexcept -> bool
Definition strong_ordering.hpp:54
friend constexpr auto operator<=(strong_ordering v, nullptr_t) noexcept -> bool
Definition strong_ordering.hpp:44
Definition weak_ordering.hpp:14
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