Boost logo

Boost Users :

Subject: Re: [Boost-users] [Range] insert algorithm fails if target is a map
From: Nathan Ridge (zeratul976_at_[hidden])
Date: 2011-11-23 13:50:43


> The title says it all really. The failure occurs because the insert
> algorithm expects the container
> to provide a 3-arg insert of the form
>
> container.insert( position, begin, end );
>
> whereas map's, multimap's and set's insert method only takes two arguments...
>
> map.insert( begin, end );
>
> Is this limitation by design? It would be easy to provide
> specialisations for maps, mmaps and sets, but
> that would not be a completely general solution.

I think what we really need is a second insert algorithm.

The one we have right now:

Container& insert(Container& target,
                              typename Container::iterator before,
                              const SinglePassRange& from);

should call target.insert(before, begin, end), and only work for sequence containers,

while a new one:

Container& insert(Container& target,
                              const SinglePassRange& from);

should call target.insert(begin, end), and only work for associative containers
(or any other container where you have no control over the position it's inserted
at, e.g. a hypothetical sorted vector).

I don't think it makes sense to try and get the first one to work for associative
containers, because the "before" parameter is meaningless for those.

Regards,
Nate
                                               


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net