#include <iostream>
#include <array>
#include <limits>
#include <set>
#include <unordered_map>
#include <functional>
#include <memory>
#include <ostream>
#include <string>
#include <vector>
#include <map>
#include <optional>
#include <chrono>
#include <mutex>
#include <thread>
#include <utility>
using namespace std;
int main()
{
auto func = [](uint16_t a) -> bool {
cout<<a<<endl;
return true;
};
auto res = func(123);
cout<<res<<endl;
return 0;
}
Capture by Reference
#include <iostream>
#include <cassert>
#include <array>
#include <limits>
#include <set>
#include <unordered_map>
#include <functional>
#include <memory>
#include <ostream>
#include <string>
#include <vector>
#include <map>
#include <optional>
#include <chrono>
#include <mutex>
#include <thread>
#include <utility>
using namespace std;
int main()
{
int x = 10;
auto func = [&x]()
{
x++;
return true;
};
func();
assert(x == 11);
x++;
assert(x == 12);
func();
assert(x == 13);
cout << "ok" << endl;
return 0;
}
#include <iostream>
#include <cassert>
#include <array>
#include <limits>
#include <set>
#include <unordered_map>
#include <functional>
#include <memory>
#include <ostream>
#include <string>
#include <vector>
#include <map>
#include <optional>
#include <chrono>
#include <mutex>
#include <thread>
#include <utility>
#include <typeinfo>
using namespace std;
int main()
{
int *p;
auto func = [p]()
{
*p = 123;
};
func();
assert(*p == 123);
cout << "Ok" << endl;
return 0;
}