This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: [PATCH] Exploit move semantics in std::accumulate.
- From: Christopher Jefferson <chris at bubblescope dot net>
- To: Eelis van der Weegen <eelis at eelis dot net>
- Cc: libstdc++ at gcc dot gnu dot org
- Date: Sat, 8 Jan 2011 18:05:03 +0000
- Subject: Re: [PATCH] Exploit move semantics in std::accumulate.
- References: <iga6qn$7hk$1@dough.gmane.org>
On 8 Jan 2011, at 17:27, Eelis van der Weegen wrote:
> The attached simple patch reduces the runtime of the following program
> from 1.4 seconds to 0.005 seconds on my machine:
>
> #include <iostream>
> #include <string>
> #include <numeric>
> #include <vector>
>
> int main()
> {
> std::vector<std::string> v;
> for(int i = 0; i != 20000; ++i)
> v.push_back(std::string(50, 'a'+(i%10)));
>
> std::cout << std::accumulate(v.begin(), v.end(),
> std::string()).size() << '\n';
> }
Your patch is a really nice idea. I'm not 100% sure it is allowed by the C++0x standard (although, I can't imagine any valid code which would possibly break it).
Chris