fork download
  1. #include<iostream>
  2. #include<chrono>
  3. #include<thread>
  4. using namespace std;
  5.  
  6. void CheckDuration (std::chrono::duration<int> seconds)
  7. {
  8. auto start = std::chrono::system_clock::now() + seconds;
  9. std::this_thread::sleep_for(std::chrono::seconds(1));
  10. auto stop = std::chrono::system_clock::now();
  11.  
  12. cout << "Difference = " << std::chrono::duration_cast<std::chrono::seconds>(stop-start).count() << endl;
  13. }
  14.  
  15. int main ()
  16. {
  17. CheckDuration(std::chrono::duration<int>(0)); // Difference = 1
  18. CheckDuration(std::chrono::duration<int>(1)); // Difference = 0
  19. CheckDuration(std::chrono::duration<int>(2)); // Difference = 0
  20. CheckDuration(std::chrono::duration<int>(3)); // Difference = -1
  21. }
Success #stdin #stdout 0s 3340KB
stdin
Standard input is empty
stdout
Difference = 1
Difference = 0
Difference = 0
Difference = -1