Add lambda captures of parameter packs.

This commit is contained in:
Anthony Calandra
2020-06-26 22:16:53 -04:00
parent aff25ca533
commit 5c6303dbee
2 changed files with 46 additions and 0 deletions

View File

@@ -15,6 +15,7 @@ C++20 includes the following new language features:
- [explicit(bool)](#explicitbool)
- [immediate functions](#immediate-functions)
- [using enum](#using-enum)
- [lambda capture of parameter pack](#lambda-capture-of-parameter-pack)
C++20 includes the following new library features:
- [concepts library](#concepts-library)
@@ -340,6 +341,28 @@ std::string_view to_string(rgba_color_channel my_channel) {
}
```
### Lambda capture of parameter pack
Capture parameter packs by value:
```c++
template <typename... Args>
auto f(Args&&... args){
// BY VALUE:
return [...args = std::forward<Args>(args)] {
// ...
};
}
```
Capture parameter packs by reference:
```c++
template <typename... Args>
auto f(Args&&... args){
// BY REFERENCE:
return [&...args = std::forward<Args>(args)] {
// ...
};
}
```
## C++20 Library Features
### Concepts library