summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--game/network/network.h2
-rw-r--r--lib/sorting.hpp21
2 files changed, 22 insertions, 1 deletions
diff --git a/game/network/network.h b/game/network/network.h
index 79a4a2b..34e6a60 100644
--- a/game/network/network.h
+++ b/game/network/network.h
@@ -37,7 +37,7 @@ public:
protected:
static void joinLinks(const LinkPtr & l, const LinkPtr & ol);
- using Nodes = std::set<NodePtr, PtrSorter<NodePtr>>;
+ using Nodes = std::set<NodePtr, PtrMemberSorter<NodePtr, &Node::pos>>;
Nodes nodes;
std::shared_ptr<Texture> texture;
};
diff --git a/lib/sorting.hpp b/lib/sorting.hpp
index 6b9be6a..0604aaf 100644
--- a/lib/sorting.hpp
+++ b/lib/sorting.hpp
@@ -1,5 +1,7 @@
#pragma once
+#include <type_traits>
+
template<typename T> struct PtrSorter {
bool
operator()(const T & a, const T & b) const
@@ -7,3 +9,22 @@ template<typename T> struct PtrSorter {
return *a < *b;
}
};
+
+template<typename T, auto M> struct PtrMemberSorter : public PtrSorter<T> {
+ using MT = std::decay_t<decltype((*T {}).*M)>;
+ using is_transparent = MT;
+
+ using PtrSorter<T>::operator();
+
+ bool
+ operator()(const MT & a, const T & b) const
+ {
+ return a < (*b).*M;
+ }
+
+ bool
+ operator()(const T & a, const MT & b) const
+ {
+ return (*a).*M < b;
+ }
+};