#include <iostream>
#include <functional>
#include <string>
struct TestA
{
std::string s;
TestA(){}
TestA(std::string const&s) : s(s) {}
TestA(TestA const&) = default;
TestA(TestA &&) = default;
TestA &operator=(TestA const&) = default;
TestA &operator=(TestA &&) = default;
~TestA() = default;
};
template<typename T, typename... Args>
std::function<T &&(Args...)> WrapCtor()
{
return [](Args... args) -> T &&
{
return T(args...);
};
}
int main()
{
auto f = WrapCtor<TestA, std::string const&>();
TestA inst = f("test");
std::cout << inst.s << std::endl;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8ZnVuY3Rpb25hbD4KI2luY2x1ZGUgPHN0cmluZz4KCnN0cnVjdCBUZXN0QQp7CiAgICBzdGQ6OnN0cmluZyBzOwogICAgVGVzdEEoKXt9CiAgICBUZXN0QShzdGQ6OnN0cmluZyBjb25zdCZzKSA6IHMocykge30KICAgIFRlc3RBKFRlc3RBIGNvbnN0JikgPSBkZWZhdWx0OwogICAgVGVzdEEoVGVzdEEgJiYpID0gZGVmYXVsdDsKICAgIFRlc3RBICZvcGVyYXRvcj0oVGVzdEEgY29uc3QmKSA9IGRlZmF1bHQ7CiAgICBUZXN0QSAmb3BlcmF0b3I9KFRlc3RBICYmKSA9IGRlZmF1bHQ7CiAgICB+VGVzdEEoKSA9IGRlZmF1bHQ7Cn07Cgp0ZW1wbGF0ZTx0eXBlbmFtZSBULCB0eXBlbmFtZS4uLiBBcmdzPgpzdGQ6OmZ1bmN0aW9uPFQgJiYoQXJncy4uLik+IFdyYXBDdG9yKCkKewogICAgcmV0dXJuIFtdKEFyZ3MuLi4gYXJncykgLT4gVCAmJgogICAgewogICAgICAgIHJldHVybiBUKGFyZ3MuLi4pOwogICAgfTsKfQoKaW50IG1haW4oKQp7CiAgICBhdXRvIGYgPSBXcmFwQ3RvcjxUZXN0QSwgc3RkOjpzdHJpbmcgY29uc3QmPigpOwogICAgVGVzdEEgaW5zdCA9IGYoInRlc3QiKTsKICAgIHN0ZDo6Y291dCA8PCBpbnN0LnMgPDwgc3RkOjplbmRsOwp9Cg==