fork download
  1. #include <iostream>
  2. #include <functional>
  3.  
  4. template <template <typename R,
  5. typename A> R func(A)>
  6. struct S : std::unary_function<R, A>
  7. {
  8. R operator()(A arg) const
  9. {
  10. return func(arg);
  11. }
  12. };
  13.  
  14. int foo(int x)
  15. {
  16. return x;
  17. }
  18.  
  19. int main()
  20. {
  21. S<foo> s;
  22.  
  23. std::cout << s(42) << std::endl;
  24. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:5: error: expected `class' before ‘R’
prog.cpp:5: error: expected ‘>’ before ‘func’
prog.cpp:6: error: ‘A’ was not declared in this scope
prog.cpp:6: error: type/value mismatch at argument 1 in template parameter list for ‘template<class _Arg, class _Result> struct std::unary_function’
prog.cpp:6: error:   expected a type, got ‘R’
prog.cpp:6: error: template argument 2 is invalid
prog.cpp:8: error: ISO C++ forbids declaration of ‘R’ with no type
prog.cpp:8: error: expected ‘;’ before ‘operator’
prog.cpp:12: error: expected `;' before ‘}’ token
prog.cpp: In function ‘int main()’:
prog.cpp:21: error: type/value mismatch at argument 1 in template parameter list for ‘template<template<class R, class A> class R> struct S’
prog.cpp:21: error:   expected a class template, got ‘foo’
prog.cpp:21: error: invalid type in declaration before ‘;’ token
prog.cpp:23: error: ‘s’ cannot be used as a function
stdout
Standard output is empty