summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2022-04-14 00:02:42 +0200
committerCarl Hetherington <cth@carlh.net>2022-05-05 21:46:30 +0200
commit00e10ea721796f660b3479eb6f862125c255dc88 (patch)
tree3ac7b8990abd31e90c2b4f7a198b83aed4f91fd6 /src
parent915991a1accee95cfe6341a286c6ecedf4f0012b (diff)
Add move constructor.
Diffstat (limited to 'src')
-rw-r--r--src/file.cc20
-rw-r--r--src/file.h4
2 files changed, 24 insertions, 0 deletions
diff --git a/src/file.cc b/src/file.cc
index 9ee91fe7..74db8396 100644
--- a/src/file.cc
+++ b/src/file.cc
@@ -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()
{
diff --git a/src/file.h b/src/file.h
index bedceada..26d0704a 100644
--- a/src/file.h
+++ b/src/file.h
@@ -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;