|
Boost : |
From: Frank Birbacher (bloodymir.crap_at_[hidden])
Date: 2008-06-11 19:39:13
Hi!
Matus Chochlik schrieb:
>> Which is why there is a stringstream. You won't return anything but instead
>> write into a ostream& directly. This reduces the complexity of the
>> algorithm.
>
> Well, unless you want to do something else with the type name
> besides writing it into an ostream ;)
Nah, I'm talking of asymptotic complexity. Say you have a nested type, n
levels deep. And each level would add some characters to a string, then
return it to the next higher level, like:
string getStr(const unsigned n)
{
if(n==0)
return "inner";
return "(-" + getStr(n-1) + "-)";
}
Then a call to getStr(n) has complexity O(n*n).
Compared to:
void putStr(const unsigned n, ostream& stream)
{
if(n==0)
stream << "inner";
else
{
stream << "(-";
putStr(n-1, stream);
stream << "-)";
}
}
Now a call to putStr(n, somestream) only has complexity O(n).
Frank
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk