| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
#pragma once |
| 32 |
|
| 33 |
#include "core/typedefs.h" |
| 34 |
|
| 35 |
template <typename F, typename S> |
| 36 |
struct Pair { |
| 37 |
F first{}; |
| 38 |
S second{}; |
| 39 |
|
| 40 |
constexpr Pair() = default; |
| 41 |
constexpr Pair(const F &p_first, const S &p_second) : |
| 42 |
first(p_first), second(p_second) {} |
| 43 |
|
| 44 |
constexpr bool operator==(const Pair &p_other) const { return first == p_other.first && second == p_other.second; } |
| 45 |
constexpr bool operator!=(const Pair &p_other) const { return first != p_other.first || second != p_other.second; } |
| 46 |
constexpr bool operator<(const Pair &p_other) const { return first == p_other.first ? (second < p_other.second) : (first < p_other.first); } |
| 47 |
constexpr bool operator<=(const Pair &p_other) const { return first == p_other.first ? (second <= p_other.second) : (first < p_other.first); } |
| 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 |
}; |
| 51 |
|
| 52 |
template <typename F, typename S> |
| 53 |
struct PairSort { |
| 54 |
constexpr bool operator()(const Pair<F, S> &p_lhs, const Pair<F, S> &p_rhs) const { |
| 55 |
return p_lhs < p_rhs; |
| 56 |
} |
| 57 |
}; |
| 58 |
|
| 59 |
|
| 60 |
template <typename F, typename S> |
| 61 |
struct is_zero_constructible<Pair<F, S>> : std::conjunction<is_zero_constructible<F>, is_zero_constructible<S>> {}; |
| 62 |
|
| 63 |
template <typename K, typename V> |
| 64 |
struct KeyValue { |
| 65 |
const K key{}; |
| 66 |
V value{}; |
| 67 |
|
| 68 |
KeyValue &operator=(const KeyValue &p_kv) = delete; |
| 69 |
KeyValue &operator=(KeyValue &&p_kv) = delete; |
| 70 |
|
| 71 |
constexpr KeyValue(const KeyValue &p_kv) = default; |
| 72 |
constexpr KeyValue(KeyValue &&p_kv) = default; |
| 73 |
constexpr KeyValue(const K &p_key, const V &p_value) : |
| 74 |
key(p_key), value(p_value) {} |
| 75 |
constexpr KeyValue(const Pair<K, V> &p_pair) : |
| 76 |
key(p_pair.first), value(p_pair.second) {} |
| 77 |
|
| 78 |
constexpr bool operator==(const KeyValue &p_other) const { return key == p_other.key && value == p_other.value; } |
| 79 |
constexpr bool operator!=(const KeyValue &p_other) const { return key != p_other.key || value != p_other.value; } |
| 80 |
constexpr bool operator<(const KeyValue &p_other) const { return key == p_other.key ? (value < p_other.value) : (key < p_other.key); } |
| 81 |
constexpr bool operator<=(const KeyValue &p_other) const { return key == p_other.key ? (value <= p_other.value) : (key < p_other.key); } |
| 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 |
}; |
| 85 |
|
| 86 |
template <typename K, typename V> |
| 87 |
struct KeyValueSort { |
| 88 |
constexpr bool operator()(const KeyValue<K, V> &p_lhs, const KeyValue<K, V> &p_rhs) const { |
| 89 |
return p_lhs.key < p_rhs.key; |
| 90 |
} |
| 91 |
}; |
| 92 |
|
| 93 |
|
| 94 |
template <typename K, typename V> |
| 95 |
struct is_zero_constructible<KeyValue<K, V>> : std::conjunction<is_zero_constructible<K>, is_zero_constructible<V>> {}; |