Boost logo

Boost :

Subject: Re: [boost] [filesystem] scoped_file feature request?
From: Jorge Lodos Vigil (lodos_at_[hidden])
Date: 2011-10-11 09:46:47


Beman Dawes wrote:

> There is a long outstanding feature request, #1090 from Marcus
> Lindblom, requesting the following be added to Boost.Filesystem:

> class scoped_file {
> public:
> explicit scoped_file(const boost::filesystem::path& file)
> : m_path(file) {}
>
> ~scoped_file() { boost::filesystem::remove(m_path); }
>
> private:
> boost::filesystem::path m_path;
> };

> My weakly held opinion is that this request should be rejected.
> Rationale: Easy enough for users to do themselves, so it doesn't
> justify the additional surface area it would add to of the library.

> Does anyone have a killer argument for adding it?

Hi
If the constructor would create the file I find this useful, even more if there is an option to create a unique file (using tmpfile, for instance). Temporary unique files are common and it would be nice to have a portable implementation. The name could be temporary_file instead of scoped_file. Please note that the current unique_path function is not very useful because the path is unique when it is generated but not necessarily when it is used. More generally, the library could include file creation, with an auto delete option and/or unique names. Just a comment, not a request :-)

In its current version I think this class is prone to errors. Since the destructor removes the file, it might be confusing if the constructor creates it or not. The confusion increases if file creation is added to the library.

Best regards
Jorge


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