ext/vstring.h swap vs unequal allocators

Paolo Carlini pcarlini@suse.de
Tue Nov 8 20:40:00 GMT 2005


Howard Hinnant wrote:

>> Maybe it's too early for that because of the assignability 
>> requirement...
>
> 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).

Thanks for the explanation: working with you is a pleasure.

> 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! :-)

Yes, we do, I think. The merit goes to Gaby: a lot of time ago, when I
added a lot of std:: qualifications everywhere to avoid problems with
ADL, he warned me to leave swap alone. I will audit, anyway.

> 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.

I know. Then for now my idea is implementing it in mainline and v7 for
ext/vstring.h, and only in v7 everything else (that is, basic_string and
containers). Then we'll see...

Thanks,
Paolo.



More information about the Libstdc++ mailing list