Iros
 
Loading...
Searching...
No Matches
weak_ordering.h
Go to the documentation of this file.
1#pragma once
2
5
6#ifndef DI_NO_USE_STD
7#include <compare>
8#else
9namespace std {
10class weak_ordering {
11public:
12 static weak_ordering const less;
13 static weak_ordering const equivalent;
14 static weak_ordering const greater;
15
16 constexpr friend auto operator==(weak_ordering v, weak_ordering w) -> bool { return v.m_value == w.m_value; }
17 constexpr friend auto operator==(weak_ordering v, int) -> bool { return v.m_value == 0; }
18
19 constexpr friend auto operator<(weak_ordering v, int) -> bool { return v.m_value < 0; }
20 constexpr friend auto operator<(int, weak_ordering v) -> bool { return v.m_value > 0; }
21
22 constexpr friend auto operator<=(weak_ordering v, int) -> bool { return v == 0 || v < 0; }
23 constexpr friend auto operator<=(int, weak_ordering v) -> bool { return v == 0 || 0 < v; }
24
25 constexpr friend auto operator>(weak_ordering v, int) -> bool { return 0 < v; }
26 constexpr friend auto operator>(int, weak_ordering v) -> bool { return v < 0; }
27
28 constexpr friend auto operator>=(weak_ordering v, int) -> bool { return 0 <= v; }
29 constexpr friend auto operator>=(int, weak_ordering v) -> bool { return v <= 0; }
30
31 constexpr friend auto operator<=>(weak_ordering v, int) -> weak_ordering { return v; }
32 constexpr friend auto operator<=>(int, weak_ordering v) -> weak_ordering { return weak_ordering(char(-v.m_value)); }
33
34 constexpr operator partial_ordering() const { return partial_ordering(m_value); }
35
36private:
37 friend class strong_ordering;
38
39 explicit constexpr weak_ordering(char value) : m_value(value) {}
40 explicit constexpr weak_ordering(di::types::detail::CompareOutcome value) : m_value(static_cast<char>(value)) {}
41
42 char m_value;
43};
44
45constexpr inline weak_ordering weak_ordering::less(di::types::detail::CompareOutcome::Less);
46constexpr inline weak_ordering weak_ordering::equivalent(di::types::detail::CompareOutcome::Equal);
47constexpr inline weak_ordering weak_ordering::greater(di::types::detail::CompareOutcome::Greater);
48}
49#endif
50
51namespace di::types {
52using std::weak_ordering;
53}
54
55namespace di {
56using types::weak_ordering;
57}
constexpr auto operator==(Duration< Rep1, Period1 > const &a, Duration< Rep2, Period2 > const &b) -> bool
Definition duration.h:108
constexpr auto operator<=>(Duration< Rep1, Period1 > const &a, Duration< Rep2, Period2 > const &b)
Definition duration.h:115
constexpr auto less
Definition less.h:23
constexpr auto value
Definition value.h:34
constexpr auto greater
Definition greater.h:23
CompareOutcome
Definition compare_outcome.h:5
@ Less
Definition compare_outcome.h:5
@ Greater
Definition compare_outcome.h:5
@ Equal
Definition compare_outcome.h:5
Definition method.h:5
Definition zstring_parser.h:9
Definition enable_generate_structed_bindings.h:46