typedefs_pass.cpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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/type_traits.hpp>
  15. #include <limits>
  16. #if !defined(BOOST_NO_CXX11_STATIC_ASSERT)
  17. #define NOTHING ""
  18. #endif
  19. template <typename D, int ExpectedDigits, typename ExpectedPeriod>
  20. void check_duration()
  21. {
  22. typedef typename D::rep Rep;
  23. typedef typename D::period Period;
  24. BOOST_CHRONO_STATIC_ASSERT(boost::is_signed<Rep>::value, NOTHING, ());
  25. BOOST_CHRONO_STATIC_ASSERT(boost::is_integral<Rep>::value, NOTHING, ());
  26. BOOST_CHRONO_STATIC_ASSERT(std::numeric_limits<Rep>::digits >= ExpectedDigits, NOTHING, ());
  27. BOOST_CHRONO_STATIC_ASSERT((boost::is_same<Period, ExpectedPeriod >::value), NOTHING, ());
  28. }
  29. void test()
  30. {
  31. check_duration<boost::chrono::hours, 22, boost::ratio<3600> >();
  32. check_duration<boost::chrono::minutes, 28, boost::ratio<60> >();
  33. check_duration<boost::chrono::seconds, 34, boost::ratio<1> >();
  34. check_duration<boost::chrono::milliseconds, 44, boost::milli >();
  35. check_duration<boost::chrono::microseconds, 54, boost::micro >();
  36. check_duration<boost::chrono::nanoseconds, 63, boost::nano >();
  37. }