From 0b51556bd22d9d9c2dc10692fc3c1feb3c6e98b3 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Tue, 3 Jan 2023 16:03:19 +0200 Subject: [PATCH] Make time constants constexpr and move them to the header --- source/time/timedelta.cpp | 9 --------- source/time/timedelta.h | 20 ++++++++++---------- 2 files changed, 10 insertions(+), 19 deletions(-) diff --git a/source/time/timedelta.cpp b/source/time/timedelta.cpp index a56e0fe..5b381da 100644 --- a/source/time/timedelta.cpp +++ b/source/time/timedelta.cpp @@ -75,14 +75,5 @@ void operator<<(LexicalConverter &conv, const TimeDelta &td) conv.result(result); } -const TimeDelta zero(0); -const TimeDelta usec(1); -const TimeDelta msec(1000); -const TimeDelta sec(1000000); -const TimeDelta min(60*1000000); -const TimeDelta hour(3600*1000000LL); -const TimeDelta day(86400*1000000LL); -const TimeDelta week(7*86400*1000000LL); - } // namespace Time } // namespace Msp diff --git a/source/time/timedelta.h b/source/time/timedelta.h index a6c7005..2ff4bdd 100644 --- a/source/time/timedelta.h +++ b/source/time/timedelta.h @@ -20,11 +20,11 @@ private: public: /** Constructs a zero TimeDelta. */ - TimeDelta() = default; + constexpr TimeDelta() = default; /** Constructs a TimeDelta from a plain number. The purpose of this is to allow serialization together with the raw() function. */ - explicit TimeDelta(RawTime u): usec(u) { } + explicit constexpr TimeDelta(RawTime u): usec(u) { } /** Returns the raw number stored inside the TimeDelta. This should only be used for serialization and the result should not be interpreted in any way. */ @@ -65,14 +65,14 @@ MSPCORE_API void operator<<(LexicalConverter &, const TimeDelta &); // Constants to be used in creation of TimeDeltas -MSPCORE_API extern const TimeDelta zero; -MSPCORE_API extern const TimeDelta usec; -MSPCORE_API extern const TimeDelta msec; -MSPCORE_API extern const TimeDelta sec; -MSPCORE_API extern const TimeDelta min; -MSPCORE_API extern const TimeDelta hour; -MSPCORE_API extern const TimeDelta day; -MSPCORE_API extern const TimeDelta week; +constexpr TimeDelta zero(0); +constexpr TimeDelta usec(1); +constexpr TimeDelta msec(1000); +constexpr TimeDelta sec(1000000); +constexpr TimeDelta min(60*1000000); +constexpr TimeDelta hour(3600*1000000LL); +constexpr TimeDelta day(86400*1000000LL); +constexpr TimeDelta week(7*86400*1000000LL); inline TimeDelta abs(const TimeDelta &t) { return t>=zero ? t : -t; } using std::abs; -- 2.45.2