Guest User

Untitled

a guest
Dec 17th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. void foo( const int i )
  4. {
  5. std::cout << ( i + i ) << std::endl;
  6. }
  7.  
  8. int bar( const double d )
  9. {
  10. const int ret = static_cast< int >( d + 0.7 );
  11. std::cout << ( ret ) << std::endl;
  12. return ret;
  13. }
  14.  
  15. template< class Ret,
  16. class Callable,
  17. class ...Args >
  18. Ret callAnyProducer( Callable callable, Args&&... args )
  19. {
  20. // auto start = current_time_point();
  21. Ret ret = callable( std::forward( args... ) );
  22. // auto duration = start - current_time_point()
  23. return ret;
  24. }
  25.  
  26. int main()
  27. {
  28. //getExecutionTime( foo, 1 );
  29.  
  30. auto a = getExecutionTime( bar, 3.2 );
  31. return 0;
  32. }
  33.  
  34. template< class Callable,
  35. class ...Args >
  36. auto getExecutionTime( Callable callable, Args&&... args )
  37. {
  38. //auto start = current_time_point();
  39. auto ret = callable( std::forward<Args...>( (args,...) ) );
  40. //auto duration = start - current_time_point()
  41. return ret;
  42. }
  43.  
  44. int main()
  45. {
  46. //auto a = getExecutionTime( foo, 1 );
  47.  
  48. auto a = getExecutionTime( bar, 3.2 );
  49. return 0;
  50. }
Add Comment
Please, Sign In to add comment