Re: Is set's iterator a const_iterator?

Discussion in 'C++' started by Jonathan Lee, May 19, 2010.

  1. Jonathan Lee

    Jonathan Lee Guest

    On May 19, 3:31 pm, Andy Champ <> wrote:
    > Have I understood this correctly?
    >
    > Andy


    Yup. I had the exact same problem recently. By
    [lib.associative.reqmts] point 5: Keys in an associative
    container are immutable.

    And in a set, the value is also the key.

    --Jonathan
     
    Jonathan Lee, May 19, 2010
    #1
    1. Advertising

  2. Jonathan Lee <> wrote:
    > Yup. I had the exact same problem recently. By
    > [lib.associative.reqmts] point 5: Keys in an associative
    > container are immutable.
    >
    > And in a set, the value is also the key.


    That's why we have std::map: It's like a set, but with a mutable part on
    each "key". It's what you should use when you want to change a part of the
    key which isn't used to determine its ordering.
     
    Juha Nieminen, May 20, 2010
    #2
    1. Advertising

  3. Jonathan Lee

    Jonathan Lee Guest

    On May 21, 3:12 pm, Andy Champ <> wrote:
    > Jonathan Lee wrote:
    > Leigh Johnston wrote:
    >
    > As I went back through the posts to forward them to my work account (no
    > NNTP) it occurred to me - Are you guys related :p
    >
    > Andy


    The near name reversal is indicative of the fact that one of us is
    from a parallel universe and has a goatee.

    You don't get to know which one.

    --Jonathan
     
    Jonathan Lee, May 21, 2010
    #3
  4. Jonathan Lee

    Brian Guest

    On May 20, 5:00 am, Juha Nieminen <> wrote:
    > Jonathan Lee <> wrote:
    > > Yup. I had the exact same problem recently. By
    > > [lib.associative.reqmts] point 5: Keys in an associative
    > > container are immutable.

    >
    > > And in a set, the value is also the key.

    >
    >   That's why we have std::map: It's like a set, but with a mutable part on
    > each "key". It's what you should use when you want to change a part of the
    > key which isn't used to determine its ordering.


    I would say that's why we have boost::multi_index_container and
    boost::intrusive containers. std::map it seems to me speaks
    with a forked tongue, pair<key, value>. Although it takes a
    little more effort, using an alternative to map avoids the
    useless "first" and "second" terminology required by maps.
    You can get by with maps in small programs, but how things
    are named is more important in larger programs. I think
    that some projects start out using maps and although they
    would benefit from switching to an alternative, they lack
    the resources to go back and rework things.


    Brian Wood
    http://webEbenezer.net
    (651) 251-9384
     
    Brian, May 22, 2010
    #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. CoolPint
    Replies:
    3
    Views:
    733
    CoolPint
    Dec 13, 2003
  2. Replies:
    2
    Views:
    365
    Ferdi Smit
    Oct 23, 2005
  3. John Harrison

    iterator and const_iterator

    John Harrison, Nov 20, 2005, in forum: C++
    Replies:
    5
    Views:
    1,271
    Cy Edmunds
    Nov 20, 2005
  4. Mark P
    Replies:
    2
    Views:
    708
    Bart van Ingen Schenau
    Jun 15, 2006
  5. Bo Persson
    Replies:
    0
    Views:
    407
    Bo Persson
    May 20, 2010
Loading...

Share This Page