duration.hpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. //---------------------------------------------------------------------------//
  2. // Copyright (c) 2013-2014 Kyle Lutz <kyle.r.lutz@gmail.com>
  3. //
  4. // Distributed under the Boost Software License, Version 1.0
  5. // See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt
  7. //
  8. // See http://boostorg.github.com/compute for more information.
  9. //---------------------------------------------------------------------------//
  10. #ifndef BOOST_COMPUTE_DETAIL_DURATION_HPP
  11. #define BOOST_COMPUTE_DETAIL_DURATION_HPP
  12. #include <boost/config.hpp>
  13. #ifndef BOOST_COMPUTE_NO_HDR_CHRONO
  14. #include <chrono>
  15. #endif
  16. #ifndef BOOST_COMPUTE_NO_BOOST_CHRONO
  17. #include <boost/chrono/duration.hpp>
  18. #endif
  19. namespace boost {
  20. namespace compute {
  21. namespace detail {
  22. #ifndef BOOST_COMPUTE_NO_HDR_CHRONO
  23. template<class Rep, class Period>
  24. inline std::chrono::duration<Rep, Period>
  25. make_duration_from_nanoseconds(std::chrono::duration<Rep, Period>, size_t nanoseconds)
  26. {
  27. return std::chrono::duration_cast<std::chrono::duration<Rep, Period> >(
  28. std::chrono::nanoseconds(nanoseconds)
  29. );
  30. }
  31. #endif // BOOST_COMPUTE_NO_HDR_CHRONO
  32. #ifndef BOOST_COMPUTE_NO_BOOST_CHRONO
  33. template<class Rep, class Period>
  34. inline boost::chrono::duration<Rep, Period>
  35. make_duration_from_nanoseconds(boost::chrono::duration<Rep, Period>, size_t nanoseconds)
  36. {
  37. return boost::chrono::duration_cast<boost::chrono::duration<Rep, Period> >(
  38. boost::chrono::nanoseconds(nanoseconds)
  39. );
  40. }
  41. #endif // BOOST_COMPUTE_NO_BOOST_CHRONO
  42. } // end detail namespace
  43. } // end compute namespace
  44. } // end boost namespace
  45. #endif // BOOST_COMPUTE_DETAIL_DURATION_HPP