[RFA] Algorithms vs operator* and operator==

Joe Buck Joe.Buck@synopsys.COM
Sun Nov 7 19:20:00 GMT 2004


On Sun, Nov 07, 2004 at 11:40:03AM +0000, chris jefferson wrote:
> Also, in the case of algorithms, I'm not convinced that move symantices 
> would help that much.

Maybe.  However, in the case of vector<T>, the special case of move
semantics corresponding to "relocatable by shallow copy" helps *a lot*.
Insertion, erasure, and resizing can all be done with memmove.

> Looking at the classes I have access to, the most efficent way of 
> implementing (2) looks like it is usually either just doing x=y, or 
> doing swap(x,y). therefore move symantics are overkill for this when you 
> simply want to either do swap(x,y) or x=y.

swap is just what you want when the algorithm calls for a swap.  If the
algorithm calls for, say, copy construction followed by destruction, it
just so happens that swap can be abused in many cases to "swap" the
initialized and the uninititalized object, but it's wasteful compared to 
memmove and it's unsafe as well.

What I would like to be able to do is to have a new type trait, and
specialize std::vector on this trait.  If the property holds, the
specialized vector would do resizing, insertion, and erasure by
memmove'ing the surviving elements.  I don't think that this would be
excessively complicated to implement.  I would then give all of the
standard containers and std::string the appropriate trait.



More information about the Libstdc++ mailing list