fork download
  1. #include <iostream>
  2. using namespace std;
  3. template<typename T, typename ...U>
  4. auto time_function_1(T&& func, U&& ...args)
  5. {
  6.  
  7. std::cout<<"timing"<<std::endl;
  8. auto val = std::forward<T>(func)(std::forward<U...>(args...));
  9. std::cout<<"timing over"<<std::endl;
  10. return val;
  11. }
  12.  
  13. template<typename T, typename ...U>
  14. auto time_function_2(T&& func, U&& ...args)
  15. {
  16.  
  17. std::cout<<"timing"<<std::endl;
  18. auto val = std::forward<T>(func)(std::forward<U>(args)...);
  19. std::cout<<"timing over"<<std::endl;
  20. return val;
  21. }
  22.  
  23.  
  24.  
  25. int f (int){return 0;}
  26.  
  27. int y (int,int){return 0;}
  28.  
  29. int main() {
  30. time_function_1(f,1);
  31. time_function_2(f,1);
  32.  
  33. time_function_1(y,1,2);
  34. time_function_2(y,1,2);
  35. return 0;
  36. }
Compilation error #stdin compilation error #stdout 0s 4332KB
stdin
Standard input is empty
compilation info
prog.cpp: In instantiation of ‘auto time_function_1(T&&, U&& ...) [with T = int (&)(int, int); U = {int, int}]’:
prog.cpp:33:23:   required from here
prog.cpp:8:56: error: no matching function for call to ‘forward<int, int>(int&, int&)’
     auto val = std::forward<T>(func)(std::forward<U...>(args...));
                                      ~~~~~~~~~~~~~~~~~~^~~~~~~~~
In file included from /usr/include/c++/8/bits/nested_exception.h:40,
                 from /usr/include/c++/8/exception:144,
                 from /usr/include/c++/8/ios:39,
                 from /usr/include/c++/8/ostream:38,
                 from /usr/include/c++/8/iostream:39,
                 from prog.cpp:1:
/usr/include/c++/8/bits/move.h:74:5: note: candidate: ‘template<class _Tp> constexpr _Tp&& std::forward(typename std::remove_reference<_Tp>::type&)’
     forward(typename std::remove_reference<_Tp>::type& __t) noexcept
     ^~~~~~~
/usr/include/c++/8/bits/move.h:74:5: note:   template argument deduction/substitution failed:
prog.cpp:8:56: error: wrong number of template arguments (2, should be 1)
     auto val = std::forward<T>(func)(std::forward<U...>(args...));
                                      ~~~~~~~~~~~~~~~~~~^~~~~~~~~
In file included from /usr/include/c++/8/bits/nested_exception.h:40,
                 from /usr/include/c++/8/exception:144,
                 from /usr/include/c++/8/ios:39,
                 from /usr/include/c++/8/ostream:38,
                 from /usr/include/c++/8/iostream:39,
                 from prog.cpp:1:
/usr/include/c++/8/bits/move.h:85:5: note: candidate: ‘template<class _Tp> constexpr _Tp&& std::forward(typename std::remove_reference<_Tp>::type&&)’
     forward(typename std::remove_reference<_Tp>::type&& __t) noexcept
     ^~~~~~~
/usr/include/c++/8/bits/move.h:85:5: note:   template argument deduction/substitution failed:
prog.cpp:8:56: error: wrong number of template arguments (2, should be 1)
     auto val = std::forward<T>(func)(std::forward<U...>(args...));
                                      ~~~~~~~~~~~~~~~~~~^~~~~~~~~
prog.cpp:10:12: error: unable to deduce ‘auto’ from ‘val’
     return val;
            ^~~
stdout
Standard output is empty