I’m currently trying to learn how to use boost library and I’ve stumbled upon a problem with boost::intrusive::splay_set (or splaytree in that matter).
Let’s assume I want to have splay tree that keeps pointers to Category class (so Category*). I’m trying to write following
splay_set<Category*, compare<std::greater<Category*>>> CategoriesSplay
Sadly, it doesn’t work. I won’t write errors it’s generating since it’s exceeding 100 and Visual Studio is terminating compilation process.
Then I tried to change class that my Category class should be extending to
class Category : public splay_set_base_hook<link_mode<auto_unlink>, Category*>
Again, no luck here. changing Category* in 2nd code to void_pointer(Category) doesn’t work either. Sadly boost documentation is no help in adding pointers to intrusive splay sets.
Have anyone got some solution to my problem? Thanks in advance.
Two things:
First, you shouldn’t store a pointer to your object, you should store the actual object. So your declaration should look like this:
Second, you need to implement the data members in your class that the container needs to do its work. The easiest way is to just inherit from the base “hook” class, like so:
Remember: the intrusive containers do not manage the memory of their contained objects the way the STL containers do. You need to allocate your object before you insert it into the container and make sure you delete it when you remove it.