diff --git a/CPP20.md b/CPP20.md index a118e54..7567eee 100644 --- a/CPP20.md +++ b/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 +auto f(Args&&... args){ + // BY VALUE: + return [...args = std::forward(args)] { + // ... + }; +} +``` +Capture parameter packs by reference: +```c++ +template +auto f(Args&&... args){ + // BY REFERENCE: + return [&...args = std::forward(args)] { + // ... + }; +} +``` + ## C++20 Library Features ### Concepts library diff --git a/README.md b/README.md index 62e666e..89a356b 100644 --- a/README.md +++ b/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 +auto f(Args&&... args){ + // BY VALUE: + return [...args = std::forward(args)] { + // ... + }; +} +``` +Capture parameter packs by reference: +```c++ +template +auto f(Args&&... args){ + // BY REFERENCE: + return [&...args = std::forward(args)] { + // ... + }; +} +``` + ## C++20 Library Features ### Concepts library