mirror of
https://github.com/AnthonyCalandra/modern-cpp-features.git
synced 2025-12-17 18:14:36 +03:00
committed by
Anthony Calandra
parent
4eb1a3ff5f
commit
b785d8f971
18
CPP11.md
18
CPP11.md
@@ -49,6 +49,7 @@ C++11 includes the following new library features:
|
|||||||
- [std::make_shared](#stdmake_shared)
|
- [std::make_shared](#stdmake_shared)
|
||||||
- [memory model](#memory-model)
|
- [memory model](#memory-model)
|
||||||
- [std::async](#stdasync)
|
- [std::async](#stdasync)
|
||||||
|
- [std::begin/end](#stdbeginend)
|
||||||
|
|
||||||
## C++11 Language Features
|
## C++11 Language Features
|
||||||
|
|
||||||
@@ -874,6 +875,23 @@ auto handle = std::async(std::launch::async, foo); // create an async task
|
|||||||
auto result = handle.get(); // wait for the result
|
auto result = handle.get(); // wait for the result
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### std::begin/end
|
||||||
|
`std::begin` and `std::end` free functions were added to return begin and end iterators of a container generically. These functions also work with raw arrays which do not have begin and end member functions.
|
||||||
|
|
||||||
|
```c++
|
||||||
|
template <typename T>
|
||||||
|
int CountTwos(const T& container) {
|
||||||
|
return std::count_if(std::begin(container), std::end(container), [](int item) {
|
||||||
|
return item == 2;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<int> vec = {2,2,43,435,4543,534};
|
||||||
|
int arr[8] = {2,43,45,435,32,32,32,32};
|
||||||
|
auto a = CountTwos(vec); // 2
|
||||||
|
auto b = CountTwos(arr); // 1
|
||||||
|
```
|
||||||
|
|
||||||
## 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.
|
||||||
|
|||||||
18
README.md
18
README.md
@@ -98,6 +98,7 @@ C++11 includes the following new library features:
|
|||||||
- [std::make_shared](#stdmake_shared)
|
- [std::make_shared](#stdmake_shared)
|
||||||
- [memory model](#memory-model)
|
- [memory model](#memory-model)
|
||||||
- [std::async](#stdasync)
|
- [std::async](#stdasync)
|
||||||
|
- [std::begin/end](#stdbeginend)
|
||||||
|
|
||||||
## C++20 Language Features
|
## C++20 Language Features
|
||||||
|
|
||||||
@@ -1698,6 +1699,23 @@ auto handle = std::async(std::launch::async, foo); // create an async task
|
|||||||
auto result = handle.get(); // wait for the result
|
auto result = handle.get(); // wait for the result
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### std::begin/end
|
||||||
|
`std::begin` and `std::end` free functions were added to return begin and end iterators of a container generically. These functions also work with raw arrays which do not have begin and end member functions.
|
||||||
|
|
||||||
|
```c++
|
||||||
|
template <typename T>
|
||||||
|
int CountTwos(const T& container) {
|
||||||
|
return std::count_if(std::begin(container), std::end(container), [](int item) {
|
||||||
|
return item == 2;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<int> vec = {2,2,43,435,4543,534};
|
||||||
|
int arr[8] = {2,43,45,435,32,32,32,32};
|
||||||
|
auto a = CountTwos(vec); // 2
|
||||||
|
auto b = CountTwos(arr); // 1
|
||||||
|
```
|
||||||
|
|
||||||
## 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.
|
||||||
|
|||||||
Reference in New Issue
Block a user