|
30 | 30 |
|
31 | 31 | #pragma once
|
32 | 32 |
|
33 |
| -#include <godot_cpp/templates/hashfuncs.hpp> |
| 33 | +#include <godot_cpp/core/defs.hpp> |
34 | 34 |
|
35 | 35 | namespace godot {
|
36 | 36 |
|
37 | 37 | template <typename F, typename S>
|
38 | 38 | struct Pair {
|
39 |
| - F first; |
40 |
| - S second; |
41 |
| - |
42 |
| - Pair() : |
43 |
| - first(), |
44 |
| - second() { |
45 |
| - } |
46 |
| - |
47 |
| - Pair(F p_first, const S &p_second) : |
48 |
| - first(p_first), |
49 |
| - second(p_second) { |
50 |
| - } |
| 39 | + F first{}; |
| 40 | + S second{}; |
| 41 | + |
| 42 | + constexpr Pair() = default; |
| 43 | + constexpr Pair(const F &p_first, const S &p_second) : |
| 44 | + first(p_first), second(p_second) {} |
| 45 | + |
| 46 | + constexpr bool operator==(const Pair &p_other) const { return first == p_other.first && second == p_other.second; } |
| 47 | + constexpr bool operator!=(const Pair &p_other) const { return first != p_other.first || second != p_other.second; } |
| 48 | + constexpr bool operator<(const Pair &p_other) const { return first == p_other.first ? (second < p_other.second) : (first < p_other.first); } |
| 49 | + constexpr bool operator<=(const Pair &p_other) const { return first == p_other.first ? (second <= p_other.second) : (first < p_other.first); } |
| 50 | + constexpr bool operator>(const Pair &p_other) const { return first == p_other.first ? (second > p_other.second) : (first > p_other.first); } |
| 51 | + constexpr bool operator>=(const Pair &p_other) const { return first == p_other.first ? (second >= p_other.second) : (first > p_other.first); } |
51 | 52 | };
|
52 | 53 |
|
53 |
| -template <typename F, typename S> |
54 |
| -bool operator==(const Pair<F, S> &pair, const Pair<F, S> &other) { |
55 |
| - return (pair.first == other.first) && (pair.second == other.second); |
56 |
| -} |
57 |
| - |
58 |
| -template <typename F, typename S> |
59 |
| -bool operator!=(const Pair<F, S> &pair, const Pair<F, S> &other) { |
60 |
| - return (pair.first != other.first) || (pair.second != other.second); |
61 |
| -} |
62 |
| - |
63 | 54 | template <typename F, typename S>
|
64 | 55 | struct PairSort {
|
65 |
| - bool operator()(const Pair<F, S> &A, const Pair<F, S> &B) const { |
66 |
| - if (A.first != B.first) { |
67 |
| - return A.first < B.first; |
68 |
| - } |
69 |
| - return A.second < B.second; |
| 56 | + constexpr bool operator()(const Pair<F, S> &p_lhs, const Pair<F, S> &p_rhs) const { |
| 57 | + return p_lhs < p_rhs; |
70 | 58 | }
|
71 | 59 | };
|
72 | 60 |
|
| 61 | +// Pair is zero-constructible if and only if both constrained types are zero-constructible. |
73 | 62 | template <typename F, typename S>
|
74 |
| -struct PairHash { |
75 |
| - static uint32_t hash(const Pair<F, S> &P) { |
76 |
| - uint64_t h1 = HashMapHasherDefault::hash(P.first); |
77 |
| - uint64_t h2 = HashMapHasherDefault::hash(P.second); |
78 |
| - return hash_one_uint64((h1 << 32) | h2); |
79 |
| - } |
80 |
| -}; |
| 63 | +struct is_zero_constructible<Pair<F, S>> : std::conjunction<is_zero_constructible<F>, is_zero_constructible<S>> {}; |
81 | 64 |
|
82 | 65 | template <typename K, typename V>
|
83 | 66 | struct KeyValue {
|
84 |
| - const K key; |
85 |
| - V value; |
86 |
| - |
87 |
| - void operator=(const KeyValue &p_kv) = delete; |
88 |
| - _FORCE_INLINE_ KeyValue(const KeyValue &p_kv) : |
89 |
| - key(p_kv.key), |
90 |
| - value(p_kv.value) { |
91 |
| - } |
92 |
| - _FORCE_INLINE_ KeyValue(const K &p_key, const V &p_value) : |
93 |
| - key(p_key), |
94 |
| - value(p_value) { |
95 |
| - } |
| 67 | + const K key{}; |
| 68 | + V value{}; |
| 69 | + |
| 70 | + KeyValue &operator=(const KeyValue &p_kv) = delete; |
| 71 | + KeyValue &operator=(KeyValue &&p_kv) = delete; |
| 72 | + |
| 73 | + constexpr KeyValue(const KeyValue &p_kv) = default; |
| 74 | + constexpr KeyValue(KeyValue &&p_kv) = default; |
| 75 | + constexpr KeyValue(const K &p_key, const V &p_value) : |
| 76 | + key(p_key), value(p_value) {} |
| 77 | + constexpr KeyValue(const Pair<K, V> &p_pair) : |
| 78 | + key(p_pair.first), value(p_pair.second) {} |
| 79 | + |
| 80 | + constexpr bool operator==(const KeyValue &p_other) const { return key == p_other.key && value == p_other.value; } |
| 81 | + constexpr bool operator!=(const KeyValue &p_other) const { return key != p_other.key || value != p_other.value; } |
| 82 | + constexpr bool operator<(const KeyValue &p_other) const { return key == p_other.key ? (value < p_other.value) : (key < p_other.key); } |
| 83 | + constexpr bool operator<=(const KeyValue &p_other) const { return key == p_other.key ? (value <= p_other.value) : (key < p_other.key); } |
| 84 | + constexpr bool operator>(const KeyValue &p_other) const { return key == p_other.key ? (value > p_other.value) : (key > p_other.key); } |
| 85 | + constexpr bool operator>=(const KeyValue &p_other) const { return key == p_other.key ? (value >= p_other.value) : (key > p_other.key); } |
96 | 86 | };
|
97 | 87 |
|
98 |
| -template <typename K, typename V> |
99 |
| -bool operator==(const KeyValue<K, V> &pair, const KeyValue<K, V> &other) { |
100 |
| - return (pair.key == other.key) && (pair.value == other.value); |
101 |
| -} |
102 |
| - |
103 |
| -template <typename K, typename V> |
104 |
| -bool operator!=(const KeyValue<K, V> &pair, const KeyValue<K, V> &other) { |
105 |
| - return (pair.key != other.key) || (pair.value != other.value); |
106 |
| -} |
107 |
| - |
108 | 88 | template <typename K, typename V>
|
109 | 89 | struct KeyValueSort {
|
110 |
| - bool operator()(const KeyValue<K, V> &A, const KeyValue<K, V> &B) const { |
111 |
| - return A.key < B.key; |
| 90 | + constexpr bool operator()(const KeyValue<K, V> &p_lhs, const KeyValue<K, V> &p_rhs) const { |
| 91 | + return p_lhs.key < p_rhs.key; |
112 | 92 | }
|
113 | 93 | };
|
114 | 94 |
|
| 95 | +// KeyValue is zero-constructible if and only if both constrained types are zero-constructible. |
| 96 | +template <typename K, typename V> |
| 97 | +struct is_zero_constructible<KeyValue<K, V>> : std::conjunction<is_zero_constructible<K>, is_zero_constructible<V>> {}; |
| 98 | + |
115 | 99 | } // namespace godot
|
0 commit comments