Boost logo

Boost Users :

From: Yuval Ronen (ronen_yuval_at_[hidden])
Date: 2005-02-11 04:56:43


>>I've then worked on a method, just by adding a special object after the '='
>>sign, which transforms these concatenations into a two pass operation, the
>>first to calculate the total length and allocate the destination string, and
>>the second pass to actually copy the source strings into the destination.
>>
>>One just need to re-write the concatenations this way :
>>std::string a = my_special_object() + b + c + d + e ;
>>
>>But maybe I am reinventing the wheel. Is there in Boost, a way to speed up
>>this kind of operation ?
>
>
> I'm not aware of anything in boost - the string algo lib seemed like a
> natural place but I didn't see anything.
>
> I wrote something like that. I'm not sure if it's really safe and
> correct and all - I believe the temporary lifetime relied on is
> guaranteed ....
>
> You can write:
>
> std::string s1;
> s1 << concat () + a + b + c;
>
> or
>
> std::string s2 = concat () + a + b + c;

Hmmm, this sounds interesting to me. I have to admit that's an idea I've
never thought of before. Am I right to assume that the temporary concat
object holds some kind of a container-of-pointers to the concatenated
strings? And this container will be pushed_back with every operator+?
And finally, assignment of this to string will only then calulate the
resulted string? I guess the trick is how to avoid memory alllocation
while push_backing. One can use a regular by-value fixed-size c-array of
pointers as a concat class member, but that complicates the code on
what-to-do-when-it's-full. Any other ideas?

Just a few thoughts...
Yuval


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net