aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2021-08-06 08:22:36 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2021-08-06 08:22:36 +0200
commit8653effc5751e68e36e7e86db7a953a00dde8439 (patch)
tree8a1157e0aec9b99c423e7e3bf8bb733db4b548da
parent205662986ed8e4cd15321ae2a94339da14b5c01f (diff)
Make fs::auto_remove movable
-rw-r--r--libcutl/fs/auto-remove.hxx30
1 files changed, 27 insertions, 3 deletions
diff --git a/libcutl/fs/auto-remove.hxx b/libcutl/fs/auto-remove.hxx
index c55f6f9..1badfa7 100644
--- a/libcutl/fs/auto-remove.hxx
+++ b/libcutl/fs/auto-remove.hxx
@@ -5,6 +5,7 @@
#define LIBCUTL_FS_AUTO_REMOVE_HXX
#include <vector>
+#include <utility>
#include <libcutl/fs/path.hxx>
#include <libcutl/fs/exception.hxx>
@@ -19,6 +20,11 @@ namespace cutl
//
struct LIBCUTL_EXPORT auto_remove
{
+ auto_remove ()
+ : canceled_ (true)
+ {
+ }
+
explicit
auto_remove (path const& p)
: path_ (p), canceled_ (false)
@@ -33,11 +39,29 @@ namespace cutl
canceled_ = true;
}
- private:
- auto_remove (auto_remove const&);
+ // Movable-only type. Move-assignment cancels the lhs object.
+ //
+ auto_remove (auto_remove&& x)
+ : path_ (std::move (x.path_)), canceled_ (x.canceled_)
+ {
+ x.canceled_ = true;
+ }
auto_remove&
- operator= (auto_remove const&);
+ operator= (auto_remove&& x)
+ {
+ if (this != &x)
+ {
+ path_ = std::move (x.path_);
+ canceled_ = x.canceled_;
+ x.canceled_ = true;
+ }
+
+ return *this;
+ }
+
+ auto_remove (auto_remove const&) = delete;
+ auto_remove& operator= (auto_remove const&) = delete;
private:
path path_;