util/IntrusiveList: use const_cast to eliminate duplicate HookTraits functions
I hate const_cast, but what I hate more is duplicate code. Sigh.
This commit is contained in:
parent
7b3d870516
commit
f1dc1af85d
|
@ -140,18 +140,9 @@ struct IntrusiveListBaseHookTraits {
|
|||
return static_cast<T *>(hook);
|
||||
}
|
||||
|
||||
static constexpr const T *Cast(const IntrusiveListNode *node) noexcept {
|
||||
const auto *hook = &Hook<T>::Cast(*node);
|
||||
return static_cast<const T *>(hook);
|
||||
}
|
||||
|
||||
static constexpr auto &ToHook(T &t) noexcept {
|
||||
return static_cast<Hook<T> &>(t);
|
||||
}
|
||||
|
||||
static constexpr const auto &ToHook(const T &t) noexcept {
|
||||
return static_cast<const Hook<T> &>(t);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -172,18 +163,9 @@ struct IntrusiveListMemberHookTraits {
|
|||
return &ContainerCast(hook, member);
|
||||
}
|
||||
|
||||
static constexpr const T *Cast(const IntrusiveListNode *node) noexcept {
|
||||
const auto &hook = Hook::Cast(*node);
|
||||
return &ContainerCast(hook, member);
|
||||
}
|
||||
|
||||
static constexpr auto &ToHook(T &t) noexcept {
|
||||
return t.*member;
|
||||
}
|
||||
|
||||
static constexpr const auto &ToHook(const T &t) noexcept {
|
||||
return t.*member;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -207,7 +189,7 @@ class IntrusiveList {
|
|||
}
|
||||
|
||||
static constexpr const T *Cast(const IntrusiveListNode *node) noexcept {
|
||||
return HookTraits::Cast(node);
|
||||
return HookTraits::Cast(const_cast<IntrusiveListNode *>(node));
|
||||
}
|
||||
|
||||
static constexpr auto &ToHook(T &t) noexcept {
|
||||
|
|
Loading…
Reference in New Issue