Replacing defined time functions with standard because cpp17
Signed-off-by: Milo Lin <100027790@mvla.net>
Change-Id: Ia84519fb0d4ef141654e2f29d59b38ec1e48cfc2
diff --git a/aos/time/time.cc b/aos/time/time.cc
index 0a633ef..882f925 100644
--- a/aos/time/time.cc
+++ b/aos/time/time.cc
@@ -221,7 +221,7 @@
using systick_duration =
std::chrono::duration<uint32_t, std::ratio<1, F_CPU>>;
- return time_point(aos::time::round<std::chrono::nanoseconds>(
+ return time_point(std::chrono::round<std::chrono::nanoseconds>(
std::chrono::milliseconds(ms_count) + systick_duration(counter_up)));
#endif // __linux__
diff --git a/aos/time/time.h b/aos/time/time.h
index 37ff3a8..52d763f 100644
--- a/aos/time/time.h
+++ b/aos/time/time.h
@@ -109,67 +109,6 @@
// Converts a timeval object to a monotonic_clock::time_point.
::aos::monotonic_clock::time_point from_timeval(struct timeval t);
-namespace time_internal {
-
-template <class T>
-struct is_duration : std::false_type {};
-template <class Rep, class Period>
-struct is_duration<std::chrono::duration<Rep, Period>> : std::true_type {};
-
-} // namespace time_internal
-
-// Returns the greatest duration t representable in ToDuration that is less or
-// equal to d.
-// Implementation copied from
-// https://en.cppreference.com/w/cpp/chrono/duration/floor.
-// TODO(Brian): Remove once we have C++17 support.
-template <class To, class Rep, class Period,
- class = std::enable_if_t<time_internal::is_duration<To>{}>>
-constexpr To floor(const std::chrono::duration<Rep, Period> &d) {
- To t = std::chrono::duration_cast<To>(d);
- if (t > d) return t - To{1};
- return t;
-}
-
-// Returns the value t representable in ToDuration that is the closest to d. If
-// there are two such values, returns the even value (that is, the value t such
-// that t % 2 == 0).
-// Implementation copied from
-// https://en.cppreference.com/w/cpp/chrono/duration/round.
-// TODO(Brian): Remove once we have C++17 support.
-template <class To, class Rep, class Period,
- class = std::enable_if_t<
- time_internal::is_duration<To>{} &&
- !std::chrono::treat_as_floating_point<typename To::rep>{}>>
-constexpr To round(const std::chrono::duration<Rep, Period> &d) {
- To t0 = aos::time::floor<To>(d);
- To t1 = t0 + To{1};
- auto diff0 = d - t0;
- auto diff1 = t1 - d;
- if (diff0 == diff1) {
- if (t0.count() & 1) return t1;
- return t0;
- } else if (diff0 < diff1) {
- return t0;
- }
- return t1;
-}
-
-// Returns the nearest time point to tp representable in ToDuration, rounding to
-// even in halfway cases, like std::chrono::round in C++17.
-// Implementation copied from
-// https://en.cppreference.com/w/cpp/chrono/time_point/round.
-// TODO(Brian): Remove once we have C++17 support.
-template <class To, class Clock, class FromDuration,
- class = std::enable_if_t<
- time_internal::is_duration<To>{} &&
- !std::chrono::treat_as_floating_point<typename To::rep>{}>>
-constexpr std::chrono::time_point<Clock, To> round(
- const std::chrono::time_point<Clock, FromDuration> &tp) {
- return std::chrono::time_point<Clock, To>{
- aos::time::round<To>(tp.time_since_epoch())};
-}
-
} // namespace time
} // namespace aos