C++ Logo

std-proposals

Advanced search

Re: [std-proposals] A Proposal to Add a New Multiset container Method to the Standard Library Technical Report

From: Jonathan Wakely <cxx_at_[hidden]>
Date: Wed, 12 Feb 2025 09:53:24 +0000
On Wed, 12 Feb 2025 at 09:04, Александр Поваляев <apovalyaev_at_[hidden]>
wrote:

> Do you mean that "The order of the elements that compare equivalent is the
> order of insertion and does not change." (
> https://en.cppreference.com/w/cpp/container/multiset") statement is wrong?
>

It's incomplete or ambiguous at best. It could be read to mean that the
order is determined at the time of insertion and doesn't change after that,
which would be correct. You are reading it to mean that the spatial order
in the container is the same as the temporal order that they are inserted,
which is wrong.

cppreference is not the standard, and not every statement on every page is
authoritative. You find a more correct statement at the link you gave
earlier:
https://en.cppreference.com/w/cpp/container/multiset/equal_range#Return_value
"Since `emplace` and unhinted `insert` always insert at the upper bound,
the order of equivalent elements in the equal range is the order of
insertion unless hinted `insert` or `emplace_hint` was used to insert an
element at a different position."




> And a hint while being used with 'insert' method of 'std::multiset' is
> considered as "A MUST", not as "A RECOMMENDATION"?
>

Yes. The standard says for a.insert(p, t) that "t is inserted as close as
possible to the position just prior to p."

Received on 2025-02-12 09:53:41