Is it possible to insert multiple pointer to pointers in std::set<n​ode **, ...>?

Joined
Jul 6, 2011
Messages
4
Reaction score
0
Good evening , We created a std:::set<node **, iterator_pointer> where node is
defined by this class: class node{
public:
Range value;
//value stored in the node
node *next;
//pointer to next node
node *prev;
//pointer to previous node
node(){ next = NULL; prev = NULL; }
node(Range r){ value = r; next = NULL; prev = NULL; }
~node();
};

and iterator_pointer is defined by the struct: struct iterator_pointer
{ bool operator()(node** r1, node** r2) const{
if (*r1 == 0 || *r2 == 0){
return false;
}
return ((*r1)->value.high() < (*r2)->value.high());
}

For some unknown reason when we only insert one pointer to pointer
(node**) into the std::set<node**, iterator_pointer>. When we try
inserting multiple unique pointer to pointers(node __), the size of
the std:set<node**, iterator_pointer> stays the same.
We tried stepping into STL template code but we couldn't
determine why the size of std:Set does not continue increasing for
each successive unique node** insert. Are we doing something wrong or
is not possible to insert multiple unique keys correctly. Here
is an example of our STL set insert:
ranges_type.insert(&(myaccesses->getFront())) where myaccesses is a
doubly linked list of the class node shown earlier. Thank you.
 
Joined
Jul 6, 2011
Messages
4
Reaction score
0
I think I know more about the situation know. I traced through the STL xtree template std::set insert code.The node** pointer to pointer I am passing into std::set::insert(node **) is always the same . However, the node* pointer which is the front of the doubly linked is always different,
I believe we should be inserting into std::set the node * pointer corresponding to the front of the doubly linked list. However, if I do that then the ownership of the node *pointer corresponding to the front of the doubly linked list becomes more complex since the STL std::set<node *>.container also owns the node corresponding to the front of the doubly linked list.
We probably need a reference counted pointer class to control the ownership of the front node of the doubly linked list, Maybe, we could use boost::shared_ptr. We would prefer a simpler reference pointer class. If any Velocity Forum engineer knows what the simplest reference pointer C++ class is, could they please tell us?
Please let us know if our analysis is correct. Thank you for your help.
 
Last edited:
Joined
Jul 6, 2011
Messages
4
Reaction score
0
Re; Is it possible to insert pointers in std::set<node *>

Good morning, We have been looking at boost documentation for boost::shared_ptr and it looks one would have to use template enable_shared_from_this.
Is it possible that we should also look at boost::intrusive pointer even though it does explicitly provide reference counting functionality. Thank you,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,961
Messages
2,570,131
Members
46,689
Latest member
liammiller

Latest Threads

Top