I am curious about the boost intrusive containers and wanted to test it. I basically copy pasted the example from boost.org in the chapter "How to use Boost.Intrusive". So my Code looks like this:
#include <iostream>
#include <boost/intrusive/list.hpp>
using namespace boost::intrusive;
struct test_tag1;
struct test_tag2;
typedef list_base_hook< tag<test_tag1> > BaseHook;
typedef list_base_hook< tag<test_tag2> > BaseHook2;
class TestClass : public BaseHook, public BaseHook2 {
public:
int test_var;
};
typedef list< TestClass, base_hook<BaseHook> > class_list;
typedef list< TestClass, base_hook<BaseHook2> > class_list2;
int main() {
class_list list;
TestClass class1 = TestClass();
list.push_back(class1);
bool is_the_same = (&list.front() == &class1);
std::cout << is_the_same;
return 0;
}
It compiles successfully, but on execution I keep getting the following error:
1Assertion failed: !hook.is_linked(), file boost/intrusive/detail/generic_hook.hpp, line 47
I opened the generic_hook.hpp to check what raises this error, and the description of the assert is:
void destructor_impl(Hook &hook, detail::link_dispatch<safe_link>)
{ //If this assertion raises, you might have destroyed an object
//while it was still inserted in a container that is alive.
//If so, remove the object from the container before destroying it.
(void)hook; BOOST_INTRUSIVE_SAFE_HOOK_DESTRUCTOR_ASSERT(!hook.is_linked());
}
But that cant be true, at least I cant see where I could have destroyed the object accidently. I dont know all the details about these containers yet, so I would be gratefull to get some help here.