mirror of
https://github.com/AnthonyCalandra/modern-cpp-features.git
synced 2025-12-16 17:47:02 +03:00
Add lambda captures of parameter packs.
This commit is contained in:
23
CPP20.md
23
CPP20.md
@@ -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
|
||||
|
||||
23
README.md
23
README.md
@@ -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)
|
||||
@@ -433,6 +434,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
|
||||
|
||||
Reference in New Issue
Block a user