Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(448)

Unified Diff: base/time/time.h

Issue 945143002: base::Time multiplicative operator overloading (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | base/time/time_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/time/time.h
diff --git a/base/time/time.h b/base/time/time.h
index 6d618614aef3ed7574f3f279c37805356d935067..b18c0b26d68c1bf8054b059278762fdc3491c62a 100644
--- a/base/time/time.h
+++ b/base/time/time.h
@@ -158,34 +158,30 @@ class BASE_EXPORT TimeDelta {
return TimeDelta(-delta_);
}
- // Computations with ints, note that we only allow multiplicative operations
- // with ints, and additive operations with other deltas.
- TimeDelta operator*(int64 a) const {
+ // Computations with numeric types.
+ template<typename T>
+ TimeDelta operator*(T a) const {
return TimeDelta(delta_ * a);
}
- TimeDelta operator/(int64 a) const {
+ template<typename T>
+ TimeDelta operator/(T a) const {
return TimeDelta(delta_ / a);
}
- TimeDelta& operator*=(int64 a) {
+ template<typename T>
+ TimeDelta& operator*=(T a) {
delta_ *= a;
return *this;
}
- TimeDelta& operator/=(int64 a) {
+ template<typename T>
+ TimeDelta& operator/=(T a) {
delta_ /= a;
return *this;
}
+
int64 operator/(TimeDelta a) const {
return delta_ / a.delta_;
}
- // Multiplicative computations with floats.
- TimeDelta multiply_by(double a) const {
- return TimeDelta(delta_ * a);
- }
- TimeDelta divide_by(double a) const {
- return TimeDelta(delta_ / a);
- }
-
// Defined below because it depends on the definition of the other classes.
Time operator+(Time t) const;
TimeTicks operator+(TimeTicks t) const;
@@ -213,7 +209,6 @@ class BASE_EXPORT TimeDelta {
private:
friend class Time;
friend class TimeTicks;
- friend TimeDelta operator*(int64 a, TimeDelta td);
// Constructs a delta given the duration in microseconds. This is private
// to avoid confusion by callers with an integer constructor. Use
@@ -225,8 +220,9 @@ class BASE_EXPORT TimeDelta {
int64 delta_;
};
-inline TimeDelta operator*(int64 a, TimeDelta td) {
- return TimeDelta(a * td.delta_);
+template<typename T>
+inline TimeDelta operator*(T a, TimeDelta td) {
+ return td * a;
}
// For logging use only.
« no previous file with comments | « no previous file | base/time/time_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698