fork(1) download
  1. #include <iostream>
  2. #include <functional>
  3. using namespace std;
  4.  
  5. template <typename F, typename S>
  6. void doSome(F &func){
  7. S a;
  8. auto res = func(a);
  9. cout << res << "\n";
  10. }
  11.  
  12. template<>
  13. void doSome<typename F, int> (F &func){
  14. int a;
  15. a = 5;
  16. auto res = func(a);
  17. cout << res << "\n";
  18. }
  19.  
  20. template<>
  21. void dpSome<typename F, double> (F &func){
  22. double a;
  23. a = 5.5
  24. auto res = func(a);
  25. cout << res << "\n";
  26. }
  27.  
  28.  
  29. int main() {
  30. doSome([](int &a){
  31. a += 2;
  32. });
  33.  
  34. doSome([](double &a){
  35. a += 2.5;
  36. });
  37. return 0;
  38. }
Compilation error #stdin compilation error #stdout 0s 15240KB
stdin
Standard input is empty
compilation info
prog.cpp:13:6: error: parse error in template argument list
 void doSome<typename F, int> (F &func){
      ^~~~~~~~~~~~~~~~~~~~~~~
prog.cpp:13:31: error: template-id ‘doSome<<expression error> >’ used as a declarator
 void doSome<typename F, int> (F &func){
                               ^
prog.cpp:13:31: error: variable or field ‘doSome’ declared void
prog.cpp:13:31: error: ‘F’ was not declared in this scope
prog.cpp:13:34: error: ‘func’ was not declared in this scope
 void doSome<typename F, int> (F &func){
                                  ^~~~
prog.cpp:21:12: error: expected initializer before ‘<’ token
 void dpSome<typename F, double> (F &func){
            ^
prog.cpp: In function ‘int main()’:
prog.cpp:32:3: error: no matching function for call to ‘doSome(main()::<lambda(int&)>)’
  });
   ^
prog.cpp:6:6: note: candidate: template<class F, class S> void doSome(F&)
 void doSome(F &func){
      ^~~~~~
prog.cpp:6:6: note:   template argument deduction/substitution failed:
prog.cpp:32:3: note:   couldn't deduce template parameter ‘S’
  });
   ^
prog.cpp:36:3: error: no matching function for call to ‘doSome(main()::<lambda(double&)>)’
  });
   ^
prog.cpp:6:6: note: candidate: template<class F, class S> void doSome(F&)
 void doSome(F &func){
      ^~~~~~
prog.cpp:6:6: note:   template argument deduction/substitution failed:
prog.cpp:36:3: note:   couldn't deduce template parameter ‘S’
  });
   ^
stdout
Standard output is empty