From: Mikko Rasa Date: Sun, 26 Jul 2015 16:57:58 +0000 (+0300) Subject: Add negation operator and abs function for TimeDelta X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=ab9e61f0bc6ed09dae52f538dc6927c54b9216df;p=libs%2Fcore.git Add negation operator and abs function for TimeDelta --- 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