From f1dc1af85d211a568b8ded022effe487474f0d87 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sat, 12 Nov 2022 08:44:54 +0100 Subject: [PATCH] util/IntrusiveList: use const_cast to eliminate duplicate HookTraits functions I hate const_cast, but what I hate more is duplicate code. Sigh. --- src/util/IntrusiveList.hxx | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-) diff --git a/src/util/IntrusiveList.hxx b/src/util/IntrusiveList.hxx index 58e563b65..570440b38 100644 --- a/src/util/IntrusiveList.hxx +++ b/src/util/IntrusiveList.hxx @@ -140,18 +140,9 @@ struct IntrusiveListBaseHookTraits { return static_cast(hook); } - static constexpr const T *Cast(const IntrusiveListNode *node) noexcept { - const auto *hook = &Hook::Cast(*node); - return static_cast(hook); - } - static constexpr auto &ToHook(T &t) noexcept { return static_cast &>(t); } - - static constexpr const auto &ToHook(const T &t) noexcept { - return static_cast &>(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(node)); } static constexpr auto &ToHook(T &t) noexcept {