From 6d16749c5c4950ca4480bc0908a602f38e21cea0 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 5 Jan 2025 19:18:40 +0000 Subject: Add helper for sorting sorted containers by a projection --- lib/sorting.h | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'lib') 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 #include #include @@ -30,6 +31,14 @@ template struct PtrMemberSorter : public PtrSorter { } }; +template 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; -- cgit v1.2.3