From dca03e5e3645b088a01446b2ed71b51eb7f7b493 Mon Sep 17 00:00:00 2001 From: Goober5000 Date: Wed, 12 Nov 2025 21:48:34 -0500 Subject: [PATCH] configurable sets Add the ability to configure the `less` operator for `SCP_set`, `SCP_map`, and so forth. Add an `ID_Less` functor so that the type-safe `ID` class can be used with these data structures. --- code/globalincs/vmallocator.h | 20 ++++++++++---------- code/utils/id.h | 9 +++++++++ 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/code/globalincs/vmallocator.h b/code/globalincs/vmallocator.h index 191e0771007..131fddbdf09 100644 --- a/code/globalincs/vmallocator.h +++ b/code/globalincs/vmallocator.h @@ -97,11 +97,11 @@ extern bool lcase_equal(const SCP_string& _Left, const SCP_string& _Right); extern bool lcase_lessthan(const SCP_string& _Left, const SCP_string& _Right); -template -using SCP_map = std::map, std::allocator>>; +template > +using SCP_map = std::map>>; -template -using SCP_multimap = std::multimap, std::allocator>>; +template > +using SCP_multimap = std::multimap>>; template using SCP_queue = std::queue>>; @@ -109,11 +109,11 @@ using SCP_queue = std::queue>>; template using SCP_deque = std::deque>; -template -class SCP_set : public std::set, std::allocator> +template > +class SCP_set : public std::set> { public: - using std::set, std::allocator>::set; // inherit all constructors + using std::set>::set; // inherit all constructors bool contains(const T& item) const { @@ -121,11 +121,11 @@ class SCP_set : public std::set, std::allocator> } }; -template -class SCP_multiset : public std::multiset, std::allocator> +template > +class SCP_multiset : public std::multiset> { public: - using std::multiset, std::allocator>::multiset; // inherit all constructors + using std::multiset>::multiset; // inherit all constructors bool contains(const T& item) const { diff --git a/code/utils/id.h b/code/utils/id.h index fd66f561ab8..37915029d33 100644 --- a/code/utils/id.h +++ b/code/utils/id.h @@ -61,4 +61,13 @@ struct ID_Hash } }; +struct ID_Less +{ + template + bool operator()(const ID &lhs, const ID &rhs) const + { + return std::less{}(lhs.value(), rhs.value()); + } +}; + }