#include <memory>
template<typename T>
struct Helper
{
template<template<typename...> class Wrapper = std::unique_ptr, typename... Args>
static Wrapper<T, Args...> Wrap(T const &t)
{
return Wrapper<T, Args...>{new T{t}};
}
};
template<typename T, template<typename...> typename Wrapper = std::unique_ptr, typename... Args>
struct WrapperHelper final
{
};
int main()
{
int x = 0;
auto c1 = Helper<int>::Wrap<>(x);
auto c2 = Helper<int>::Wrap<std::shared_ptr>(x);
auto c3 = Helper<int>::Wrap<WrapperHelper, int>(*c1);
}
I2luY2x1ZGUgPG1lbW9yeT4KCnRlbXBsYXRlPHR5cGVuYW1lIFQ+CnN0cnVjdCBIZWxwZXIKewoJdGVtcGxhdGU8dGVtcGxhdGU8dHlwZW5hbWUuLi4+IGNsYXNzIFdyYXBwZXIgPSBzdGQ6OnVuaXF1ZV9wdHIsIHR5cGVuYW1lLi4uIEFyZ3M+CglzdGF0aWMgV3JhcHBlcjxULCBBcmdzLi4uPiBXcmFwKFQgY29uc3QgJnQpCgl7CgkJcmV0dXJuIFdyYXBwZXI8VCwgQXJncy4uLj57bmV3IFR7dH19OwoJfQp9OwoKdGVtcGxhdGU8dHlwZW5hbWUgVCwgdGVtcGxhdGU8dHlwZW5hbWUuLi4+IHR5cGVuYW1lIFdyYXBwZXIgPSBzdGQ6OnVuaXF1ZV9wdHIsIHR5cGVuYW1lLi4uIEFyZ3M+CnN0cnVjdCBXcmFwcGVySGVscGVyIGZpbmFsCnsKfTsKCmludCBtYWluKCkKewoJaW50IHggPSAwOwoJYXV0byBjMSA9IEhlbHBlcjxpbnQ+OjpXcmFwPD4oeCk7CglhdXRvIGMyID0gSGVscGVyPGludD46OldyYXA8c3RkOjpzaGFyZWRfcHRyPih4KTsKCWF1dG8gYzMgPSBIZWxwZXI8aW50Pjo6V3JhcDxXcmFwcGVySGVscGVyLCBpbnQ+KCpjMSk7Cn0K
prog.cpp: In function 'int main()':
prog.cpp:22:48: error: no matching function for call to 'Helper<int>::Wrap(int&)'
auto c2 = Helper<int>::Wrap<std::shared_ptr>(x);
^
prog.cpp:7:29: note: candidate: template<template<class ...> class typedef Wrapper Wrapper, class ... Args> static Wrapper<T, Args ...> Helper<T>::Wrap(const T&) [with Wrapper = Wrapper; Args = {Args ...}; T = int]
static Wrapper<T, Args...> Wrap(T const &t)
^
prog.cpp:7:29: note: template argument deduction/substitution failed:
prog.cpp: In substitution of 'template<template<class ...> class typedef Wrapper Wrapper, class ... Args> static Wrapper<T, Args ...> Helper<T>::Wrap(const T&) [with typedef Wrapper Wrapper = std::shared_ptr; Args = {}]':
prog.cpp:22:48: required from here
prog.cpp:7:29: error: wrong number of template arguments (2, should be 1)
In file included from /usr/include/c++/5/bits/shared_ptr.h:52:0,
from /usr/include/c++/5/memory:82,
from prog.cpp:1:
/usr/include/c++/5/bits/shared_ptr_base.h:345:11: note: provided for 'template<class _Tp> class std::shared_ptr'
class shared_ptr;
^
prog.cpp:23:53: error: no matching function for call to 'Helper<int>::Wrap(int&)'
auto c3 = Helper<int>::Wrap<WrapperHelper, int>(*c1);
^
prog.cpp:7:29: note: candidate: template<template<class ...> class typedef Wrapper Wrapper, class ... Args> static Wrapper<T, Args ...> Helper<T>::Wrap(const T&) [with Wrapper = Wrapper; Args = {Args ...}; T = int]
static Wrapper<T, Args...> Wrap(T const &t)
^
prog.cpp:7:29: note: template argument deduction/substitution failed: