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