From: Hurd, Matthew (hurdm_at_[hidden])
Date: 2003-11-07 01:37:24
> -----Original Message-----
> From: John Torjo [mailto:john.lists_at_[hidden]]
> Sent: Saturday, 8 November 2003 9:03 AM
> To: Boost mailing list
> Subject: Re: [boost] String thought
> Matthew Hurd wrote:
> > Any lib related to Boost that uses expression templates for string or
> > operations to minimize the temporary objects? Only thinking of
> > concatenation but I guess it might apply elsewhere.
> > Might be a neat addition to the string algorithm library.
> I would think so ;)
> However, I'm not sure how realistic this could be.
> Just consider this:
> for ( int i = 0; i < 10000; ++i)
> s += "s";
> In cases like this, expression templates would be useless, IMO.
Completely useless, I'd agree. No temporaries here.
It only really makes sense when you can do
X = a + b; or worse....
This would at least create one unnecessary temporary.
That is the assignment overload would resize the string to take the
total size of the strings to be added and then add all the components in, in
This would eliminate the temporaries and just require on realloc
equiv, if that is how the underlying string works.
Would be especially helpful in:
X = a + b + c + d + e;
Not sure if it is that important but I have noticed that std::string gets a
bit of bad press from time to time in the speed department. I seem to think
that often if boils down to simple unrequired temporaries like this.
A way to avoid it is to resize x to the appropriate size in advance and then
X += a;
X += b; ...
Etc... not quite so eloquent though.
I'll write the code when I get home, profile it and post some results for
MINGW and VC7.1... Still the test cases will be artificial and may not
reflect too much reality.
> Anyway, Pavol, any thoughts?
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk