[Boost-bugs] [Boost C++ Libraries] #1090: scoped_file class that deletes file at end of scope

Subject: [Boost-bugs] [Boost C++ Libraries] #1090: scoped_file class that deletes file at end of scope
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2007-07-13 12:35:23


#1090: scoped_file class that deletes file at end of scope
--------------------------------------------+-------------------------------
 Reporter: Marcus Lindblom <macke_at_[hidden]> | Type: Patches
   Status: new | Milestone: To Be Determined
Component: filesystem | Version:
 Severity: Not Applicable | Keywords:
--------------------------------------------+-------------------------------
 I've found myself wanting this on a couple of occasions with 1.33.1, and
 I've done it with boost::shared_ptr:

 {{{
 #!c++
 boost::shared_ptr<fs::path> removeFile(&file, bind(&fs::remove,
 boost::cref(file)));
 }}}

 That didn't work with 1.34.1 (maybe due to compiler intricacies), so I did
 it properly:

 {{{
 #!cpp
 class scoped_file {
 public:
     explicit scoped_file(const std::string& file) : m_path(file,
 boost::filesystem::native) {}
     explicit scoped_file(const boost::filesystem::path& file) :
 m_path(file) {}

     ~scoped_file() { boost::filesystem::remove(m_path); }

 private:
     boost::filesystem::path m_path;
 };
 }}}

 That might be something to add?

--
Ticket URL: <http://svn.boost.org/trac/boost/ticket/1090>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.


This archive was generated by hypermail 2.1.7 : 2017-02-16 18:49:56 UTC