Refine decision to use the std::chrono rounding modes

This commit is contained in:
Howard Hinnant 2016-09-10 11:57:52 -04:00
parent 6cb8d59886
commit 845ce25bb7
2 changed files with 16 additions and 5 deletions

View File

@ -1,6 +1,6 @@
[![Join the chat at https://gitter.im/HowardHinnant/date](https://badges.gitter.im/HowardHinnant/date.svg)](https://gitter.im/HowardHinnant/date?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
_**[Try it out on wandbox!](http://melpon.org/wandbox/permlink/zKiDqIUK0XwePf7Y)**_
_**[Try it out on wandbox!](http://melpon.org/wandbox/permlink/lb6FHxHyQ1V9eCLm)**_
This is actually several separate C++11/C++14 libraries:

19
date.h
View File

@ -963,8 +963,19 @@ trunc(const std::chrono::duration<Rep, Period>& d)
return To{detail::trunc(std::chrono::duration_cast<To>(d).count())};
}
// VS Update 2 provides floor, ceil, round, abs in chrono.
#if (defined(_MSC_FULL_VER) && _MSC_FULL_VER < 190023918) || __cplusplus <= 201402
#ifndef HAS_CHRONO_ROUNDING
# if defined(_MSC_FULL_VER) && _MSC_FULL_VER >= 190023918
# define HAS_CHRONO_ROUNDING 1
# elif defined(__cpp_lib_chrono) && __cplusplus > 201402 && __cpp_lib_chrono >= 201510
# define HAS_CHRONO_ROUNDING 1
# elif defined(_LIBCPP_VERSION) && __cplusplus > 201402 && _LIBCPP_VERSION >= 3800
# define HAS_CHRONO_ROUNDING 1
# else
# define HAS_CHRONO_ROUNDING 0
# endif
#endif // HAS_CHRONO_ROUNDING
#if HAS_CHRONO_ROUNDING == 0
// round down
template <class To, class Rep, class Period>
@ -1061,14 +1072,14 @@ ceil(const std::chrono::time_point<Clock, FromDuration>& tp)
return time_point<Clock, To>{ceil<To>(tp.time_since_epoch())};
}
#else // (defined(_MSC_FULL_VER) && _MSC_FULL_VER < 190023918) || __cplusplus <= 201402
#else // HAS_CHRONO_ROUNDING == 1
using std::chrono::floor;
using std::chrono::ceil;
using std::chrono::round;
using std::chrono::abs;
#endif // (defined(_MSC_FULL_VER) && _MSC_FULL_VER < 190023918) || __cplusplus <= 201402
#endif // HAS_CHRONO_ROUNDING
// trunc towards zero
template <class To, class Clock, class FromDuration>