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.
> 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
-- I do not respond to top-posted replies, please don't ask
On Friday, September 28, 2012 3:25:15 PM UTC+2, ArbolOne wrote:
> 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).
ArbolOne wrote:
> 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.