Re: Is set's iterator a const_iterator?

Discussion in 'C++' started by Bo Persson, May 20, 2010.

  1. Bo Persson

    Bo Persson Guest

    Andy Champ wrote:
    > We're experimenting with MS VC2010 - we wish to upgrade from 2008 -
    > and we've had an error come out which is a little bit of a
    > surprise. I'd just like to check with the experts here.
    >
    > An object in a set must be comparable with other objects in the set,
    > typically with its inbuilt operator< but perhaps with another
    > predicate. This comparison must be stable, transitive and various
    > other rules that I'm sure everyone knows.
    >
    > We've taken the view that we can do anything we like to the objects
    > in the set *provided that what we do does nothing to alter the way
    > it sorts*. It looks as though this wasn't correct - that we can't
    > do anything at all that requires non-const behaviour on the object.
    > In fact it looks as though set's iterator is almost identical to its
    > const_iterator, so what we'll have to do is pull the object out of
    > the set, copy it, fiddle with the copy, then put the copy back. This
    > sounds expensive :(
    >
    > Have I understood this correctly?
    >


    Yes. :)

    http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#103


    If you really, really, REALLY know what you are doing, you can beat
    the compiler with a const_cast. The slightest mistake, and you are
    toast, of course...



    Bo Persson
    Bo Persson, May 20, 2010
    #1
    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:
    720
    CoolPint
    Dec 13, 2003
  2. Replies:
    2
    Views:
    358
    Ferdi Smit
    Oct 23, 2005
  3. John Harrison

    iterator and const_iterator

    John Harrison, Nov 20, 2005, in forum: C++
    Replies:
    5
    Views:
    1,249
    Cy Edmunds
    Nov 20, 2005
  4. Mark P
    Replies:
    2
    Views:
    692
    Bart van Ingen Schenau
    Jun 15, 2006
  5. Jonathan Lee
    Replies:
    3
    Views:
    314
    Brian
    May 22, 2010
Loading...

Share This Page