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

@@ -26,6 +26,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++17 Language Features
@@ -365,6 +366,22 @@ 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"));
}
}
```
## Acknowledgements
* [cppreference](http://en.cppreference.com/w/cpp) - especially useful for finding examples and documentation of new library features.
* [C++ Rvalue References Explained](http://thbecker.net/articles/rvalue_references/section_01.html) - a great introduction I used to understand rvalue references, perfect forwarding, and move semantics.