diff --git a/lib/utils/mu-utils.hh b/lib/utils/mu-utils.hh index a5e55f0f..63f9f002 100644 --- a/lib/utils/mu-utils.hh +++ b/lib/utils/mu-utils.hh @@ -1,5 +1,5 @@ /* -** Copyright (C) 2017 Dirk-Jan C. Binnema +** Copyright (C) 2020 Dirk-Jan C. Binnema ** ** This library is free software; you can redistribute it and/or ** modify it under the terms of the GNU Lesser General Public License @@ -119,15 +119,18 @@ std::string date_to_time_t_string (const std::string& date, bool first); */ std::string date_to_time_t_string (int64_t t); -using SteadyClock = std::chrono::steady_clock; +using Clock = std::chrono::steady_clock; +using Duration = Clock::duration; -static inline int64_t to_ms (SteadyClock::duration dur) { - return std::chrono::duration_cast(dur).count(); -} -static inline int64_t to_us (SteadyClock::duration dur) { - return std::chrono::duration_cast(dur).count(); +template constexpr int64_t to_unit (Duration d) { + using namespace std::chrono; + return duration_cast(d).count(); } +constexpr int64_t to_s (Duration d) { return to_unit(d); } +constexpr int64_t to_ms (Duration d) { return to_unit(d); } +constexpr int64_t to_us (Duration d) { return to_unit(d); } + /** * Convert a size string to a size in bytes *