Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
854258f3
Commit
854258f3
authored
Aug 28, 2014
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Chrono: override operator+ and operator-
Make sure we return the correct type. This obsoletes the cast constructor trick.
parent
26f2d7fb
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
14 deletions
+23
-14
Chrono.hxx
src/Chrono.hxx
+23
-14
No files found.
src/Chrono.hxx
View file @
854258f3
...
...
@@ -21,6 +21,7 @@
#define MPD_CHRONO_HXX
#include <chrono>
#include <utility>
#include <cstdint>
/**
...
...
@@ -37,13 +38,9 @@ public:
template
<
typename
T
>
explicit
constexpr
SongTime
(
T
t
)
:
Base
(
t
)
{}
/**
* This constructor allows implicit conversion from the base
* class to this class. It is necessary because all of
* std::chrono::duration's operators return another
* std::chrono::duration and not an instance of this class.
*/
constexpr
SongTime
(
Base
b
)
:
Base
(
b
)
{}
static
constexpr
SongTime
zero
()
{
return
SongTime
(
Base
::
zero
());
}
static
constexpr
SongTime
FromS
(
unsigned
s
)
{
return
SongTime
(
rep
(
s
)
*
1000
);
...
...
@@ -81,6 +78,14 @@ public:
constexpr
bool
IsPositive
()
const
{
return
count
()
>
0
;
}
constexpr
SongTime
operator
+
(
const
SongTime
&
other
)
const
{
return
SongTime
(
*
(
const
Base
*
)
this
+
(
const
Base
&
)
other
);
}
constexpr
SongTime
operator
-
(
const
SongTime
&
other
)
const
{
return
SongTime
(
*
(
const
Base
*
)
this
-
(
const
Base
&
)
other
);
}
};
/**
...
...
@@ -97,13 +102,9 @@ public:
template
<
typename
T
>
explicit
constexpr
SignedSongTime
(
T
t
)
:
Base
(
t
)
{}
/**
* This constructor allows implicit conversion from the base
* class to this class. It is necessary because all of
* std::chrono::duration's operators return another
* std::chrono::duration and not an instance of this class.
*/
constexpr
SignedSongTime
(
Base
b
)
:
Base
(
b
)
{}
static
constexpr
SignedSongTime
zero
()
{
return
SignedSongTime
(
Base
::
zero
());
}
static
constexpr
SignedSongTime
FromS
(
int
s
)
{
return
SignedSongTime
(
rep
(
s
)
*
1000
);
...
...
@@ -145,6 +146,14 @@ public:
constexpr
bool
IsNegative
()
const
{
return
count
()
<
0
;
}
constexpr
SignedSongTime
operator
+
(
const
SignedSongTime
&
other
)
const
{
return
SignedSongTime
(
*
(
const
Base
*
)
this
+
(
const
Base
&
)
other
);
}
constexpr
SignedSongTime
operator
-
(
const
SignedSongTime
&
other
)
const
{
return
SignedSongTime
(
*
(
const
Base
*
)
this
-
(
const
Base
&
)
other
);
}
};
#endif
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment