Add filesystem library (#38)

* Add filesystem library
This commit is contained in:
Tulio Leao
2018-08-20 12:24:54 -03:00
committed by Anthony Calandra
parent 36729c1716
commit 12b9992c01
2 changed files with 33 additions and 0 deletions

View File

@@ -28,6 +28,7 @@ C++17 includes the following new library features:
- [std::invoke](#stdinvoke)
- [std::apply](#stdapply)
- [splicing for maps and sets](#splicing-for-maps-and-sets)
- [std::filesystem](#stdfilesystem)
C++14 includes the following new language features:
- [binary literals](#binary-literals)
@@ -423,6 +424,21 @@ e.key() = 4;
m.insert(std::move(e));
// m == { { 1, "one" }, { 3, "three" }, { 4, "two" } }
```
### std::filesystem
The new `std::filesystem` library provides a standard way to manipulate files, directories, and paths in a filesystem.
Here, a big file is copied to a temporary path if there is available space:
```c++
const auto bigFilePath {"bigFileToCopy"};
if (std::filesystem::exists(bigFilePath)) {
const auto bigFileSize {std::filesystem::file_size(bigFilePath)};
std::filesystem::path tmpPath {"/tmp"};
if (std::filesystem::space(tmpPath).available > bigFileSize) {
std::filesystem::create_directory(tmpPath.append("example"));
std::filesystem::copy_file(bigFilePath, tmpPath.append("newFile"));
}
}
```
## C++14 Language Features