ext/vstring.h swap vs unequal allocators

Howard Hinnant hhinnant@apple.com
Tue Nov 8 20:08:00 GMT 2005


On Nov 8, 2005, at 1:14 PM, Paolo Carlini wrote:

> Paolo Carlini wrote:
>
>>                                                   Basically, would
>> mean removing the O(N) fallback and replacing it with a swap of the
>> allocators.
>>
> Maybe it's too early for that because of the assignability  
> requirement...
>
> Paolo.

Swappable actually. :-)  Allocator assignment doesn't have to be  
implemented if the allocator has a custom swap (and if the libstd  
calls the custom swap).  We need to first make sure that we always  
call swap unqualified, and then only when allowed - and this would be  
for C++0X.  The (proposed) spec for when you can call swap  
unqualified is most easily read by searching for the table of  
algorithms here:

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1771.html

Anything with an X in the S column can call swap unqualified.  If the  
X is lacking from the MC (move construction) and MA (move assignment)  
columns (well, from all other columns too), then the algorithm *must*  
call swap unqualified if it is to move any values around (there is no  
other legal mechanism to move or copy the value).

Personally I think it would be a good idea to lead C++0X and  
implement this part early.  People are complaining today that they  
can't put their (templated) swap in namespace std, and that when put  
in their own namespace it doesn't get called.  Quick glance:  I think  
we already implement this! :-)

Next the containers, if they are going to swap allocators, must be  
careful to swap unqualified.  Use of something along the lines of  
boost::compressed_pair for allocator storage is the easiest way to  
deal with this issue.  compressed_pair should have a swap that swaps  
its members.

I'm not qualified to say if this should happen now or later.   
CodeWarrior has it now.

-Howard



More information about the Libstdc++ mailing list