https://en.cppreference.com/w/cpp/language/lambda https://www.geeksforgeeks.org/lambda-expression-in-c/
◆ algorithm_11()
algorithm
Definition at line 478 of file 11.cpp.
480 vector<int> v = {1, 2, 3};
481 assert(find(begin(v), end(v), 0) == end(v));
482 assert(find(begin(v), end(v), 1) != end(v));
◆ container_11()
container
forward_list
Definition at line 444 of file 11.cpp.
447 vector<int> v = {1, 2, 3};
448 assert(v.data()[2] == 3);
452 v.emplace(v.cbegin(), 0);
453 assert(v.front() == 0);
456 assert(v.back() == 4);
458 array<int, 1> a1, a2;
462 forward_list<int> fl;
465 assert(fl.front() == 1);
467 assert(fl.front() == 2);
468 fl.insert_after(fl.cbegin(), 3);
469 assert(fl.front() + 1 == 3);
470 assert(fl.front() == 2);
471 fl.erase_after(fl.cbefore_begin());
472 assert(fl.front() == 3);
◆ lambda_basics()
static void lambda_basics |
( |
void |
| ) |
|
|
static |
Definition at line 350 of file 11.cpp.
352 auto annotated_named_lambda_expression =
362 auto closure = [] { };
367 auto pass = [] (
int a) {
return a; };
368 assert(pass(5) == 5);
372 auto get_i = [=] () {
return c; };
373 assert(get_i() == 1);
377 auto inc_get = [&] {
return ++c; };
378 assert(inc_get() == 2);
379 assert(inc_get() == 3);
401 assert([](
int a) {
return a + 1; }(1) == 2);
◆ lambda_capture()
static void lambda_capture |
( |
void |
| ) |
|
|
static |
Definition at line 411 of file 11.cpp.
415 assert([=]{
return i; }() == 2);
418 [&](
int a){i = a;}(3);
423 [i, &j](){ j = i; }();
428 [=, &j](){ j = i; }();
433 [&, i](){ j = i; }();
437 auto inc_global = [] () {
return ++glob; };
438 assert(inc_global() == 1);
439 assert(inc_global() == 2);
◆ sort_11()
Compare with sort_03.
array
Definition at line 487 of file 11.cpp.
491 array<int, 10> s {5, 7, 4, 2, 8, 6, 1, 9, 0, 3};
492 sort(s.begin(), s.end(),