New to STL

B

breck

Hi, I'm working on a program in which I want to store instances of
Cubes in a hash_set and pointers to those cubes in Nodes (the nodes are
stored in a priority queue).

My code looks something like this:

std::hash_set <Cube, hashFunc<Cube>, equals> cubesVisited;
std::priority_queue <Node, std::vector<Node>, comp> nodesToExpand;
std::pair<std::hash_set <Cube>::iterator, bool> p;

p = cubesVisited.insert(Cube(currentState).turnFrontCW());
if (p.second)
nodesToExpand.push(Node(*pointer to what was just inserted in the hash
table*, n));

I'm not sure how to access that memory location. I know to get the
value of the Cube I would put *p, but I just want p (not the iterator,
but the memory location the iterator is pointing to). Do I even get at
it through the iterator? Is there some other way? Thanks for any help
in advance.
 
M

Mark P

breck said:
Hi, I'm working on a program in which I want to store instances of
Cubes in a hash_set and pointers to those cubes in Nodes (the nodes are
stored in a priority queue).

My code looks something like this:

std::hash_set <Cube, hashFunc<Cube>, equals> cubesVisited;
std::priority_queue <Node, std::vector<Node>, comp> nodesToExpand;
std::pair<std::hash_set <Cube>::iterator, bool> p;

p = cubesVisited.insert(Cube(currentState).turnFrontCW());
if (p.second)
nodesToExpand.push(Node(*pointer to what was just inserted in the hash
table*, n));

I'm not sure how to access that memory location. I know to get the
value of the Cube I would put *p, but I just want p (not the iterator,
but the memory location the iterator is pointing to). Do I even get at
it through the iterator? Is there some other way? Thanks for any help
in advance.

Note that hash_set is currently not standard.

If I understand your question, I think what you want is &*(p->first).

-Mark
 
R

red floyd

breck said:
Hi, I'm working on a program in which I want to store instances of
Cubes in a hash_set and pointers to those cubes in Nodes (the nodes are
stored in a priority queue).

My code looks something like this:

std::hash_set <Cube, hashFunc<Cube>, equals> cubesVisited;
std::priority_queue <Node, std::vector<Node>, comp> nodesToExpand;
std::pair<std::hash_set <Cube>::iterator, bool> p;
hash_set is not a member of std.
 

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

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top