floor.hpp 797 B

123456789101112131415161718192021222324252627282930313233343536
  1. // boost/chrono/round.hpp ------------------------------------------------------------//
  2. // (C) Copyright Howard Hinnant
  3. // Copyright 2011 Vicente J. Botet Escriba
  4. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. // See http://www.boost.org/libs/chrono for documentation.
  7. #ifndef BOOST_CHRONO_FLOOR_HPP
  8. #define BOOST_CHRONO_FLOOR_HPP
  9. #include <boost/chrono/duration.hpp>
  10. namespace boost
  11. {
  12. namespace chrono
  13. {
  14. /**
  15. * rounds down
  16. */
  17. template <class To, class Rep, class Period>
  18. To floor(const duration<Rep, Period>& d)
  19. {
  20. To t = duration_cast<To>(d);
  21. if (t>d) --t;
  22. return t;
  23. }
  24. } // namespace chrono
  25. } // namespace boost
  26. #endif