DoublyLinkedList: Make DoublyLinkedListCLink more useful.

Before, it just used a hardcoded Element::link member. Now,
it uses whatever one is specified based on the template
arguments.

No source compatibility breakage intended.

Change-Id: I62128921766df0b705488eb64402f902334f2ed0
Reviewed-on: https://review.haiku-os.org/c/haiku/+/10589
Reviewed-by: waddlesplash <[email protected]>
Tested-by: Commit checker robot <[email protected]>
Haiku-Format: Haiku-format Bot <[email protected]>
This commit is contained in:
Augustin Cavalier
2026-03-30 22:11:53 +00:00
committed by waddlesplash
parent 397b2e8189
commit 15594f62fe
+14 -13
View File
@@ -83,22 +83,23 @@ public:
} }
}; };
// DoublyLinkedListCLink - interface to struct list // DoublyLinkedListCLink - interface to struct list (or equivalent)
template<typename Element> template<typename Element, typename CLink = struct list_link,
CLink Element::* LinkMember = &Element::link>
class DoublyLinkedListCLink { class DoublyLinkedListCLink {
private: private:
typedef DoublyLinkedListLink<Element> Link; typedef DoublyLinkedListLink<Element> Link;
public: public:
inline Link* operator()(Element* element) const inline Link* operator()(Element* element) const
{ {
return (Link*)&element->link; return (Link*)&(element->*LinkMember);
} }
inline const Link* operator()(const Element* element) const inline const Link* operator()(const Element* element) const
{ {
return (const Link*)&element->link; return (Link*)&(element->*LinkMember);
} }
}; };
// for convenience // for convenience