summaryrefslogtreecommitdiff
path: root/src/Chrono.hxx
diff options
context:
space:
mode:
authorMax Kellermann <max@musicpd.org>2018-09-21 20:18:22 +0200
committerMax Kellermann <max@musicpd.org>2018-09-21 20:41:23 +0200
commit39542de69d8729b5f7c1271a0494f1a221434075 (patch)
treea24f5798b2c1a26f805357c65a2e1f59ad5bedc4 /src/Chrono.hxx
parent1d00d55d53aed450fb5af1da00d81f07afed9f90 (diff)
Chrono: add static method Cast()
Diffstat (limited to 'src/Chrono.hxx')
-rw-r--r--src/Chrono.hxx10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/Chrono.hxx b/src/Chrono.hxx
index 106c10445..b57ff3e62 100644
--- a/src/Chrono.hxx
+++ b/src/Chrono.hxx
@@ -42,6 +42,11 @@ public:
return SongTime(Base::zero());
}
+ template<typename D>
+ static constexpr SongTime Cast(D src) {
+ return SongTime(std::chrono::duration_cast<Base>(src));
+ }
+
static constexpr SongTime FromS(unsigned s) {
return SongTime(rep(s) * 1000);
}
@@ -138,6 +143,11 @@ public:
return SignedSongTime(-1);
}
+ template<typename D>
+ static constexpr SongTime Cast(D src) {
+ return SongTime(std::chrono::duration_cast<Base>(src));
+ }
+
static constexpr SignedSongTime FromS(int s) {
return SignedSongTime(rep(s) * 1000);
}