Boost logo

Boost :

Subject: Re: [boost] [multi_index] scalar insert interface
From: Joaquin M Lopez Munoz (joaquin_at_[hidden])
Date: 2010-11-08 11:30:44


Maxim Yegorushkin <maxim.yegorushkin <at> gmail.com> writes:

>
> On 05/11/10 18:15, JOAQUIN M. LOPEZ MUÑOZ wrote:
> > ________________________________________
> > De: boost-bounces <at> lists.boost.org [boost-bounces <at> lists.boost.org]
> > En nombre de Stewart, Robert [Robert.Stewart <at> sig.com]
> >
> >> As is, it mirrors std::map's interface.
> >
> > Correct, this is exactly the rationale behind the difference in the
> > result types of both overloads. Clever as Maxim's suggestion is,
> > I'm reluctant to diverge from the standard without a compelling
> > reason --here the benefit does not seem impressive, since there
> > are efficient ways to determine whether the insertion took place,
> > for instance checking size() before and after trying the insertion.
>
> Performance-wise, it probably requires extra CPU cycles and storage
> (cache) to check size before and after insertion.
>
> I would still vote for another insert overload, maybe insert2() or
> something, which returns that bool. Since internally final_insert_
> always returns it, there is no good reason to waste it.

The (not explicitly stated) reason why the second overload of insert
does not return a pair<iterator,bool> is to make ordered containers
compatible with std::insert_iterator:

http://www.sgi.com/tech/stl/insert_iterator.html

Why don't you propose your auto_cast_pair solution as a modification
to the standard? As it stands, seems like insert_iterator can be
easily modified to cope with a auto_cast_pair return type.

Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk