Skip to content

Commit d327d01

Browse files
committed
Simplify stream function
1 parent 7da9b92 commit d327d01

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

lib/file.cpp

+10-8
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,20 @@ namespace tmp {
88
namespace {
99

1010
/// Opens a temporary file for writing and returns an output file stream
11-
/// @param file The file to open
12-
/// @param binary Whether to open the file in binary mode (true) or text mode (false)
13-
/// @param append Whether to append to the end of the file (true) or truncate it (false)
11+
/// @param file The file to open
12+
/// @param binary Whether to open the file in binary mode
13+
/// @param append Whether to append to the end of the file
1414
/// @return An output file stream
1515
std::ofstream stream(const file& file, bool binary, bool append) noexcept {
1616
std::ios::openmode mode = append ? std::ios::app : std::ios::trunc;
17-
auto path = static_cast<const std::filesystem::path&>(file);
18-
return binary
19-
? std::ofstream { path, mode | std::ios::binary }
20-
: std::ofstream { path, mode };
21-
}
17+
if (binary) {
18+
mode |= std::ios::binary;
19+
}
20+
21+
const std::filesystem::path& path = file;
22+
return std::ofstream { path, mode };
2223
}
24+
} // namespace
2325

2426
file::file(std::string_view prefix) : file(prefix, /*binary=*/true) {
2527
}

lib/path.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ void remove(const tmp::path& path) noexcept {
1414
std::filesystem::remove_all(path, ec);
1515
}
1616
}
17-
1817
} // namespace
1918

2019
namespace tmp {

0 commit comments

Comments
 (0)