The perfect STL container

Discussion in 'C++' started by ArbolOne, Sep 28, 2012.

  1. ArbolOne

    ArbolOne Guest

    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
    ArbolOne, Sep 28, 2012
    #1
    1. Advertising

  2. 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
    Victor Bazarov, Sep 28, 2012
    #2
    1. Advertising

  3. ArbolOne

    Guest

    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.
    , Sep 28, 2012
    #3
  4. ArbolOne

    Rui Maciel Guest

    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
    Rui Maciel, Sep 28, 2012
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Vivi Orunitia
    Replies:
    11
    Views:
    4,446
    Martijn Lievaart
    Feb 4, 2004
  2. Maitre Bart
    Replies:
    2
    Views:
    510
    Maitre Bart
    Feb 11, 2004
  3. Steven T. Hatton
    Replies:
    4
    Views:
    3,869
    Rob Williscroft
    Dec 5, 2004
  4. Replies:
    4
    Views:
    779
    Daniel T.
    Feb 16, 2006
  5. wolverine
    Replies:
    2
    Views:
    437
    Marcus Kwok
    Jul 24, 2006
Loading...

Share This Page