The perfect STL container

A

ArbolOne

Does STL have a container that would allow me to story only one copy of whatever data I am storing? For instance, in a data pool where there are several people named Mike, the container will only allow me to story the first person named Mike.

TIA
 
V

Victor Bazarov

Does STL have a container that would allow me to story only one copy
of whatever data I am storing? For instance, in a data pool where
there are several people named Mike, the container will only allow me
to story the first person named Mike.

Your question is a bit unclear. What is "a data pool"? How are you
going to populate your container from the "data pool"? There is always
more than one way to skin the proverbial cat, and since you mentioned
"people" and storing (I assume you meant "store" not "story") only "the
first person", do you need to store the whole "person" (whatever you
mean by that) or only the name? Seems that no matter what container you
end up using, you still need to introduce some kind of discriminating
logic to meet the requirement of storing only the first object, and not
the last [encountered], for instance.

V
 
G

goran.pusic

Does STL have a container that would allow me to story only one copy of whatever data I am storing? For instance, in a data pool where there are several people named Mike, the container will only allow me to story the first person named Mike.

Look up std::set (hash_set if you have it and don't care about sorting your people).

HTH,

Goran.
 
R

Rui Maciel

ArbolOne said:
Does STL have a container that would allow me to story only one copy of
whatever data I am storing? For instance, in a data pool where there are
several people named Mike, the container will only allow me to story the
first person named Mike.

It appears you are looking for a unique associative container. The STL
provides a hand full of those, including std::map and std::set.


Rui Maciel
 

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
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top