From ab9e61f0bc6ed09dae52f538dc6927c54b9216df Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sun, 26 Jul 2015 19:57:58 +0300 Subject: [PATCH] Add negation operator and abs function for TimeDelta --- source/time/timedelta.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/source/time/timedelta.h b/source/time/timedelta.h index c73529b..2ce6eeb 100644 --- a/source/time/timedelta.h +++ b/source/time/timedelta.h @@ -1,6 +1,7 @@ #ifndef MSP_TIME_TIMEDELTA_H_ #define MSP_TIME_TIMEDELTA_H_ +#include #include #include #include "rawtime.h" @@ -32,6 +33,7 @@ public: TimeDelta &operator+=(const TimeDelta &t) { usec += t.usec; return *this; } TimeDelta operator-(const TimeDelta &t) const { return TimeDelta(usec-t.usec); } TimeDelta &operator-=(const TimeDelta &t) { usec -= t.usec; return *this; } + TimeDelta operator-() const { return TimeDelta(-usec); } template TimeDelta operator*(T a) const { return TimeDelta(RawTime(usec*a)); } @@ -71,6 +73,9 @@ extern const TimeDelta hour; extern const TimeDelta day; extern const TimeDelta week; +inline TimeDelta abs(const TimeDelta &t) { return t>=zero ? t : -t; } +using std::abs; + } // namespace Time } // namespace Msp -- 2.45.2