Boost logo

Boost Users :

From: Stuart Dootson (stuart.dootson_at_[hidden])
Date: 2005-02-11 15:09:57


On Fri, 11 Feb 2005 13:14:11 -0600, Jim Lear <jim.lear_at_[hidden]> wrote:
> So, I assume the '...' paramater, a la printf, is all but forbidden. It's
> too bad there no good way to pass a variable number of arguments in C++. Of
> course one could pass a vector of std::string references, but I'm beyond my
> feeble abilities to understand the performance affects of constructing a
> temporary vector.
>
> t. scott urban wrote:
> On Fri, 2005-02-11 at 10:39 -0600, Jim Lear wrote:
 
> No, fastcat does not exist. I'm suggesting that it may be easier
> for
Chateauneu to create an optimized method (fastcat or such) that
accepts
> multiple operands rather than wrestling with operators that
accept only two
> operands.
 You're probably right. You could do something like.

using
> std::string
void fastcat (string & dest, const string & s1);
void fastcat
> (string & dest, const string & s1, const string & s2);
etc

Explicit
> unrolling of the loops in my toy concat class. Unless you only
have a few
> cases you care about, this is tedious.

It's probably to use some template
> machinery and or preprocessor magic
to create a form that takes an arbitrary
> (up to some limit) number of
strings to concatenate.

Another option is to
> rely on the compilers intimate knowledge of it's
own library implementations
> to do all this for you. Don't know of real
compilers do this, but it seems
> like a reasonable request.

 
> --
Jim Lear
(512) 228-5532 (work)
(512) 293-7248 (cell)
>

You could try a signature like this:

std::string fastcat(std::string s0, std::string s1 = std::string(), /*
and as many strings as you want or can be bothered to put in */,
std::string sn = std::string())

Empty strings should be relatively cheap to construct (no heap?), and
you get a simulation of a variable number of arguments.

Stuart Dootson


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