From 8653effc5751e68e36e7e86db7a953a00dde8439 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Fri, 6 Aug 2021 08:22:36 +0200 Subject: Make fs::auto_remove movable --- libcutl/fs/auto-remove.hxx | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) (limited to 'libcutl') 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 +#include #include #include @@ -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_; -- cgit v1.1