Re: [Boost-users] AVL tree insert_equal generating assertion `node_algorithms::unique(to_insert)'

My previous mail got truncated, the completed listing is below:
Hi,
I have the following piece of code that is generating the above assertion. Could someone tell me what is going wrong:
template <typename T>
struct my_node_t : public avl_set_base_hook<> {
my_node_t(T data): m_data(data) {}
template <typename U>
friend bool operator< (const my_node_t<U>& lhs, const my_node_t<U>& rhs) {
return lhs.m_data < rhs.m_data;
};
T m_data;
};
typedef my_node_t<int> avlnode_t;
typedef avltree

bsing escribió:
My previous mail got truncated, the completed listing is below:
Because you are inserting a value which is inalready inserted in an intrusive container. See Documentation: http://www.boost.org/doc/libs/1_40_0/doc/html/intrusive/safe_hook.html Best, ion

bsing escribió:
My previous mail got truncated, the completed listing is below:
Because you are inserting a value which is inalready inserted in an intrusive container. See Documentation: Yes I figured it out immediately after posting. I tried fixing it by adding a duplicate instance in the vector before adding it to the tree, but the trouble with that seems to be that push_back()s that cause resize()s make the object invalid. So I guess a list is a better structure to hold objects for the lifetime of the avltree? http://www.boost.org/doc/libs/1_40_0/doc/html/intrusive/safe_hook.html Best, ion _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

Yes I figured it out immediately after posting. I tried fixing it by adding a duplicate instance in the vector before adding it to the tree, but the trouble with that seems to be that push_back()s that cause resize()s make the object invalid. So I guess a list is a better structure to hold objects for the lifetime of the avltree?
Or try deque if you just need to add and not erase. Anyway, why do you need Boost.Intrusive if you are going to copy the value? Isn't better to use std::set and forget Boost.Intrusive? Ion

Yes I figured it out immediately after posting. I tried fixing it by adding a duplicate instance in the vector before adding it to the tree, but the trouble with that seems to be that push_back()s that cause resize()s make the object invalid. So I guess a list is a better structure to hold objects for the lifetime of the avltree?
Or try deque if you just need to add and not erase. Anyway, why do you need Boost.Intrusive if you are going to copy the value? Isn't better to use std::set and forget Boost.Intrusive? The intent is to use a BST which can easily be coaxed into using smart pointers. I don't see how this is possible without an intrusive container, which std::set is not (well, discounting the.Allocator). I'm not writing a real application, more like a test program to observe the memory signatures of rebalancing, controlled pointer-chasing and such (at a low-level). I would be much happier not duplicating the value at all. I want the lifetime of the objects to persist, which means I can't insert objects created on the stack and malloc/new isn't an option due to the nature of my runtime (a simulated machine). So what I need is a BST that manages lifetime internally (like std::set) but allows me to dictate raw/smart pointer types (like boost::avltree). I realize I might be asking for too much :). Ion _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (2)
-
bsing
-
Ion Gaztañaga