mirror of
https://github.com/AnthonyCalandra/modern-cpp-features.git
synced 2025-12-17 10:04:35 +03:00
committed by
Anthony Calandra
parent
36729c1716
commit
12b9992c01
17
CPP17.md
17
CPP17.md
@@ -26,6 +26,7 @@ C++17 includes the following new library features:
|
|||||||
- [std::invoke](#stdinvoke)
|
- [std::invoke](#stdinvoke)
|
||||||
- [std::apply](#stdapply)
|
- [std::apply](#stdapply)
|
||||||
- [splicing for maps and sets](#splicing-for-maps-and-sets)
|
- [splicing for maps and sets](#splicing-for-maps-and-sets)
|
||||||
|
- [std::filesystem](#stdfilesystem)
|
||||||
|
|
||||||
## C++17 Language Features
|
## C++17 Language Features
|
||||||
|
|
||||||
@@ -365,6 +366,22 @@ m.insert(std::move(e));
|
|||||||
// m == { { 1, "one" }, { 3, "three" }, { 4, "two" } }
|
// 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
|
## Acknowledgements
|
||||||
* [cppreference](http://en.cppreference.com/w/cpp) - especially useful for finding examples and documentation of new library features.
|
* [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.
|
* [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.
|
||||||
|
|||||||
16
README.md
16
README.md
@@ -28,6 +28,7 @@ C++17 includes the following new library features:
|
|||||||
- [std::invoke](#stdinvoke)
|
- [std::invoke](#stdinvoke)
|
||||||
- [std::apply](#stdapply)
|
- [std::apply](#stdapply)
|
||||||
- [splicing for maps and sets](#splicing-for-maps-and-sets)
|
- [splicing for maps and sets](#splicing-for-maps-and-sets)
|
||||||
|
- [std::filesystem](#stdfilesystem)
|
||||||
|
|
||||||
C++14 includes the following new language features:
|
C++14 includes the following new language features:
|
||||||
- [binary literals](#binary-literals)
|
- [binary literals](#binary-literals)
|
||||||
@@ -423,6 +424,21 @@ e.key() = 4;
|
|||||||
m.insert(std::move(e));
|
m.insert(std::move(e));
|
||||||
// m == { { 1, "one" }, { 3, "three" }, { 4, "two" } }
|
// 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
|
## C++14 Language Features
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user