duration_values_pass.cpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. #include <boost/chrono/duration.hpp>
  14. #include <boost/detail/lightweight_test.hpp>
  15. #include "../rep.h"
  16. #if defined BOOST_NO_CXX11_NUMERIC_LIMITS || defined 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. template <class D>
  23. void check_max()
  24. {
  25. typedef typename D::rep Rep;
  26. Rep max_rep = (boost::chrono::duration_values<Rep>::max)();
  27. BOOST_TEST((D::max)().count() == max_rep);
  28. {
  29. typedef typename D::rep Rep;
  30. BOOST_CHRONO_LIB_CONSTEXPR Rep max_rep = (boost::chrono::duration_values<Rep>::max)();
  31. BOOST_CONSTEXPR_ASSERT((D::max)().count() == max_rep);
  32. }
  33. }
  34. template <class D>
  35. void check_min()
  36. {
  37. typedef typename D::rep Rep;
  38. Rep min_rep = (boost::chrono::duration_values<Rep>::min)();
  39. BOOST_TEST((D::min)().count() == min_rep);
  40. {
  41. typedef typename D::rep Rep;
  42. BOOST_CHRONO_LIB_CONSTEXPR Rep min_rep = (boost::chrono::duration_values<Rep>::min)();
  43. BOOST_CONSTEXPR_ASSERT((D::min)().count() == min_rep);
  44. }
  45. }
  46. template <class D>
  47. void check_zero()
  48. {
  49. typedef typename D::rep Rep;
  50. Rep zero_rep = boost::chrono::duration_values<Rep>::zero();
  51. BOOST_TEST(D::zero().count() == zero_rep);
  52. {
  53. typedef typename D::rep Rep;
  54. BOOST_CONSTEXPR Rep zero_rep = boost::chrono::duration_values<Rep>::zero();
  55. BOOST_CONSTEXPR_ASSERT(D::zero().count() == zero_rep);
  56. }
  57. }
  58. int main()
  59. {
  60. check_max<boost::chrono::duration<int> >();
  61. check_max<boost::chrono::duration<Rep> >();
  62. check_min<boost::chrono::duration<int> >();
  63. check_min<boost::chrono::duration<Rep> >();
  64. check_zero<boost::chrono::duration<int> >();
  65. check_zero<boost::chrono::duration<Rep> >();
  66. return boost::report_errors();
  67. }