Skip to content

Commit bd2cc87

Browse files
committed
Use spaceship operator to simplify map_proxy
1 parent dac8c7a commit bd2cc87

File tree

1 file changed

+6
-14
lines changed

1 file changed

+6
-14
lines changed

include/bencode.hpp

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -132,24 +132,16 @@ namespace bencode {
132132
auto key_comp() const { return proxy_->key_comp(); }
133133
auto value_comp() const { return proxy_->value_comp(); }
134134

135+
friend bool operator ==(const map_proxy &lhs, const map_proxy &rhs) {
136+
return *lhs == *rhs;
137+
}
138+
friend auto operator <=>(const map_proxy &lhs, const map_proxy &rhs) {
139+
return *lhs <=> *rhs;
140+
}
135141
private:
136142
std::unique_ptr<map_type> proxy_;
137143
};
138144

139-
#define BENCODE_MAP_PROXY_RELOP(op) \
140-
template<typename Key, typename Value> \
141-
bool operator op(const map_proxy<Key, Value> &lhs, \
142-
const map_proxy<Key, Value> &rhs) { \
143-
return *lhs == *rhs; \
144-
}
145-
146-
BENCODE_MAP_PROXY_RELOP(==)
147-
BENCODE_MAP_PROXY_RELOP(!=)
148-
BENCODE_MAP_PROXY_RELOP(>=)
149-
BENCODE_MAP_PROXY_RELOP(<=)
150-
BENCODE_MAP_PROXY_RELOP(>)
151-
BENCODE_MAP_PROXY_RELOP(<)
152-
153145
#define BENCODE_DATA_GETTER(func, impl, arg_type, container_type) \
154146
basic_data & func(const arg_type &key) & { \
155147
return impl<container_type>(*this, key); \

0 commit comments

Comments
 (0)