Skip to content

Commit 4f7f677

Browse files
committed
Use std::exchange in directory
1 parent ea98470 commit 4f7f677

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

src/directory.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <filesystem>
66
#include <string_view>
77
#include <system_error>
8+
#include <utility>
89

910
namespace tmp {
1011
namespace {
@@ -100,7 +101,7 @@ directory::operator const fs::path&() const noexcept {
100101
}
101102

102103
const fs::path& directory::path() const noexcept {
103-
return *this;
104+
return pathobject;
104105
}
105106

106107
fs::path directory::operator/(std::string_view source) const {
@@ -124,16 +125,13 @@ directory::~directory() noexcept {
124125
}
125126

126127
directory::directory(directory&& other) noexcept
127-
: pathobject(std::move(other.pathobject)) {
128-
other.pathobject.clear();
129-
}
128+
: pathobject(std::exchange(other.pathobject, fs::path())) {}
130129

131130
directory& directory::operator=(directory&& other) noexcept {
131+
// TODO: should this throw in case of remove error?
132132
remove(*this);
133133

134-
pathobject = std::move(other.pathobject);
135-
other.pathobject.clear();
136-
134+
pathobject = std::exchange(other.pathobject, fs::path());
137135
return *this;
138136
}
139137
} // namespace tmp

0 commit comments

Comments
 (0)