Re: Ordering of same value keys in multimap

Discussion in 'C++' started by Howard Hinnant, Aug 26, 2012.

  1. On Sunday, August 26, 2012 9:36:50 AM UTC-4, Chris Vine wrote:

    > If two or more pairs are added to a multimap which have the same
    > key value, is there any requirement in the standard that when iterated
    > through they should appear in the order in which they were inserted?
    >
    > Or is any ordering of same value keys OK, so this an implementation
    > matter?


    It depends on which standard.

    In C++98/03, the ordering for equivalent keys was unspecified.

    In C++11, this paper: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1780.html
    was adopted which specifies that if the keys are inserted without a hint, that they will be stored in the order that they were inserted. If they are inserted with a hint, then they will be positioned as close to the hint as possible. For example if the hint is end(), then they are always ordered in the order inserted. If the hint is always begin(), they are ordered in the reverse order inserted.

    N1780 was adopted long enough ago, that I would expect all compiler/libraries to have already implemented it, whether or not operating in C++11 mode.
     
    Howard Hinnant, Aug 26, 2012
    #1
    1. Advertising

  2. On Monday, August 27, 2012 8:30:52 AM UTC-4, Chris Vine wrote:
    > On Sun, 26 Aug 2012 11:56:28 -0700 (PDT)
    > Also, I wonder if Table 102 is defective
    > and it ought to distinguish between a_uniq.emplace_hint() and
    > a_eq.emplace_hint() rather than lump them as a single item.


    After distinguishing the entries, what changes would you make that makes them different?

    Howard
     
    Howard Hinnant, Aug 28, 2012
    #2
    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. Przemek
    Replies:
    3
    Views:
    758
    Mike Wahler
    Jan 31, 2005
  2. reppisch
    Replies:
    6
    Views:
    989
    reppisch
    Jun 19, 2007
  3. puzzlecracker
    Replies:
    19
    Views:
    895
    puzzlecracker
    Oct 30, 2008
  4. nbigaouette

    Z-Ordering (Morton ordering) question

    nbigaouette, Nov 5, 2009, in forum: C Programming
    Replies:
    2
    Views:
    2,171
  5. Boris Punk

    Ordering of hashtable keys

    Boris Punk, Jul 17, 2010, in forum: Java
    Replies:
    6
    Views:
    453
Loading...

Share This Page