From 5a0b3927a33807cca4c77c40eb873f8a3b51b0b0 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 29 Apr 2023 19:07:11 +0100 Subject: Drop .hpp for header only things Half of them acquired a .cpp part anyway --- lib/sorting.h | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 lib/sorting.h (limited to 'lib/sorting.h') diff --git a/lib/sorting.h b/lib/sorting.h new file mode 100644 index 0000000..777de00 --- /dev/null +++ b/lib/sorting.h @@ -0,0 +1,49 @@ +#pragma once + +#include +#include + +template struct PtrSorter { + bool + operator()(const T & a, const T & b) const + { + return *a < *b; + } +}; + +template struct PtrMemberSorter : public PtrSorter { + using MT = std::decay_t; + using is_transparent = MT; + + using PtrSorter::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; + } +}; + +struct CompareBy { + glm::length_t index; + + template + auto + operator()(const T & a, const T & b) const + { + return get(a) < get(b); + } + + template + auto + get(const T & a) const + { + return a[index]; + } +}; -- cgit v1.2.3