From dc8ccdc45880f5b1944991c2eff355a034dd2164 Mon Sep 17 00:00:00 2001 From: ToruNiina Date: Sun, 9 Dec 2018 18:00:46 +0900 Subject: [PATCH] construct much more tmp variables std::chrono::seconds -= std::chrono::milliseconds cannot be done bc it represents the duration as integer value and milliseconds are less than seconds. it causes compilation error when we pass a duration to toml::local_time. to avoid this, we need to type-cast the values to smaller duration, like sec -> msec --- toml/datetime.hpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/toml/datetime.hpp b/toml/datetime.hpp index 82d283b..eccd1df 100644 --- a/toml/datetime.hpp +++ b/toml/datetime.hpp @@ -145,21 +145,21 @@ struct local_time {} template - explicit local_time(std::chrono::duration t) + explicit local_time(const std::chrono::duration& t) { const auto h = std::chrono::duration_cast(t); this->hour = h.count(); - t -= h; - const auto m = std::chrono::duration_cast(t); + const auto t2 = t - h; + const auto m = std::chrono::duration_cast(t2); this->minute = m.count(); - t -= m; - const auto s = std::chrono::duration_cast(t); + const auto t3 = t2 - m; + const auto s = std::chrono::duration_cast(t3); this->second = s.count(); - t -= s; - const auto ms = std::chrono::duration_cast(t); + const auto t4 = t3 - s; + const auto ms = std::chrono::duration_cast(t4); this->millisecond = ms.count(); - t -= ms; - const auto us = std::chrono::duration_cast(t); + const auto t5 = t4 - ms; + const auto us = std::chrono::duration_cast(t5); this->microsecond = us.count(); }