Can anyone explain boost intrusive hooks concept? i don't understand reading the documentation http://www.boost.org/doc/libs/1_47_0/doc/html/intrusive.html
Boost.intrusive forces you to provide information along the objects you want to store in an intrusive container.
Hooks are the way to provide the required information to the associated intrusive container. To do so, the class defining the objects you want to store can either inherit from the hook or own it as a member.
As long as the intrusive container needs to be fully known at compile time, hooks are parameterized using templates, which leads to a syntax where the option is a template class and the associated value is its parameter.
For instance, you can define the link mode by specifying the link_mode parameter in the template parameters list and set its value:
boost::intrusive::list< MyClass, boost::intrusive::link_mode< boost::intrusive::safe_link > > l;
Last but not least, if your hook contains non-default values, you will have to pass it as a template parameter to the intrusive container class you use.
Considering intrusive list for example, this means replacing
boost::intrusive::list<MyClass> l;
by
boost::intrusive::list<MyClass, MyHook> l;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With