-
Notifications
You must be signed in to change notification settings - Fork 363
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1211 from guwirth/cpp17/lambda-capture-this
C++17 lambda extensions
- Loading branch information
Showing
9 changed files
with
123 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
cxx-squid/src/test/resources/parser/own/C++17/constexpr-lambdas.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
auto add1 = [](int a, int b) constexpr { return a + b; }; | ||
int arr[add1(1, 2)]; | ||
|
||
auto monoid = [](auto v) { return [=] { return v; }; }; | ||
auto add2 = [](auto m1) constexpr { | ||
auto ret = m1(); | ||
return [=](auto m2) mutable { | ||
auto m1val = m1(); | ||
auto plus = [=](auto m2val) mutable constexpr | ||
{ return m1val += m2val; }; | ||
ret = plus(m2()); | ||
return monoid(ret); | ||
}; | ||
}; |
10 changes: 10 additions & 0 deletions
10
cxx-squid/src/test/resources/parser/own/C++17/lambda-capture-this.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
struct my_struct { | ||
int x; | ||
void value(); | ||
}; | ||
|
||
void my_struct::value() { | ||
// Capture *this: This will allow the lambda expression to capture the enclosing object by copy. | ||
// This will make possible to use safely the lambda expression even after the enclosing object has been destroyed. | ||
[=, *this](){}; | ||
} |