From 00e10ea721796f660b3479eb6f862125c255dc88 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Thu, 14 Apr 2022 00:02:42 +0200 Subject: Add move constructor. --- src/file.cc | 20 ++++++++++++++++++++ src/file.h | 4 ++++ 2 files changed, 24 insertions(+) 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; -- cgit v1.2.3