From 5c6303dbee3b75e07e3ba0f0885be57ea5d5a712 Mon Sep 17 00:00:00 2001 From: Anthony Calandra Date: Fri, 26 Jun 2020 22:16:53 -0400 Subject: [PATCH] Add lambda captures of parameter packs. --- CPP20.md | 23 +++++++++++++++++++++++ README.md | 23 +++++++++++++++++++++++ 2 files changed, 46 insertions(+) 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