#include <iostream>
#include <memory>
std::pair<std::function<int()>, std::function<int()>> addSome() {
auto numbers = std::make_shared<std::pair<int, int>>(0, 0);
return std::make_pair([numbers] {
++numbers->first;
++numbers->second;
return numbers->first + numbers->second;
}, [numbers] {
return numbers->first;
});
}
int main() {
auto f = addSome();
std::cout << f.first();
std::cout << " " << f.second();
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8bWVtb3J5PgoKc3RkOjpwYWlyPHN0ZDo6ZnVuY3Rpb248aW50KCk+LCBzdGQ6OmZ1bmN0aW9uPGludCgpPj4gYWRkU29tZSgpIHsKCWF1dG8gbnVtYmVycyA9IHN0ZDo6bWFrZV9zaGFyZWQ8c3RkOjpwYWlyPGludCwgaW50Pj4oMCwgMCk7CgkKICAgIHJldHVybiBzdGQ6Om1ha2VfcGFpcihbbnVtYmVyc10gewogICAgCSsrbnVtYmVycy0+Zmlyc3Q7CiAgICAJKytudW1iZXJzLT5zZWNvbmQ7CiAgICAgICAgcmV0dXJuIG51bWJlcnMtPmZpcnN0ICsgbnVtYmVycy0+c2Vjb25kOwogICAgICAgIH0sIFtudW1iZXJzXSB7CiAgICAgICAgICAgIHJldHVybiBudW1iZXJzLT5maXJzdDsKICAgICAgICB9KTsKfQoKaW50IG1haW4oKSB7CiAgICBhdXRvIGYgPSBhZGRTb21lKCk7CiAgICBzdGQ6OmNvdXQgPDwgZi5maXJzdCgpOwogICAgc3RkOjpjb3V0IDw8ICIgIiA8PCBmLnNlY29uZCgpOwogICAgcmV0dXJuIDA7Cn0=