X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=folly%2Fexperimental%2FTestUtil.h;h=0f1ba3ebf2dcb4a22f490137392aaf9a2ed170f4;hb=017cae98c3f57090c998110042f4844653a86bc0;hp=b9481490df843c8d73bd3493693bce17b8deabcb;hpb=1badabb2b6715e70e47040711607e620c5952adf;p=folly.git diff --git a/folly/experimental/TestUtil.h b/folly/experimental/TestUtil.h index b9481490..0f1ba3eb 100644 --- a/folly/experimental/TestUtil.h +++ b/folly/experimental/TestUtil.h @@ -50,19 +50,37 @@ class TemporaryFile { 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_; + } }; /**