Commit bf0d2143 authored by Adam Simpkins's avatar Adam Simpkins Committed by afrind

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
parent 3e447ce4
......@@ -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:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment