fork(1) download
  1. #include <chrono>
  2. #include <ctime>
  3. #include <cstdint>
  4. struct HighResClock
  5. {
  6. typedef long long rep;
  7. typedef std::nano period;
  8. typedef std::chrono::duration<rep, period> duration;
  9. typedef std::chrono::time_point<HighResClock> time_point;
  10. static const bool is_steady = true;
  11. static time_point now();
  12. };
  13.  
  14. template<class Clock>
  15. class Timer
  16. {
  17. using SysClock = Clock;
  18. using Time = Clock::time_point;
  19. using Duration = Clock::duration;
  20. Time start_;
  21. public:
  22. Timer();
  23. void Restart();
  24.  
  25. Duration TimeElapsed() const;
  26. int64_t TimeElapsed_s() const;
  27. int64_t TimeElapsed_ms() const;
  28. int64_t TimeElapsed_us() const;
  29. int64_t TimeElapsed_ns() const;
  30.  
  31. template<class unit>
  32. int64_t TimeElapsed_T() const
  33. {
  34. return std::chrono::duration_cast<unit>(TimeElapsed()).count();
  35. }
  36. };
  37.  
  38. using NTimer = Timer<std::chrono::sys_clock>;
  39. using HRTimer = Timer<HighResClock>;
  40.  
  41.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:18:26: error: expected type-specifier
         using Time     = Clock::time_point;
                          ^
prog.cpp:19:26: error: expected type-specifier
         using Duration = Clock::duration;
                          ^
prog.cpp:20:9: error: ‘Time’ does not name a type
         Time start_;
         ^
prog.cpp:25:9: error: ‘Duration’ does not name a type
         Duration TimeElapsed() const;
         ^
prog.cpp: In member function ‘int64_t Timer<Clock>::TimeElapsed_T() const’:
prog.cpp:34:65: error: there are no arguments to ‘TimeElapsed’ that depend on a template parameter, so a declaration of ‘TimeElapsed’ must be available [-fpermissive]
             return std::chrono::duration_cast<unit>(TimeElapsed()).count();
                                                                 ^
prog.cpp:34:65: note: (if you use ‘-fpermissive’, G++ will accept your code, but allowing the use of an undeclared name is deprecated)
prog.cpp: At global scope:
prog.cpp:38:26: error: ‘sys_clock’ is not a member of ‘std::chrono’
     using NTimer = Timer<std::chrono::sys_clock>;
                          ^
prog.cpp:38:26: error: ‘sys_clock’ is not a member of ‘std::chrono’
prog.cpp:38:48: error: template argument 1 is invalid
     using NTimer = Timer<std::chrono::sys_clock>;
                                                ^
stdout
Standard output is empty