File: std-function-lambda-capture.cpp

package info (click to toggle)
cupt 2.10.4%2Bnmu2
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 3,144 kB
  • sloc: cpp: 23,642; perl: 1,599; sh: 40; makefile: 19
file content (26 lines) | stat: -rw-r--r-- 368 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <functional>
#include <iostream>

void* g = nullptr;

struct C
{
	void doCb()
	{
		size_t dummy_a = 1;

		std::cout << "Outside: " << this << std::endl;
		std::function<void ()> f;
		f = [this, &dummy_a]() {};
		f = [this]() { g = this; std::cout << "Inside: " << this << std::endl; };
		f();
	}
};

int main()
{
	C c;
	c.doCb();
	return g == &c ? 0 : 77;
}