Boost logo

Boost :

Subject: Re: [boost] [filesystem] windows/posix inconsistencies.
From: Thorsten Ottosen (thorsten.ottosen_at_[hidden])
Date: 2012-02-01 06:08:27


Den 31-01-2012 21:37, Ion Gaztañaga skrev:
> El 31/01/2012 14:47, Stephan T. Lavavej escribió:
>> [Thorsten Ottosen]

> Although returning vectors by value might be a good idea for factories,
> and such things, it's always more efficient to pass a reference to a
> vector, and clear() + fill or assign, or even better, reusing already
> constructed values (which can be vectors of vectors). Using
> filesystem::path in a loop might trigger a lot of allocations that could
> be avoided if the string could be passed as an argument, reusing already
> allocated memory for each path.
>

In my case "glob" performance is not important; STLSofts version is
probabily much faster.

Remark 1: with the &/&& syntax of C++11, at least the temporary strings
are more efficient, as we can move the value.

Remark 2: The fact that functions like extension() returns a temporary
path object seems overkill (I know its only a cheap string copy, but still).
I fail to see how ".foo" can be a path.

I feel that the problem is that there is no
uniform handling of strings in the interface/internally. If the path
objects stored/acccepted utf8 strings, we would have a very nice, clean
interface.

Taking extension() as an example, we have the following options:

A. return a temporary path

B. return a temporary string

C. add a function, path::has_extention( const std::string& );

D. add a free function, has_extension( const path& p, const string& );

I think the latter are to be preferred, and I don't think there is any
overhead at all with them.

-Thorsten


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk