bool closeOnDestruction = true);
~TemporaryFile();
- // Movable, but not copiable
- TemporaryFile(TemporaryFile&&) = default;
- TemporaryFile& operator=(TemporaryFile&&) = default;
+ // Movable, but not copyable
+ TemporaryFile(TemporaryFile&& other) noexcept {
+ reset();
+ assign(other);
+ }
+
+ TemporaryFile& operator=(TemporaryFile&& other) {
+ if (this != &other) {
+ reset();
+ assign(other);
+ }
+ return *this;
+ }
void close();
int fd() const { return fd_; }
const fs::path& path() const;
+ void reset();
private:
Scope scope_;
bool closeOnDestruction_;
int fd_;
fs::path path_;
+
+ void assign(TemporaryFile& other) {
+ scope_ = other.scope_;
+ closeOnDestruction_ = other.closeOnDestruction_;
+ fd_ = std::exchange(other.fd_, -1);
+ path_ = other.path_;
+ }
};
/**