Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Boost Intrusive List hook

What is the difference in a base hook and a member hook in Boost::Intrusive library and when is one better to use then the other?

I've read the boost documentation, but its not that explanatory.

like image 706
Tony The Lion Avatar asked Sep 29 '10 11:09

Tony The Lion


3 Answers

As far as I can tell it is a matter of style and object-oriented design. Base hooks intrude upon the inheritance hierarchy, necessitating an extra public parent class and possibly forcing multiple inheritance upon the design. Using member hooks allows the programmer to treat an object as having a has-a relation with a container, rather than an is-a relation with container membership.

like image 132
Fred Foo Avatar answered Sep 28 '22 07:09

Fred Foo


imho if your object is intended to be included into single container only, base hook seems more convinient. Otherwise (for multiple containers), multiple member hooks provide less ambigious solution (since multiple inheritance is avoided)

like image 45
user396672 Avatar answered Sep 28 '22 06:09

user396672


http://www.boost.org/doc/libs/1_47_0/doc/html/intrusive/recursive.html "Member hooks are not suitable for recursive structures"

like image 45
xnx Avatar answered Sep 28 '22 05:09

xnx