fork(1) download
  1. #include <memory>
  2.  
  3. template<typename T>
  4. struct Helper
  5. {
  6. template<template<typename...> class Wrapper = std::unique_ptr, typename... Args>
  7. static Wrapper<T, Args...> Wrap(T const &t)
  8. {
  9. return Wrapper<T, Args...>{new T{t}};
  10. }
  11. };
  12.  
  13. template<typename T, template<typename...> typename Wrapper = std::unique_ptr, typename... Args>
  14. struct WrapperHelper final
  15. {
  16. };
  17.  
  18. int main()
  19. {
  20. int x = 0;
  21. auto c1 = Helper<int>::Wrap<>(x);
  22. auto c2 = Helper<int>::Wrap<std::shared_ptr>(x);
  23. auto c3 = Helper<int>::Wrap<WrapperHelper, int>(*c1);
  24. }
  25.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
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:
stdout
Standard output is empty