#include #include #include #include #include using namespace std ; class Person { public: int age ; int id ; Person( int idP , int ageP ) { age = ageP ; id = idP ; } Person(const Person& obj1 ) { cout << "Copy constructor." << endl ; age = obj1.age ; id = obj1.id ; } ~Person() { cout << "Person Destructor." << endl ; } }; void swapM( int& x1, int& x2 ) { int temp ; temp = x1 ; x1 = x2 ; x2 = x1 ; } int main() { int a1 = 10 ; int a2 = 11 ; //TO DO Write a lambda expression to replace swapM //The capture clause [] is empty auto swap1 = [](int& x1, int& x2 ){ int temp ; temp = x1 ; x1 = x2 ; x2 = temp ; } ; swap1(a1, a2 ) ; cout << "a1:" << a1 << " " << "a2:" << a2 << endl ; Person person(1 , 50 ) ; //Pass this object ( "person") by value to a lambda and print // the id and age. { //TO DO Write the code for the lambda in the curly braces //Does the copy constructor get called. When does the object //in the lambda get destroyed ? auto print1 = [=](){ cout << person.id << " " << person.age << endl ; }; print1() ; } //Pass this object ( "person") by reference to a lambda and print // the id and age. How is this different from the calling by //value above ? auto print2 = [&](){ cout << person.id << " " << person.age << endl ; }; print2() ; }