From bf0d21438a2bccef4d851f12bd90e6cb371be22f Mon Sep 17 00:00:00 2001 From: Adam Simpkins Date: Thu, 26 Mar 2015 12:40:56 -0700 Subject: [PATCH] TemporaryFile and TemporaryDirectory Summary: TemporaryFile, TemporaryDirectory, and ChangeToTempDir should all be moveable objects, but not copiable. Define default move constructors and move assignment operators for these classes. This will prevent copy constructor and copy assignment operators from being implicitly defined. Test Plan: Used this in a new test to write a helper function which created and returned a new TemporaryFile object using the move constructor. Reviewed By: yfeldblum@fb.com Subscribers: doug, net-systems@, exa, folly-diffs@, yfeldblum FB internal diff: D1945134 Signature: t1:1945134:1427342944:3428327e797ce4b3d362f9a2d2276de6d8b96137 --- folly/experimental/TestUtil.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/folly/experimental/TestUtil.h b/folly/experimental/TestUtil.h index adf8be39..30687bf7 100644 --- a/folly/experimental/TestUtil.h +++ b/folly/experimental/TestUtil.h @@ -48,6 +48,10 @@ class TemporaryFile { bool closeOnDestruction = true); ~TemporaryFile(); + // Movable, but not copiable + TemporaryFile(TemporaryFile&&) = default; + TemporaryFile& operator=(TemporaryFile&&) = default; + int fd() const { return fd_; } const fs::path& path() const; @@ -81,6 +85,10 @@ class TemporaryDirectory { Scope scope = Scope::DELETE_ON_DESTRUCTION); ~TemporaryDirectory(); + // Movable, but not copiable + TemporaryDirectory(TemporaryDirectory&&) = default; + TemporaryDirectory& operator=(TemporaryDirectory&&) = default; + const fs::path& path() const { return path_; } private: @@ -97,6 +105,10 @@ public: ChangeToTempDir(); ~ChangeToTempDir(); + // Movable, but not copiable + ChangeToTempDir(ChangeToTempDir&&) = default; + ChangeToTempDir& operator=(ChangeToTempDir&&) = default; + const fs::path& path() const { return dir_.path(); } private: -- 2.34.1