Boost logo

Boost :

From: Frank Birbacher (bloodymir.crap_at_[hidden])
Date: 2008-06-11 19:39:13


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)
                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)
                stream << "inner";
                stream << "(-";
                putStr(n-1, stream);
                stream << "-)";

Now a call to putStr(n, somestream) only has complexity O(n).


Boost list run by bdawes at, gregod at, cpdaniel at, john at