From: Adam Simpkins <simpkins@fb.com>
Date: Thu, 26 Mar 2015 19:40:56 +0000 (-0700)
Subject: TemporaryFile and TemporaryDirectory
X-Git-Tag: v0.33.0~23
X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=bf0d21438a2bccef4d851f12bd90e6cb371be22f;p=folly.git

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
---

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: