Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

The perfect STL container

51 views
Skip to first unread message

ArbolOne

unread,
Sep 28, 2012, 9:25:14 AM9/28/12
to
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

Victor Bazarov

unread,
Sep 28, 2012, 9:35:48 AM9/28/12
to
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

goran...@gmail.com

unread,
Sep 28, 2012, 9:38:54 AM9/28/12
to
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).

HTH,

Goran.

Rui Maciel

unread,
Sep 28, 2012, 9:50:09 AM9/28/12
to
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
0 new messages