#include <iostream>
#include <chrono>
#include <future>
using std::cout;
using std::cin;
using std::endl;
int bar() { return 42; }
int main()
{
auto s2 = std::chrono::steady_clock::now();
auto sh_ptr1 = std::make_shared<std::packaged_task<int()> >(bar);
auto e2 = std::chrono::steady_clock::now();
auto s1 = std::chrono::steady_clock::now();
std::packaged_task<int()> pt1(bar);
auto e1 = std::chrono::steady_clock::now();
auto first = std::chrono::duration_cast<std::chrono::nanoseconds>(e1-s1);
auto second = std::chrono::duration_cast<std::chrono::nanoseconds>(e2-s2);
cout << "Regular: " << first.count() << endl
<< "Make shared: " << second.count() << endl;
pt1();
(*sh_ptr1)();
cout << "As you can see, both are working correctly: "
<< pt1.get_future().get() << " & "
<< sh_ptr1->get_future().get() << endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8Y2hyb25vPgojaW5jbHVkZSA8ZnV0dXJlPgoKdXNpbmcgc3RkOjpjb3V0Owp1c2luZyBzdGQ6OmNpbjsKdXNpbmcgc3RkOjplbmRsOwoKaW50IGJhcigpIHsgcmV0dXJuIDQyOyB9CgppbnQgbWFpbigpCnsKICAgIGF1dG8gczIgPSBzdGQ6OmNocm9ubzo6c3RlYWR5X2Nsb2NrOjpub3coKTsKICAgIGF1dG8gc2hfcHRyMSA9IHN0ZDo6bWFrZV9zaGFyZWQ8c3RkOjpwYWNrYWdlZF90YXNrPGludCgpPiA+KGJhcik7CiAgICBhdXRvIGUyID0gc3RkOjpjaHJvbm86OnN0ZWFkeV9jbG9jazo6bm93KCk7CgogICAgYXV0byBzMSA9IHN0ZDo6Y2hyb25vOjpzdGVhZHlfY2xvY2s6Om5vdygpOwogICAgc3RkOjpwYWNrYWdlZF90YXNrPGludCgpPiBwdDEoYmFyKTsKICAgIGF1dG8gZTEgPSBzdGQ6OmNocm9ubzo6c3RlYWR5X2Nsb2NrOjpub3coKTsKCiAgICBhdXRvIGZpcnN0ID0gc3RkOjpjaHJvbm86OmR1cmF0aW9uX2Nhc3Q8c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