Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > The perfect STL container

Reply
Thread Tools

The perfect STL container

 
 
ArbolOne
Guest
Posts: n/a
 
      09-28-2012
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
 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      09-28-2012
On 9/28/2012 9:25 AM, 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.


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
 
Reply With Quote
 
 
 
 
goran.pusic@gmail.com
Guest
Posts: n/a
 
      09-28-2012
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.
 
Reply With Quote
 
Rui Maciel
Guest
Posts: n/a
 
      09-28-2012
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.


Rui Maciel
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
container inside container in stl wolverine C++ 2 07-24-2006 03:08 PM
Copy elements from one STL container to another STL container Marko.Cain.23@gmail.com C++ 4 02-16-2006 05:03 PM
std::transform container => std::abs(container) Steven T. Hatton C++ 4 12-05-2004 07:10 AM
STL: container's values setup by another container Maitre Bart C++ 2 02-11-2004 12:11 AM
std::container::iterator vs std::container::pointer Vivi Orunitia C++ 11 02-04-2004 08:09 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57