C++ features by examples
Collaboration diagram for More complex Lambdas:

Functions

static void lambda_complex (void)
 

Detailed Description

Function Documentation

◆ lambda_complex()

static void lambda_complex ( void  )
static

Definition at line 531 of file 11.cpp.

532{
533 auto increment = [] (int a) -> int { return a + 1; };
534 assert(increment(5) == 6);
535
536 // named lambda as argument
537 assert(use_lambda(2, increment) == 3);
538 set_lambda(increment);
539 assert(call_lambda(3) == 4);
540
541 // inline lambda as argument
542 assert(use_lambda(1, [](int a) {return a + 1;}) == 2);
543
544 int x = 0;
545 [x] () mutable { assert(++x);}();
546 assert(x == 0);
547}
Here is the caller graph for this function: