Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
F
fmt
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
fmt
Commits
af4734fd
Commit
af4734fd
authored
Jul 12, 2019
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix warnings
parent
a3a74672
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
37 additions
and
17 deletions
+37
-17
ChangeLog.rst
ChangeLog.rst
+3
-0
include/fmt/chrono.h
include/fmt/chrono.h
+4
-1
include/fmt/safe-duration-cast.h
include/fmt/safe-duration-cast.h
+30
-16
No files found.
ChangeLog.rst
View file @
af4734fd
6.0.0 - TBD
-----------
5.3.0 - 2018-12-28
------------------
...
...
include/fmt/chrono.h
View file @
af4734fd
...
...
@@ -477,7 +477,10 @@ template <typename Rep, typename Period,
FMT_ENABLE_IF
(
std
::
is_floating_point
<
Rep
>
::
value
)
>
inline
std
::
chrono
::
duration
<
Rep
,
std
::
milli
>
get_milliseconds
(
std
::
chrono
::
duration
<
Rep
,
Period
>
d
)
{
auto
ms
=
mod
(
d
.
count
()
*
Period
::
num
/
Period
::
den
*
1000
,
1000
);
using
common_type
=
typename
std
::
common_type
<
Rep
,
std
::
intmax_t
>::
type
;
auto
ms
=
mod
(
d
.
count
()
*
static_cast
<
common_type
>
(
Period
::
num
)
/
static_cast
<
common_type
>
(
Period
::
den
)
*
1000
,
1000
);
return
std
::
chrono
::
duration
<
Rep
,
std
::
milli
>
(
static_cast
<
Rep
>
(
ms
));
}
...
...
include/fmt/safe-duration-cast.h
View file @
af4734fd
...
...
@@ -20,12 +20,10 @@ FMT_BEGIN_NAMESPACE
namespace
safe_duration_cast
{
/**
* converts From to To, without loss. If the dynamic value of from
* can't be converted to To without loss, ec is set.
*/
template
<
typename
To
,
typename
From
,
FMT_ENABLE_IF
(
!
std
::
is_same
<
From
,
To
>
::
value
)
>
FMT_ENABLE_IF
(
!
std
::
is_same
<
From
,
To
>
::
value
&&
std
::
numeric_limits
<
From
>::
is_signed
==
std
::
numeric_limits
<
To
>::
is_signed
)
>
FMT_CONSTEXPR
To
lossless_integral_conversion
(
const
From
from
,
int
&
ec
)
{
ec
=
0
;
using
F
=
std
::
numeric_limits
<
From
>
;
...
...
@@ -33,10 +31,9 @@ FMT_CONSTEXPR To lossless_integral_conversion(const From from, int& ec) {
static_assert
(
F
::
is_integer
,
"From must be integral"
);
static_assert
(
T
::
is_integer
,
"To must be integral"
);
if
(
F
::
is_signed
==
T
::
is_signed
)
{
// A and B are both signed, or both unsigned.
if
(
F
::
digits
<=
T
::
digits
)
{
// From fits in To without any problem
// From fits in To without any problem.
}
else
{
// From does not always fit in To, resort to a dynamic check.
if
(
from
<
T
::
min
()
||
from
>
T
::
max
())
{
...
...
@@ -45,7 +42,23 @@ FMT_CONSTEXPR To lossless_integral_conversion(const From from, int& ec) {
return
{};
}
}
}
return
static_cast
<
To
>
(
from
);
}
/**
* converts From to To, without loss. If the dynamic value of from
* can't be converted to To without loss, ec is set.
*/
template
<
typename
To
,
typename
From
,
FMT_ENABLE_IF
(
!
std
::
is_same
<
From
,
To
>
::
value
&&
std
::
numeric_limits
<
From
>::
is_signed
!=
std
::
numeric_limits
<
To
>::
is_signed
)
>
FMT_CONSTEXPR
To
lossless_integral_conversion
(
const
From
from
,
int
&
ec
)
{
ec
=
0
;
using
F
=
std
::
numeric_limits
<
From
>
;
using
T
=
std
::
numeric_limits
<
To
>
;
static_assert
(
F
::
is_integer
,
"From must be integral"
);
static_assert
(
T
::
is_integer
,
"To must be integral"
);
if
(
F
::
is_signed
&&
!
T
::
is_signed
)
{
// From may be negative, not allowed!
...
...
@@ -261,7 +274,8 @@ To safe_duration_cast(std::chrono::duration<FromRep, FromPeriod> from,
// this can't go wrong, right? den>0 is checked earlier.
if
(
Factor
::
den
!=
1
)
{
count
/=
Factor
::
den
;
using
common_t
=
typename
std
::
common_type
<
IntermediateRep
,
intmax_t
>::
type
;
count
/=
static_cast
<
common_t
>
(
Factor
::
den
);
}
// convert to the to type, safely
...
...
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