-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCapture.cpp
23 lines (17 loc) · 833 Bytes
/
Capture.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
struct S2 { void f(int i); };
void S2::f(int i)
{
[&]{}; // OK: by-reference capture default
[&, i]{}; // OK: by-reference capture, except i is captured by copy
[&, &i] {}; // Warning: by-reference capture when by-reference is the default
[&, this] {}; // OK, equivalent to [&]
[&, this, i]{}; // OK, equivalent to [&, i]
[=]{}; // OK: by-copy capture default
[=, &i]{}; // OK: by-copy capture, except i is captured by reference
// [=, *this]{}; // until C++17: Error: invalid syntax
// since C++17: OK: captures the enclosing S2 by copy
[=, this] {}; // until C++20:
// Until C++20: Warning: explicit by-copy capture of ‘this’ redundant with by-copy capture default
// Since C++20: OK, same as [=]
}
int main(){return 0;}