summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2025-01-05 19:18:40 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2025-01-05 19:18:40 +0000
commit6d16749c5c4950ca4480bc0908a602f38e21cea0 (patch)
tree4af628dec6ad783e5e4e368f838d89135e4d0b7a
parentAdd helper for merging close elements in a vector (diff)
downloadilt-6d16749c5c4950ca4480bc0908a602f38e21cea0.tar.bz2
ilt-6d16749c5c4950ca4480bc0908a602f38e21cea0.tar.xz
ilt-6d16749c5c4950ca4480bc0908a602f38e21cea0.zip
Add helper for sorting sorted containers by a projection
-rw-r--r--lib/sorting.h9
1 files changed, 9 insertions, 0 deletions
diff --git a/lib/sorting.h b/lib/sorting.h
index 777de00..be5a7e2 100644
--- a/lib/sorting.h
+++ b/lib/sorting.h
@@ -1,5 +1,6 @@
#pragma once
+#include <functional>
#include <glm/fwd.hpp>
#include <type_traits>
@@ -30,6 +31,14 @@ template<typename T, auto M> struct PtrMemberSorter : public PtrSorter<T> {
}
};
+template<auto Proj> struct SortedBy {
+ auto
+ operator()(const auto & left, const auto & right) const
+ {
+ return (std::invoke(Proj, left) < std::invoke(Proj, right));
+ }
+};
+
struct CompareBy {
glm::length_t index;