#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+VGVzdEEoKSA9IGRlZmF1bHQ7Cn07Cgp0ZW1wbGF0ZTx0eXBlbmFtZSBULCB0eXBlbmFtZS4uLiBBcmdzPgpzdGQ6OmZ1bmN0aW9uPFQgKEFyZ3MuLi4pPiBXcmFwQ3RvcigpCnsKICAgIHJldHVybiBbXShBcmdzLi4uIGFyZ3MpIC0+IFQKICAgIHsKICAgICAgICByZXR1cm4gVChhcmdzLi4uKTsKICAgIH07Cn0KCmludCBtYWluKCkKewogICAgYXV0byBmID0gV3JhcEN0b3I8VGVzdEEsIHN0ZDo6c3RyaW5nIGNvbnN0Jj4oKTsKICAgIFRlc3RBIGluc3QgPSBmKCJ0ZXN0Iik7CiAgICBzdGQ6OmNvdXQgPDwgaW5zdC5zIDw8IHN0ZDo6ZW5kbDsKfQo=