#include <iostream>
#include <future>
using namespace std;
class Work {
private:
int val;
public:
Work(int t_val = 42) : val(t_val) {
cout << "constructor " << this << endl;
}
Work(const Work &other) {
this->val = other.val;
cout << "copy constructor " << this << endl;
}
std::future<int> spaw() {
cout << "in spaw " << endl;
return std::async([=, tmp = *this]() {
cout << "lambda " << this << endl;
return tmp.val;});
}
~Work() {
cout << "destructor " << this << endl;
}
};
std::future<int> foo() {
cout << "in foo " << endl;
Work t;
return t.spaw();
}
int main() {
cout << "in main " << endl;
std::future<int> f = foo();
f.wait();
cout << f.get() << endl;
return 0;
}