Velocity Reviews

Velocity Reviews (
-   C++ (
-   -   Re: Ordering of same value keys in multimap (

Howard Hinnant 08-26-2012 06:56 PM

Re: Ordering of same value keys in multimap
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:
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 08-28-2012 02:59 PM

Re: Ordering of same value keys in multimap
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?


All times are GMT. The time now is 01:38 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.