std::map question

Discussion in 'C++' started by Razmig K, Aug 25, 2003.

  1. Razmig K

    Razmig K Guest

    Dear mates,

    Is there an elegant way to ensure the existence of a certain key among
    the keys of a map variable ?

    Thank you.

    //rk
     
    Razmig K, Aug 25, 2003
    #1
    1. Advertising

  2. Razmig K

    Dave Theese Guest

    Could you please clarify the question a little further?

    I'm tempted to say "just insert a pair that has the key you desire to be
    present", but somehow I think that's probably missing your intended point...


    "Razmig K" <> wrote in message
    news:...
    > Dear mates,
    >
    > Is there an elegant way to ensure the existence of a certain key among
    > the keys of a map variable ?
    >
    > Thank you.
    >
    > //rk
     
    Dave Theese, Aug 25, 2003
    #2
    1. Advertising

  3. Razmig K

    Mike Wahler Guest

    Razmig K <> wrote in message
    news:...
    > Dear mates,
    >
    > Is there an elegant way to ensure the existence of a certain key among
    > the keys of a map variable ?


    if(the_map.find(key) == the_map.end())
    the_map[key];

    -Mike
     
    Mike Wahler, Aug 25, 2003
    #3
  4. Razmig K wrote:

    > Dear mates,
    >
    > Is there an elegant way to ensure the existence of a certain key among
    > the keys of a map variable ?
    >


    I'm not sure I understand. If you want to make sure a certain key will
    exist in the map, you need only insert it. As long as you don't remove
    it later, this ensures that the key will exist "among the keys in the
    map variable".

    If you meant to ask how one would check for the existence of a
    particular key, the answer is to use the 'find()' function.

    -Kevin
    --
    My email address is valid, but changes periodically.
    To contact me please use the address from a recent posting.
     
    Kevin Goodsell, Aug 26, 2003
    #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. Matthias Hildebrand
    Replies:
    5
    Views:
    8,012
    krogers
    Mar 20, 2012
  2. Peter Jansson
    Replies:
    5
    Views:
    6,355
    Ivan Vecerina
    Mar 17, 2005
  3. Replies:
    1
    Views:
    435
    red floyd
    Dec 21, 2008
  4. Thomas J. Gritzan
    Replies:
    6
    Views:
    1,033
    James Kanze
    Dec 22, 2008
  5. James Kanze
    Replies:
    0
    Views:
    2,026
    James Kanze
    Dec 21, 2008
Loading...

Share This Page