diff --git a/CPP17.md b/CPP17.md index e22ae62..97ebeb7 100644 --- a/CPP17.md +++ b/CPP17.md @@ -28,6 +28,7 @@ C++17 includes the following new library features: - [std::filesystem](#stdfilesystem) - [std::byte](#stdbyte) - [splicing for maps and sets](#splicing-for-maps-and-sets) +- [parallel algorithms](#parallel-algorithms) ## C++17 Language Features @@ -394,6 +395,17 @@ m.insert(std::move(e)); // m == { { 1, "one" }, { 3, "three" }, { 4, "two" } } ``` +### Parallel algorithms +Many of the STL algorithms, such as the `copy`, `find` and `sort` methods, started to support the *parallel execution policies*: `seq`, `par` and `par_unseq` which translate to "sequentially", "parallel" and "parallel unsequenced". + +```c++ +std::vector longVector; +// Find element using parallel execution policy +auto result1 = std::find(std::execution::par, std::begin(longVector), std::end(longVector), 2); +// Sort elements using sequential execution policy +auto result2 = std::sort(std::execution::seq, std::begin(longVector), std::end(longVector)); +``` + ## 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. diff --git a/README.md b/README.md index 6943aaf..f1036e0 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,7 @@ C++17 includes the following new library features: - [std::filesystem](#stdfilesystem) - [std::byte](#stdbyte) - [splicing for maps and sets](#splicing-for-maps-and-sets) +- [parallel algorithms](#parallel-algorithms) C++14 includes the following new language features: - [binary literals](#binary-literals) @@ -453,6 +454,17 @@ m.insert(std::move(e)); // m == { { 1, "one" }, { 3, "three" }, { 4, "two" } } ``` +### Parallel algorithms +Many of the STL algorithms, such as the `copy`, `find` and `sort` methods, started to support the *parallel execution policies*: `seq`, `par` and `par_unseq` which translate to "sequentially", "parallel" and "parallel unsequenced". + +```c++ +std::vector longVector; +// Find element using parallel execution policy +auto result1 = std::find(std::execution::par, std::begin(longVector), std::end(longVector), 2); +// Sort elements using sequential execution policy +auto result2 = std::sort(std::execution::seq, std::begin(longVector), std::end(longVector)); +``` + ## C++14 Language Features ### Binary literals