literals2.pass.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. //===----------------------------------------------------------------------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. // UNSUPPORTED: c++98, c++03, c++11
  9. // <chrono>
  10. #include <chrono>
  11. #include <type_traits>
  12. #include <cassert>
  13. #include "test_macros.h"
  14. int main(int, char**)
  15. {
  16. using namespace std::literals;
  17. std::chrono::hours h = 4h;
  18. assert ( h == std::chrono::hours(4));
  19. auto h2 = 4.0h;
  20. assert ( h == h2 );
  21. std::chrono::minutes min = 36min;
  22. assert ( min == std::chrono::minutes(36));
  23. auto min2 = 36.0min;
  24. assert ( min == min2 );
  25. std::chrono::seconds s = 24s;
  26. assert ( s == std::chrono::seconds(24));
  27. auto s2 = 24.0s;
  28. assert ( s == s2 );
  29. std::chrono::milliseconds ms = 247ms;
  30. assert ( ms == std::chrono::milliseconds(247));
  31. auto ms2 = 247.0ms;
  32. assert ( ms == ms2 );
  33. std::chrono::microseconds us = 867us;
  34. assert ( us == std::chrono::microseconds(867));
  35. auto us2 = 867.0us;
  36. assert ( us == us2 );
  37. std::chrono::nanoseconds ns = 645ns;
  38. assert ( ns == std::chrono::nanoseconds(645));
  39. auto ns2 = 645.ns;
  40. assert ( ns == ns2 );
  41. return 0;
  42. }