|
Boost Users : |
From: t. scott urban (scottu_at_[hidden])
Date: 2005-02-11 12:05:48
On Fri, 2005-02-11 at 11:22 +0100, Chateauneu Remi wrote:
> > On Thu, 2005-02-10 at 18:48 +0100, Chateauneu Remi wrote:
> > > std::string a = my_special_object() + b + c + d + e ;
> > >
> > std::string s1;
> > s1 << concat () + a + b + c;
> > std::string s2 = concat () + a + b + c;
> >
> > If you want to see it, let me know.
> Yes, thanks ! If you wish, I can send mine (330 lines, 11 k-bytes).
> Could we take the best of both, and maybe put it in the string algo lib ?
Attached. The way I did it is pretty short - 50 lines or so of
implementation, but like I said it relies on lifetimes of temporaries
and order of operations which I think are guaranteed, but not certain.
Also, a quick stress test doesn't show any improvement in speed over the
naive method, but that would depend greatly on the lifetime of the
destination string, size and number of strings you're concatenating, the
behavior of your implementation (e.g. mine penalizes multi-threaded
std::string usage heavily), etc.
Perhaps you have a way to solve it in a more effective manner.
In case I haven't put enough caveats on this, this is just toy code, I
haven't and wouldn't put this in production code without more testing,
profiling, etc.
Regards
-- t. scott urban <scottu_at_[hidden]>
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