Opened 15 years ago
Last modified 14 years ago
#1090 new Feature Requests
scoped_file class that deletes file at end of scope
Reported by: | Owned by: | Beman Dawes | |
---|---|---|---|
Milestone: | To Be Determined | Component: | filesystem |
Version: | Severity: | Not Applicable | |
Keywords: | Cc: |
Description
I've found myself wanting this on a couple of occasions with 1.33.1, and I've done it with boost::shared_ptr:
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:
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?
Change History (4)
comment:1 by , 15 years ago
comment:2 by , 15 years ago
Owner: | set to |
---|
comment:3 by , 14 years ago
Type: | Patches → Feature Requests |
---|
comment:4 by , 14 years ago
What is lacking in the current proposal?
(Also, the c++ markup in the description seems to have failed. Could you edit that?)
Note:
See TracTickets
for help on using tickets.
Sorry! The shared_ptr impl should look like this: