Mercurial > hg > vamp-build-and-test
annotate DEPENDENCIES/generic/include/boost/chrono/round.hpp @ 133:4acb5d8d80b6 tip
Don't fail environmental check if README.md exists (but .txt and no-suffix don't)
author | Chris Cannam |
---|---|
date | Tue, 30 Jul 2019 12:25:44 +0100 |
parents | c530137014c0 |
children |
rev | line source |
---|---|
Chris@16 | 1 // boost/chrono/round.hpp ------------------------------------------------------------// |
Chris@16 | 2 |
Chris@16 | 3 // (C) Copyright Howard Hinnant |
Chris@16 | 4 // Copyright 2011 Vicente J. Botet Escriba |
Chris@16 | 5 |
Chris@16 | 6 // Distributed under the Boost Software License, Version 1.0. (See accompanying |
Chris@16 | 7 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
Chris@16 | 8 |
Chris@16 | 9 // See http://www.boost.org/libs/chrono for documentation. |
Chris@16 | 10 |
Chris@16 | 11 #ifndef BOOST_CHRONO_ROUND_HPP |
Chris@16 | 12 #define BOOST_CHRONO_ROUND_HPP |
Chris@16 | 13 |
Chris@16 | 14 #include <boost/chrono/duration.hpp> |
Chris@16 | 15 #include <boost/chrono/duration.hpp> |
Chris@16 | 16 //#include <boost/chrono/typeof/boost/chrono/chrono.hpp> |
Chris@16 | 17 |
Chris@16 | 18 namespace boost |
Chris@16 | 19 { |
Chris@16 | 20 namespace chrono |
Chris@16 | 21 { |
Chris@16 | 22 |
Chris@16 | 23 /** |
Chris@16 | 24 * rounds to nearest, to even on tie |
Chris@16 | 25 */ |
Chris@16 | 26 template <class To, class Rep, class Period> |
Chris@16 | 27 To round(const duration<Rep, Period>& d) |
Chris@16 | 28 { |
Chris@101 | 29 typedef typename common_type<To, duration<Rep, Period> >::type result_type; |
Chris@101 | 30 result_type diff0; |
Chris@101 | 31 result_type diff1; |
Chris@101 | 32 |
Chris@16 | 33 To t0 = duration_cast<To>(d); |
Chris@16 | 34 To t1 = t0; |
Chris@101 | 35 if (t0>d) { |
Chris@101 | 36 --t1; |
Chris@101 | 37 diff0 = t0 - d; |
Chris@101 | 38 diff1 = d - t1; |
Chris@101 | 39 } else { |
Chris@101 | 40 ++t1; |
Chris@101 | 41 diff0 = d - t0; |
Chris@101 | 42 diff1 = t1 - d; |
Chris@101 | 43 } |
Chris@101 | 44 |
Chris@16 | 45 if (diff0 == diff1) |
Chris@16 | 46 { |
Chris@16 | 47 if (t0.count() & 1) |
Chris@16 | 48 return t1; |
Chris@16 | 49 return t0; |
Chris@16 | 50 } |
Chris@16 | 51 else if (diff0 < diff1) |
Chris@16 | 52 return t0; |
Chris@16 | 53 return t1; |
Chris@16 | 54 } |
Chris@16 | 55 |
Chris@16 | 56 } // namespace chrono |
Chris@16 | 57 } // namespace boost |
Chris@16 | 58 |
Chris@16 | 59 #endif |