[PATCH] Exploit move semantics in std::accumulate.

Paolo Carlini paolo.carlini@oracle.com
Tue Jan 11 12:50:00 GMT 2011


On 01/11/2011 01:45 PM, Marc Glisse wrote:
> On Tue, 11 Jan 2011, Paolo Carlini wrote:
>
>> ... for concreteness, this is what I actually tested.
>
> Why use x=move(x)+y and not x+=y?
>
>> Seems safe to me, being restricted to string / wstring (eg, no
>> problem with basic_string specializations), I can't see how the user
>> could detect the optimization.
>
> It would be safe if you also restricted the iterator's reference type.
> I believe a user can define:
>
> std::string operator+(std::string const&,MyType){...}
> std::string operator+(std::string&&,MyType)=delete;
Bah, let's reconsider this for 4.7.0...

Thanks,
Paolo.



More information about the Libstdc++ mailing list