Add move constructor.
authorCarl Hetherington <cth@carlh.net>
Wed, 13 Apr 2022 22:02:42 +0000 (00:02 +0200)
committerCarl Hetherington <cth@carlh.net>
Thu, 5 May 2022 19:46:30 +0000 (21:46 +0200)
src/file.cc
src/file.h

index 9ee91fe709aa03c36503d6c03eb1c6834b89f624..74db83965e1fa8d89043ef6135f4cd13eb791cf1 100644 (file)
@@ -58,6 +58,26 @@ File::File(boost::filesystem::path path, std::string mode)
 }
 
 
+File::File(File&& other)
+       : _path(other._path)
+       , _file(other._file)
+{
+       other._file = nullptr;
+}
+
+
+File&
+File::operator=(File&& other)
+{
+       if (*this != other) {
+               close();
+               _file = other._file;
+               other._file = nullptr;
+       }
+       return *this;
+}
+
+
 void
 File::close()
 {
index bedceada7140254719d1953a923355a7b3b8f80c..26d0704a6ae42af53fa1f7dd24be75b898f9b09e 100644 (file)
@@ -52,6 +52,10 @@ public:
         *  @param mode mode flags, as for fopen(3)
         */
        File(boost::filesystem::path, std::string mode);
+
+       File(File&& other);
+       File& operator=(File&& other);
+
        ~File();
 
        File(File const&) = delete;