arithmetic_ext_pass.cpp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. //===----------------------------------------------------------------------===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is dual licensed under the MIT and the University of Illinois Open
  6. // Source Licenses. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. // Adaptation to Boost of the libcxx
  10. // Copyright 2010 Vicente J. Botet Escriba
  11. // Distributed under the Boost Software License, Version 1.0.
  12. // See http://www.boost.org/LICENSE_1_0.txt
  13. #define BOOST_CHRONO_EXTENSIONS
  14. #include <boost/chrono/chrono.hpp>
  15. #include <boost/detail/lightweight_test.hpp>
  16. #ifdef BOOST_NO_CXX11_CONSTEXPR
  17. #define BOOST_CONSTEXPR_ASSERT(C) BOOST_TEST(C)
  18. #else
  19. #include <boost/static_assert.hpp>
  20. #define BOOST_CONSTEXPR_ASSERT(C) BOOST_STATIC_ASSERT(C)
  21. #endif
  22. int main()
  23. {
  24. {
  25. typedef boost::chrono::system_clock Clock;
  26. typedef boost::chrono::milliseconds Duration;
  27. boost::chrono::time_point<Clock, Duration> t(Duration(3));
  28. t += 2;
  29. BOOST_TEST(t.time_since_epoch() == Duration(5));
  30. }
  31. {
  32. typedef boost::chrono::system_clock Clock;
  33. typedef boost::chrono::milliseconds Duration;
  34. boost::chrono::time_point<Clock, Duration> t(Duration(3));
  35. t++;
  36. BOOST_TEST(t.time_since_epoch() == Duration(4));
  37. }
  38. {
  39. typedef boost::chrono::system_clock Clock;
  40. typedef boost::chrono::milliseconds Duration;
  41. boost::chrono::time_point<Clock, Duration> t(Duration(3));
  42. ++t;
  43. BOOST_TEST(t.time_since_epoch() == Duration(4));
  44. }
  45. {
  46. typedef boost::chrono::system_clock Clock;
  47. typedef boost::chrono::milliseconds Duration;
  48. boost::chrono::time_point<Clock, Duration> t(Duration(3));
  49. t -= 2;
  50. BOOST_TEST(t.time_since_epoch() == Duration(1));
  51. }
  52. {
  53. typedef boost::chrono::system_clock Clock;
  54. typedef boost::chrono::milliseconds Duration;
  55. boost::chrono::time_point<Clock, Duration> t(Duration(3));
  56. t--;
  57. BOOST_TEST(t.time_since_epoch() == Duration(2));
  58. }
  59. {
  60. typedef boost::chrono::system_clock Clock;
  61. typedef boost::chrono::milliseconds Duration;
  62. boost::chrono::time_point<Clock, Duration> t(Duration(3));
  63. --t;
  64. BOOST_TEST(t.time_since_epoch() == Duration(2));
  65. }
  66. return boost::report_errors();
  67. }