diff options
Diffstat (limited to 'lib/sorting.h')
-rw-r--r-- | lib/sorting.h | 49 |
1 files changed, 49 insertions, 0 deletions
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 <glm/fwd.hpp> +#include <type_traits> + +template<typename T> struct PtrSorter { + bool + operator()(const T & a, const T & b) const + { + 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; + } +}; + +struct CompareBy { + glm::length_t index; + + template<typename T> + auto + operator()(const T & a, const T & b) const + { + return get(a) < get(b); + } + + template<typename T> + auto + get(const T & a) const + { + return a[index]; + } +}; |