util/Intrusive*: move constant_time_size to an options struct

This makes it easier to add more options later.
This commit is contained in:
Max Kellermann
2023-09-11 18:48:21 +02:00
committed by Max Kellermann
parent 1f495efb46
commit f01793ad4a
8 changed files with 44 additions and 31 deletions

View File

@@ -13,6 +13,10 @@
#include <type_traits>
#include <utility>
struct IntrusiveListOptions {
bool constant_time_size = false;
};
struct IntrusiveListNode {
IntrusiveListNode *next, *prev;
@@ -27,7 +31,7 @@ template<IntrusiveHookMode _mode=IntrusiveHookMode::NORMAL>
class IntrusiveListHook {
template<typename T> friend struct IntrusiveListBaseHookTraits;
template<auto member> friend struct IntrusiveListMemberHookTraits;
template<typename T, typename HookTraits, bool> friend class IntrusiveList;
template<typename T, typename HookTraits, IntrusiveListOptions> friend class IntrusiveList;
protected:
IntrusiveListNode siblings;
@@ -135,8 +139,10 @@ struct IntrusiveListMemberHookTraits {
*/
template<typename T,
typename HookTraits=IntrusiveListBaseHookTraits<T>,
bool constant_time_size=false>
IntrusiveListOptions options=IntrusiveListOptions{}>
class IntrusiveList {
static constexpr bool constant_time_size = options.constant_time_size;
IntrusiveListNode head{&head, &head};
[[no_unique_address]]