1 2 3 4 5 6 7 8 9 10 11 12 13 | #include <memory> template<typename T, typename... Args> std::unique_ptr<T> make_unique(Args&&... args) { return std::unique_ptr<T>(new T(std::forward(args)...)); } struct A { A(int,int) {} }; int main() { auto p = make_unique<A>(1, 2); (void)p; } |
I2luY2x1ZGUgPG1lbW9yeT4KCnRlbXBsYXRlPHR5cGVuYW1lIFQsIHR5cGVuYW1lLi4uIEFyZ3M+CnN0ZDo6dW5pcXVlX3B0cjxUPiBtYWtlX3VuaXF1ZShBcmdzJiYuLi4gYXJncykKewogICAgcmV0dXJuIHN0ZDo6dW5pcXVlX3B0cjxUPihuZXcgVChzdGQ6OmZvcndhcmQoYXJncykuLi4pKTsKfQoKc3RydWN0IEEgeyBBKGludCxpbnQpIHt9IH07CgppbnQgbWFpbigpIHsKICBhdXRvIHAgPSBtYWtlX3VuaXF1ZTxBPigxLCAyKTsgKHZvaWQpcDsKfQ==
prog.cpp: In function 'std::unique_ptr<T> make_unique(Args&& ...) [with T = A, Args = {int, int}]':
prog.cpp:12:31: instantiated from here
prog.cpp:6:59: error: no matching function for call to 'forward(int&)'
-
result: Compilation error (maybe you wish to see an example for C++11)


