File indexing completed on 2025-01-18 09:29:49
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_CHRONO_ROUND_HPP
0012 #define BOOST_CHRONO_ROUND_HPP
0013
0014 #include <boost/chrono/duration.hpp>
0015 #include <boost/chrono/duration.hpp>
0016
0017
0018 namespace boost
0019 {
0020 namespace chrono
0021 {
0022
0023
0024
0025
0026 template <class To, class Rep, class Period>
0027 To round(const duration<Rep, Period>& d)
0028 {
0029 typedef typename common_type<To, duration<Rep, Period> >::type result_type;
0030 result_type diff0;
0031 result_type diff1;
0032
0033 To t0 = duration_cast<To>(d);
0034 To t1 = t0;
0035 if (t0>d) {
0036 --t1;
0037 diff0 = t0 - d;
0038 diff1 = d - t1;
0039 } else {
0040 ++t1;
0041 diff0 = d - t0;
0042 diff1 = t1 - d;
0043 }
0044
0045 if (diff0 == diff1)
0046 {
0047 if (t0.count() & 1)
0048 return t1;
0049 return t0;
0050 }
0051 else if (diff0 < diff1)
0052 return t0;
0053 return t1;
0054 }
0055
0056 }
0057 }
0058
0059 #endif