Boost logo

Boost :

Subject: Re: [boost] [filesystem] scoped_file feature request?
From: Andrzej Krzemienski (akrzemi1_at_[hidden])
Date: 2011-10-11 15:42:32


> 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?
> --Beman

Hi,
I would add to the rationale for rejection, that scoped_file's destructor
performs an operation that might throw an exception, which is counter to
well established practices in C++. You could use the error_code version, but
that would hide the error if any occurs.

Regards,
&rzej


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