From add9c468686e2ec2aefef7b9e2626063a535ded9 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 comparison operators to the type-safe `ID` class so that it can be used with these data structures. --- code/globalincs/vmallocator.h | 20 ++++++++++---------- code/utils/id.h | 5 +++++ 2 files changed, 15 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..2dc3a0985f4 100644 --- a/code/utils/id.h +++ b/code/utils/id.h @@ -41,6 +41,11 @@ class ID friend bool operator==(ID a, ID b) { return a.m_val == b.m_val; } friend bool operator!=(ID a, ID b) { return a.m_val != b.m_val; } + friend bool operator< (ID a, ID b) { return a.m_val < b.m_val; } + friend bool operator<=(ID a, ID b) { return a.m_val <= b.m_val; } + friend bool operator> (ID a, ID b) { return a.m_val > b.m_val; } + friend bool operator>=(ID a, ID b) { return a.m_val >= b.m_val; } + friend std::ostream& operator<< (std::ostream& stream, const ID& id) { stream << id.value(); return stream;