fork download
  1. template<class ret, class ...param_types)
  2. class function_interface {
  3. public:
  4. virtual ret operator()(param_types... ps)=0;
  5. virtual ~function_interface ()=0;
  6. };
  7.  
  8. template<class functor, class ret, class ...param_types>
  9. class function_impl : function_interface<ret, param_types...> {
  10. functor data;
  11. public:
  12. function_impl(functor d) :data(std::move(d)) {}
  13. virtual ret operator()(param_types... ps) {return data();}
  14. };
  15.  
  16. template<class ret, class ...param_types>
  17. class function {
  18. std::unique_ptr<function_interface<ret, param_types...>> ptr;
  19. public:
  20. template<class functor>
  21. function(functor d) :ptr(new function_impl<functor, ret, param_types...>(std::move(d)) {}
  22. ret operator()(param_types... ps) {return (*ptr)();}
  23. };
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:1: error: ISO C++ does not include variadic templates
prog.cpp:1: error: expected ‘>’ before ‘)’ token
prog.cpp:1: error: expected unqualified-id before ‘)’ token
prog.cpp:8: error: ISO C++ does not include variadic templates
prog.cpp:9: error: expected template-name before ‘<’ token
prog.cpp:9: error: expected `{' before ‘<’ token
prog.cpp:9: error: expected unqualified-id before ‘<’ token
prog.cpp:16: error: ISO C++ does not include variadic templates
prog.cpp:18: error: ISO C++ forbids declaration of ‘unique_ptr’ with no type
prog.cpp:18: error: invalid use of ‘::’
prog.cpp:18: error: expected ‘;’ before ‘<’ token
prog.cpp:23: error: expected `}' at end of input
prog.cpp: In constructor ‘function<ret, param_types>::function(functor)’:
prog.cpp:21: error: class ‘function<ret, param_types>’ does not have any field named ‘ptr’
prog.cpp:21: error: ‘move’ is not a member of ‘std’
prog.cpp:21: error: expected `)' before ‘{’ token
prog.cpp:23: error: expected `{' before ‘}’ token
prog.cpp: At global scope:
prog.cpp:23: error: expected unqualified-id at end of input
stdout
Standard output is empty