Qt_GUI_BG_3_1 - 8BitsCoding/RobotMentor GitHub Wiki
๋๋ค์์ ๊ธฐ๋ณธ๊ตฌ์กฐ
#include<iostream>usingnamespacestd;intmain()
{
/* ๋๋ค์ ๊ธฐ๋ณธ์์ ๋ค์๊ณผ ๊ฐ๋ค. [capture list] (parameter list) {function body}*/// Give lambda function a name and call itauto func = []() {
cout << "Hello World!" << endl;
};
func();
// Call lambda function directly after definition
[]() {
cout << "Hello World!" << endl;
}(); // ์์๊ณผ ๋์์ ๋์// Define a lambda function that takes parameters
[](int a, int b) {
cout << " a + b = " << a + b << endl;
}(7,3);
// Define a lambda that returns somethingint sum = [](int a, int b)->int{
cout << " a + b = " << a + b << endl;
return a + b;
}(7, 3);
cout << "The sum is : " << sum << endl;
// Capture Listsint a = 7;
int b = 3;
[a,b]() {
cout << "a is : " << a << endl;
cout << "b is : " << b << endl;
}();
// Caturing by value & referenceint c = 42;
// auto func = [c]() {auto func = [&c]() {
cout << "The value of c is : " << c << endl;
};
for (int i = 1; i < 5; i++) {
cout << "The outer value of c is : " << c << endl;
func();
c++;
}
// Caturing everything by value & referenceint c = 42;
//auto func = [=]() {auto func = [&]() {
cout << "The value of c is : " << c << endl;
};
for (int i = 1; i < 5; i++) {
cout << "The outer value of c is : " << c << endl;
func();
c++;
}
return0;
}