Topic: std::chrono additions
Author: Richard Thorell <richard.thorell@king.com>
Date: Fri, 5 Aug 2016 06:24:44 -0700 (PDT)
Raw View
------=_Part_1976_273561257.1470403484369
Content-Type: multipart/alternative;
boundary="----=_Part_1977_1746607561.1470403484370"
------=_Part_1977_1746607561.1470403484370
Content-Type: text/plain; charset=UTF-8
Hey,
I have some additions to the std::chrono library that might be useful for
other. Thought I might share it here and see if there's any interest in it.
Basically what it's all about is to be able to extract the number of
seconds/minutes/hours etc. from a time_point or duration type without
converting it to a time_t object.
Here's a reference implementation:
//
// time_traits
//
template <std::intmax_t Num, std::intmax_t Denom>
struct time_traits_base;
// Seconds
template <>
struct time_traits_base<1, 1>
{
static constexpr std::intmax_t num = 1;
static constexpr std::intmax_t mod = 1;
};
// Minutes
template <>
struct time_traits_base<60, 1>
{
static constexpr std::intmax_t num = 60;
static constexpr std::intmax_t mod = 60;
};
// Hours
template <>
struct time_traits_base<3600, 1>
{
static constexpr std::intmax_t num = 3600;
static constexpr std::intmax_t mod = 24;
};
template <class T>
struct time_traits;
template <class Rep, std::intmax_t Num, std::intmax_t Denom>
struct time_traits<std::chrono::duration<Rep, std::ratio<Num, Denom>>> :
public time_traits_base<Num, Denom>
{};
//
// extract
//
template <class ToDuration, class Rep, class Period>
constexpr ToDuration extract(const std::chrono::duration<Rep, Period>& d)
{
return ToDuration((std::chrono::duration_cast<std::chrono::seconds>(d).
count() / time_traits<ToDuration>::num) % time_traits<ToDuration>::mod);
}
template <class ToDuration,class Clock, class Duration>
constexpr ToDuration extract(const std::chrono::time_point<Clock,Duration>&
t)
{
return extract<ToDuration>(t.time_since_epoch());
}
And a sample usage:
template <class Rep, class Period>
inline std::ostream& operator<<(std::ostream& os, const std::chrono::
duration<Rep, Period>& d)
{
return os << d.count();
}
int main(int argc, char** argv)
{
constexpr auto a = std::chrono::minutes(123);
constexpr auto b = std::chrono::seconds(456);
constexpr auto c = a + b;
constexpr auto h = extract<std::chrono::hours>(c);
constexpr auto m = extract<std::chrono::minutes>(c);
constexpr auto s = extract<std::chrono::seconds>(c);
std::cout << h << " hours, " << m << " minutes, " << s << " seconds." <<
std::endl;
return 0;
}
Would print:
2 hours, 10 minutes, 0 seconds.
Cheers,
ricky
--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/9b000907-f267-48b3-88b7-e230af875a51%40isocpp.org.
------=_Part_1977_1746607561.1470403484370
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">Hey,<div><br></div><div>I have some additions to the std::=
chrono library that might be useful for other. Thought I might share it her=
e and see if there's any interest in it.</div><div>Basically what it=
9;s all about is to be able to extract the number of seconds/minutes/hours =
etc. from a time_point or duration type without converting it to a time_t o=
bject.</div><div><br></div><div>Here's a reference implementation:</div=
><div><br></div><div><div class=3D"prettyprint" style=3D"border: 1px solid =
rgb(187, 187, 187); word-wrap: break-word; background-color: rgb(250, 250, =
250);"><code class=3D"prettyprint"><div class=3D"subprettyprint"><span styl=
e=3D"color: #800;" class=3D"styled-by-prettify">//</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #8=
00;" class=3D"styled-by-prettify">// time_traits</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #800=
;" class=3D"styled-by-prettify">//</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"><br></span><span style=3D"color: #008;" class=3D"st=
yled-by-prettify">template</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify"><</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
>std</span><span style=3D"color: #660;" class=3D"styled-by-prettify">::</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify">intmax_t </spa=
n><span style=3D"color: #606;" class=3D"styled-by-prettify">Num</span><span=
style=3D"color: #660;" class=3D"styled-by-prettify">,</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify"> std</span><span style=3D"color=
: #660;" class=3D"styled-by-prettify">::</span><span style=3D"color: #000;"=
class=3D"styled-by-prettify">intmax_t </span><span style=3D"color: #606;" =
class=3D"styled-by-prettify">Denom</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">></span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"><br></span><span style=3D"color: #008;" class=3D"styled-b=
y-prettify">struct</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"> time_traits_base</span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">;</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"><br><br></span><span style=3D"color: #800;" class=3D"styled-by-pretti=
fy">// Seconds</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"><br></span><span style=3D"color: #008;" class=3D"styled-by-prettify">te=
mplate</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify"><></spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><spa=
n style=3D"color: #008;" class=3D"styled-by-prettify">struct</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"> time_traits_base</span><=
span style=3D"color: #660;" class=3D"styled-by-prettify"><</span><span s=
tyle=3D"color: #066;" class=3D"styled-by-prettify">1</span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">,</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"> </span><span style=3D"color: #066;" class=
=3D"styled-by-prettify">1</span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">></span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"><br></span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">{</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=
=C2=A0 =C2=A0 </span><span style=3D"color: #008;" class=3D"styled-by-pretti=
fy">static</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
</span><span style=3D"color: #008;" class=3D"styled-by-prettify">constexpr=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> std</span=
><span style=3D"color: #660;" class=3D"styled-by-prettify">::</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify">intmax_t num </span><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color=
: #066;" class=3D"styled-by-prettify">1</span><span style=3D"color: #660;" =
class=3D"styled-by-prettify">;</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"><br>=C2=A0 =C2=A0 </span><span style=3D"color: #008;" c=
lass=3D"styled-by-prettify">static</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"style=
d-by-prettify">constexpr</span><span style=3D"color: #000;" class=3D"styled=
-by-prettify"> std</span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">::</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
intmax_t mod </span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">=3D</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </s=
pan><span style=3D"color: #066;" class=3D"styled-by-prettify">1</span><span=
style=3D"color: #660;" class=3D"styled-by-prettify">;</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"color=
: #660;" class=3D"styled-by-prettify">};</span><span style=3D"color: #000;"=
class=3D"styled-by-prettify"><br><br></span><span style=3D"color: #800;" c=
lass=3D"styled-by-prettify">// Minutes</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify"><br></span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">template</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"style=
d-by-prettify"><></span><span style=3D"color: #000;" class=3D"styled-=
by-prettify"><br></span><span style=3D"color: #008;" class=3D"styled-by-pre=
ttify">struct</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"> time_traits_base</span><span style=3D"color: #660;" class=3D"styled-by-=
prettify"><</span><span style=3D"color: #066;" class=3D"styled-by-pretti=
fy">60</span><span style=3D"color: #660;" class=3D"styled-by-prettify">,</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span=
style=3D"color: #066;" class=3D"styled-by-prettify">1</span><span style=3D=
"color: #660;" class=3D"styled-by-prettify">></span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #660=
;" class=3D"styled-by-prettify">{</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 </span><span style=3D"color: #008=
;" class=3D"styled-by-prettify">static</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"s=
tyled-by-prettify">constexpr</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"> std</span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">::</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy">intmax_t num </span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">=3D</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
</span><span style=3D"color: #066;" class=3D"styled-by-prettify">60</span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">;</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 </span><=
span style=3D"color: #008;" class=3D"styled-by-prettify">static</span><span=
style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D=
"color: #008;" class=3D"styled-by-prettify">constexpr</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"> std</span><span style=3D"color:=
#660;" class=3D"styled-by-prettify">::</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify">intmax_t mod </span><span style=3D"color: #660=
;" class=3D"styled-by-prettify">=3D</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"> </span><span style=3D"color: #066;" class=3D"styl=
ed-by-prettify">60</span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><=
br></span><span style=3D"color: #660;" class=3D"styled-by-prettify">};</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"><br><br></span>=
<span style=3D"color: #800;" class=3D"styled-by-prettify">// Hours</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span st=
yle=3D"color: #008;" class=3D"styled-by-prettify">template</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify"><></span><span style=3D"color:=
#000;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #008;=
" class=3D"styled-by-prettify">struct</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"> time_traits_base</span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify"><</span><span style=3D"color: #066;" c=
lass=3D"styled-by-prettify">3600</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">,</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"> </span><span style=3D"color: #066;" class=3D"styled-by-pret=
tify">1</span><span style=3D"color: #660;" class=3D"styled-by-prettify">>=
;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">{</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 </span=
><span style=3D"color: #008;" class=3D"styled-by-prettify">static</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #008;" class=3D"styled-by-prettify">constexpr</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> std</span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">::</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify">intmax_t num </span><span style=3D"color: =
#660;" class=3D"styled-by-prettify">=3D</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify"> </span><span style=3D"color: #066;" class=3D"=
styled-by-prettify">3600</span><span style=3D"color: #660;" class=3D"styled=
-by-prettify">;</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify"><br>=C2=A0 =C2=A0 </span><span style=3D"color: #008;" class=3D"styled-=
by-prettify">static</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"> </span><span style=3D"color: #008;" class=3D"styled-by-prettify">=
constexpr</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> =
std</span><span style=3D"color: #660;" class=3D"styled-by-prettify">::</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify">intmax_t mod </=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #066;" class=3D"styled-by-prettify">24</span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">;</span><span style=3D"color: #000;"=
class=3D"styled-by-prettify"><br></span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">};</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify"><br><br></span><span style=3D"color: #008;" class=3D"styled=
-by-prettify">template</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y"><</span><span style=3D"color: #008;" class=3D"styled-by-prettify">cla=
ss</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> T</span=
><span style=3D"color: #660;" class=3D"styled-by-prettify">></span><span=
style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span style=
=3D"color: #008;" class=3D"styled-by-prettify">struct</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"> time_traits</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">;</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"><br><br></span><span style=3D"color: =
#008;" class=3D"styled-by-prettify">template</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify"><</span><span style=3D"color: #008;" class=3D"s=
tyled-by-prettify">class</span><span style=3D"color: #000;" class=3D"styled=
-by-prettify"> </span><span style=3D"color: #606;" class=3D"styled-by-prett=
ify">Rep</span><span style=3D"color: #660;" class=3D"styled-by-prettify">,<=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify"> std</span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">::</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify">intmax_t </span><span sty=
le=3D"color: #606;" class=3D"styled-by-prettify">Num</span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">,</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"> std</span><span style=3D"color: #660;" cl=
ass=3D"styled-by-prettify">::</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify">intmax_t </span><span style=3D"color: #606;" class=3D"st=
yled-by-prettify">Denom</span><span style=3D"color: #660;" class=3D"styled-=
by-prettify">></span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"><br></span><span style=3D"color: #008;" class=3D"styled-by-prettify"=
>struct</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> ti=
me_traits</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&=
lt;</span><span style=3D"color: #000;" class=3D"styled-by-prettify">std</sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">::</span><span=
style=3D"color: #000;" class=3D"styled-by-prettify">chrono</span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify">::</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify">duration</span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify"><</span><span style=3D"color: #60=
6;" class=3D"styled-by-prettify">Rep</span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">,</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"> std</span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">::</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y">ratio</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&l=
t;</span><span style=3D"color: #606;" class=3D"styled-by-prettify">Num</spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">,</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"c=
olor: #606;" class=3D"styled-by-prettify">Denom</span><span style=3D"color:=
#660;" class=3D"styled-by-prettify">>>></span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;"=
class=3D"styled-by-prettify">:</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"styled-b=
y-prettify">public</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"> time_traits_base</span><span style=3D"color: #660;" class=3D"style=
d-by-prettify"><</span><span style=3D"color: #606;" class=3D"styled-by-p=
rettify">Num</span><span style=3D"color: #660;" class=3D"styled-by-prettify=
">,</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span=
><span style=3D"color: #606;" class=3D"styled-by-prettify">Denom</span><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify">></span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">{};</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"><br><br></span><span style=3D"color: #80=
0;" class=3D"styled-by-prettify">//</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"><br></span><span style=3D"color: #800;" class=3D"s=
tyled-by-prettify">// extract</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"><br></span><span style=3D"color: #800;" class=3D"styled-=
by-prettify">//</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify"><br></span><span style=3D"color: #008;" class=3D"styled-by-prettify">t=
emplate</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </=
span><span style=3D"color: #660;" class=3D"styled-by-prettify"><</span><=
span style=3D"color: #008;" class=3D"styled-by-prettify">class</span><span =
style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"=
color: #606;" class=3D"styled-by-prettify">ToDuration</span><span style=3D"=
color: #660;" class=3D"styled-by-prettify">,</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" clas=
s=3D"styled-by-prettify">class</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"> </span><span style=3D"color: #606;" class=3D"styled-by=
-prettify">Rep</span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">,</span><font color=3D"#000088"><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by-=
prettify">class</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify"> </span><span style=3D"color: #606;" class=3D"styled-by-prettify">Peri=
od</span><span style=3D"color: #660;" class=3D"styled-by-prettify">></sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><sp=
an style=3D"color: #008;" class=3D"styled-by-prettify">constexpr</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #606;" class=3D"styled-by-prettify">ToDuration</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> extract</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=3D"color=
: #008;" class=3D"styled-by-prettify">const</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"> std</span><span style=3D"color: #660;" cl=
ass=3D"styled-by-prettify">::</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify">chrono</span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">::</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify">duration</span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify"><</span><span style=3D"color: #606;" class=3D"styled-by-prettify">R=
ep</span><span style=3D"color: #660;" class=3D"styled-by-prettify">,</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span sty=
le=3D"color: #606;" class=3D"styled-by-prettify">Period</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">>&</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> d</span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">)</span><span style=3D"color: #000;"=
class=3D"styled-by-prettify"><br></span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">{</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"><br>=C2=A0 =C2=A0 </span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">return</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"> </span><span style=3D"color: #606;" class=3D"styled-by=
-prettify">ToDuration</span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">((</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y">std</span><span style=3D"color: #660;" class=3D"styled-by-prettify">::</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify">chrono</span=
><span style=3D"color: #660;" class=3D"styled-by-prettify">::</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify">duration_cast</span><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify"><</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify">std</span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">::</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify">chrono</span><span style=3D"color: #660;" =
class=3D"styled-by-prettify">::</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify">seconds</span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">>(</span><span style=3D"color: #000;" class=3D"styled-=
by-prettify">d</span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">).</span><span style=3D"color: #000;" class=3D"styled-by-prettify">coun=
t</span><span style=3D"color: #660;" class=3D"styled-by-prettify">()</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify">/</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"> time_traits</span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify"><</span><span style=3D"color: =
#606;" class=3D"styled-by-prettify">ToDuration</span><span style=3D"color: =
#660;" class=3D"styled-by-prettify">>::</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify">num</span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">)</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">%</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> t=
ime_traits</span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
<</span><span style=3D"color: #606;" class=3D"styled-by-prettify">ToDura=
tion</span><span style=3D"color: #660;" class=3D"styled-by-prettify">>::=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify">mod</span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">);</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span style=3D=
"color: #660;" class=3D"styled-by-prettify">}</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"><br><br></span><span style=3D"color: #00=
8;" class=3D"styled-by-prettify">template</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=
=3D"styled-by-prettify"><</span><span style=3D"color: #008;" class=3D"st=
yled-by-prettify">class</span><span style=3D"color: #000;" class=3D"styled-=
by-prettify"> </span><span style=3D"color: #606;" class=3D"styled-by-pretti=
fy">ToDuration</span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">,</span><span style=3D"color: #008;" class=3D"styled-by-prettify">class=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><s=
pan style=3D"color: #606;" class=3D"styled-by-prettify">Clock</span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">,</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #00=
8;" class=3D"styled-by-prettify">class</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify"> </span><span style=3D"color: #606;" class=3D"s=
tyled-by-prettify">Duration</span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">></span><span style=3D"color: #000;" class=3D"styled-by=
-prettify"><br></span><span style=3D"color: #008;" class=3D"styled-by-prett=
ify">constexpr</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"> </span><span style=3D"color: #606;" class=3D"styled-by-prettify">ToDur=
ation</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> extr=
act</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span=
><span style=3D"color: #008;" class=3D"styled-by-prettify">const</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"> std</span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">::</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify">chrono</span><span style=3D"color: =
#660;" class=3D"styled-by-prettify">::</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify">time_point</span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify"><</span><span style=3D"color: #606;" class=
=3D"styled-by-prettify">Clock</span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">,</span><span style=3D"color: #606;" class=3D"styled-by-=
prettify">Duration</span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">>&</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"> t</span><span style=3D"color: #660;" class=3D"styled-by-prettify">)=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></span=
><span style=3D"color: #660;" class=3D"styled-by-prettify">{</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 </span>=
<span style=3D"color: #008;" class=3D"styled-by-prettify">return</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"> extract</span><span =
style=3D"color: #660;" class=3D"styled-by-prettify"><</span><span style=
=3D"color: #606;" class=3D"styled-by-prettify">ToDuration</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">>(</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify">t</span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">.</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify">time_since_epoch</span><span style=3D"color: #660;"=
class=3D"styled-by-prettify">());</span></font><font color=3D"#000088"><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"><br></span></font><f=
ont color=3D"#000088"><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">}</span></font></div></code></div><br><br></div><div>And a sample usag=
e:</div><div><div class=3D"prettyprint" style=3D"border: 1px solid rgb(187,=
187, 187); word-wrap: break-word; background-color: rgb(250, 250, 250);"><=
code class=3D"prettyprint"><div class=3D"subprettyprint"><span style=3D"col=
or: #008;" class=3D"styled-by-prettify">template</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" =
class=3D"styled-by-prettify"><</span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">class</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"> </span><span style=3D"color: #606;" class=3D"styled-by-=
prettify">Rep</span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">,</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </spa=
n><span style=3D"color: #008;" class=3D"styled-by-prettify">class</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #606;" class=3D"styled-by-prettify">Period</span><span style=3D"=
color: #660;" class=3D"styled-by-prettify">></span><span style=3D"color:=
#000;" class=3D"styled-by-prettify"><br></span><span style=3D"color: #008;=
" class=3D"styled-by-prettify">inline</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"> std</span><span style=3D"color: #660;" class=3D=
"styled-by-prettify">::</span><span style=3D"color: #000;" class=3D"styled-=
by-prettify">ostream</span><span style=3D"color: #660;" class=3D"styled-by-=
prettify">&</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify"> </span><span style=3D"color: #008;" class=3D"styled-by-prettify">oper=
ator</span><span style=3D"color: #660;" class=3D"styled-by-prettify"><&l=
t;(</span><span style=3D"color: #000;" class=3D"styled-by-prettify">std</sp=
an><span style=3D"color: #660;" class=3D"styled-by-prettify">::</span><span=
style=3D"color: #000;" class=3D"styled-by-prettify">ostream</span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">&</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> os</span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">,</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">const</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"> std</span><span style=3D"color: #660;" class=3D"styled-=
by-prettify">::</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify">chrono</span><span style=3D"color: #660;" class=3D"styled-by-prettify"=
>::</span><span style=3D"color: #000;" class=3D"styled-by-prettify">duratio=
n</span><span style=3D"color: #660;" class=3D"styled-by-prettify"><</spa=
n><span style=3D"color: #606;" class=3D"styled-by-prettify">Rep</span><span=
style=3D"color: #660;" class=3D"styled-by-prettify">,</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #=
606;" class=3D"styled-by-prettify">Period</span><span style=3D"color: #660;=
" class=3D"styled-by-prettify">>&</span><span style=3D"color: #000;"=
class=3D"styled-by-prettify"> d</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">)</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"><br></span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">{</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
<br>=C2=A0 =C2=A0 </span><span style=3D"color: #008;" class=3D"styled-by-pr=
ettify">return</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"> os </span><span style=3D"color: #660;" class=3D"styled-by-prettify">&l=
t;<</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> d</=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">.</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify">count</span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify">();</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"><br></span><span style=3D"color: =
#660;" class=3D"styled-by-prettify">}</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"><br><br></span><span style=3D"color: #008;" clas=
s=3D"styled-by-prettify">int</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"> main</span><span style=3D"color: #660;" class=3D"styled-=
by-prettify">(</span><span style=3D"color: #008;" class=3D"styled-by-pretti=
fy">int</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> ar=
gc</span><span style=3D"color: #660;" class=3D"styled-by-prettify">,</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span sty=
le=3D"color: #008;" class=3D"styled-by-prettify">char</span><span style=3D"=
color: #660;" class=3D"styled-by-prettify">**</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"> argv</span><span style=3D"color: #660;"=
class=3D"styled-by-prettify">)</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify"><br></span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">{</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"><br>=C2=A0 =C2=A0 </span><font color=3D"#000088"><span style=3D"color=
: #008;" class=3D"styled-by-prettify">constexpr</span><span style=3D"color:=
#000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" c=
lass=3D"styled-by-prettify">auto</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> a </span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">=3D</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"> std</span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">::</span><span style=3D"color: #000;" class=3D"styled-by-prettify">chro=
no</span><span style=3D"color: #660;" class=3D"styled-by-prettify">::</span=
><span style=3D"color: #000;" class=3D"styled-by-prettify">minutes</span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=
=3D"color: #066;" class=3D"styled-by-prettify">123</span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">);</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"><br></span></font><span style=3D"color: #00=
0;" class=3D"styled-by-prettify">=C2=A0 =C2=A0 </span><span style=3D"color:=
#008;" class=3D"styled-by-prettify">constexpr</span><span style=3D"color: =
#000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" cl=
ass=3D"styled-by-prettify">auto</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify"> b </span><span style=3D"color: #660;" class=3D"styled=
-by-prettify">=3D</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"> std</span><span style=3D"color: #660;" class=3D"styled-by-prettify"=
>::</span><span style=3D"color: #000;" class=3D"styled-by-prettify">chrono<=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify">::</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify">seconds</span><span=
style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=3D=
"color: #066;" class=3D"styled-by-prettify">456</span><span style=3D"color:=
#660;" class=3D"styled-by-prettify">);</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 </span><span style=3D"color:=
#008;" class=3D"styled-by-prettify">constexpr</span><span style=3D"color: =
#000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" cl=
ass=3D"styled-by-prettify">auto</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify"> c </span><span style=3D"color: #660;" class=3D"styled=
-by-prettify">=3D</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"> a </span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
+</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> b</span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">;</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"><br><br>=C2=A0 =C2=A0 </sp=
an><span style=3D"color: #008;" class=3D"styled-by-prettify">constexpr</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span s=
tyle=3D"color: #008;" class=3D"styled-by-prettify">auto</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> h </span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">=3D</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"> extract</span><span style=3D"color: #660;=
" class=3D"styled-by-prettify"><</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify">std</span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">::</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify">chrono</span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">::</span><span style=3D"color: #000;" class=3D"styled-by-prettify">ho=
urs</span><span style=3D"color: #660;" class=3D"styled-by-prettify">>(</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify">c</span><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify">);</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 </span><sp=
an style=3D"color: #008;" class=3D"styled-by-prettify">constexpr</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #008;" class=3D"styled-by-prettify">auto</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"> m </span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">=3D</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"> extract</span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify"><</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify">std</span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">::</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy">chrono</span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
::</span><span style=3D"color: #000;" class=3D"styled-by-prettify">minutes<=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify">>(</span=
><span style=3D"color: #000;" class=3D"styled-by-prettify">c</span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">);</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 </span><span st=
yle=3D"color: #008;" class=3D"styled-by-prettify">constexpr</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"col=
or: #008;" class=3D"styled-by-prettify">auto</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"> s </span><span style=3D"color: #660;" cl=
ass=3D"styled-by-prettify">=3D</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"> extract</span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify"><</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify">std</span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">::</span><span style=3D"color: #000;" class=3D"styled-by-prettify">chr=
ono</span><span style=3D"color: #660;" class=3D"styled-by-prettify">::</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify">seconds</span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">>(</span><span =
style=3D"color: #000;" class=3D"styled-by-prettify">c</span><span style=3D"=
color: #660;" class=3D"styled-by-prettify">);</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"><br><br>=C2=A0 =C2=A0 std</span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">::</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify">cout </span><span style=3D"color:=
#660;" class=3D"styled-by-prettify"><<</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"> h </span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify"><<</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"> </span><span style=3D"color: #080;" class=3D"sty=
led-by-prettify">" hours, "</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify"><<</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify"> m </span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify"><<</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify"> </span><span style=3D"color: #080;" class=3D"styled-by-prettify">&q=
uot; minutes, "</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify"=
><<</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> =
s </span><span style=3D"color: #660;" class=3D"styled-by-prettify"><<=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><s=
pan style=3D"color: #080;" class=3D"styled-by-prettify">" seconds.&quo=
t;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify"><<</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"> std</span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">::</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify">endl</span><span style=3D"color: =
#660;" class=3D"styled-by-prettify">;</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"><br><br>=C2=A0 =C2=A0 </span><span style=3D"colo=
r: #008;" class=3D"styled-by-prettify">return</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #066;" cla=
ss=3D"styled-by-prettify">0</span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">;</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"><br></span><span style=3D"color: #660;" class=3D"styled-by-prettify=
">}</span></div></code></div><div><br></div>Would print:</div><div>2 hours,=
10 minutes, 0 seconds.<br></div><div><br></div><div>Cheers,</div><div>rick=
y</div></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/9b000907-f267-48b3-88b7-e230af875a51%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/9b000907-f267-48b3-88b7-e230af875a51=
%40isocpp.org</a>.<br />
------=_Part_1977_1746607561.1470403484370--
------=_Part_1976_273561257.1470403484369--
.
Author: Howard Hinnant <howard.hinnant@gmail.com>
Date: Fri, 5 Aug 2016 10:49:52 -0400
Raw View
--Apple-Mail=_E06CB113-23E5-4269-A4BE-CFBF5E034A60
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=UTF-8
On Aug 5, 2016, at 9:24 AM, Richard Thorell <richard.thorell@king.com> wrot=
e:
>=20
> Hey,
>=20
> I have some additions to the std::chrono library that might be useful for=
other. Thought I might share it here and see if there's any interest in it=
..
> Basically what it's all about is to be able to extract the number of seco=
nds/minutes/hours etc. from a time_point or duration type without convertin=
g it to a time_t object.
>=20
> Here's a reference implementation:
>=20
> //
> // time_traits
> //
> template <std::intmax_t Num, std::intmax_t Denom>
> struct time_traits_base;
>=20
> // Seconds
> template <>
> struct time_traits_base<1, 1>
> {
> static constexpr std::intmax_t num =3D 1;
> static constexpr std::intmax_t mod =3D 1;
> };
>=20
> // Minutes
> template <>
> struct time_traits_base<60, 1>
> {
> static constexpr std::intmax_t num =3D 60;
> static constexpr std::intmax_t mod =3D 60;
> };
>=20
> // Hours
> template <>
> struct time_traits_base<3600, 1>
> {
> static constexpr std::intmax_t num =3D 3600;
> static constexpr std::intmax_t mod =3D 24;
> };
>=20
> template <class T>
> struct time_traits;
>=20
> template <class Rep, std::intmax_t Num, std::intmax_t Denom>
> struct time_traits<std::chrono::duration<Rep, std::ratio<Num, Denom>>> : =
public time_traits_base<Num, Denom>
> {};
>=20
> //
> // extract
> //
> template <class ToDuration, class Rep, class Period>
> constexpr ToDuration extract(const std::chrono::duration<Rep, Period>& d)
> {
> return ToDuration((std::chrono::duration_cast<std::chrono::seconds>(d=
).count() / time_traits<ToDuration>::num) % time_traits<ToDuration>::mod);
> }
>=20
> template <class ToDuration,class Clock, class Duration>
> constexpr ToDuration extract(const std::chrono::time_point<Clock,Duration=
>& t)
> {
> return extract<ToDuration>(t.time_since_epoch());
> }
>=20
>=20
> And a sample usage:
> template <class Rep, class Period>
> inline std::ostream& operator<<(std::ostream& os, const std::chrono::dura=
tion<Rep, Period>& d)
> {
> return os << d.count();
> }
>=20
> int main(int argc, char** argv)
> {
> constexpr auto a =3D std::chrono::minutes(123);
> constexpr auto b =3D std::chrono::seconds(456);
> constexpr auto c =3D a + b;
>=20
> constexpr auto h =3D extract<std::chrono::hours>(c);
> constexpr auto m =3D extract<std::chrono::minutes>(c);
> constexpr auto s =3D extract<std::chrono::seconds>(c);
>=20
> std::cout << h << " hours, " << m << " minutes, " << s << " seconds."=
<< std::endl;
>=20
> return 0;
> }
>=20
> Would print:
> 2 hours, 10 minutes, 0 seconds.
I agree that <chrono> is in need of utilities such as the one you demonstra=
te. Here is my version of this utility:
https://howardhinnant.github.io/date/date.html
which would be used like this:
#include "date.h"
#include <iostream>
int
main()
{
using namespace std::chrono_literals;
std::cout << date::make_time(123min + 456s) << '\n';
}
And outputs:
02:10:36
The result of make_time is a struct with hours(), minutes(), etc. getters, =
though I=E2=80=99ve found in practice that I only use it for formatting (as=
opposed to using it as a data member in a larger type).
I am glad to see others (such as yourself) exploring ways to improve/extend=
<chrono>! :-)
Howard
--=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/97783A49-61BD-4444-B127-7FEE6BE19714%40gmail.com=
..
--Apple-Mail=_E06CB113-23E5-4269-A4BE-CFBF5E034A60
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename=signature.asc
Content-Type: application/pgp-signature;
name=signature.asc
Content-Description: Message signed with OpenPGP using GPGMail
-----BEGIN PGP SIGNATURE-----
iQIcBAEBCAAGBQJXpKeRAAoJEGbcHCxKqhWCkKMQAKWKYQ8HZzY+8nm6l09a3A+h
oBmOk9kcqIO1it7ThOwaSfoRMfZzT4eifX6jikSQ+lvF6G8lZEa5Mp0zY8FMuhO+
0HSffr7GFV+oikvrH0d7sVzyPT/tSItla8f5oIf0lYlDN6KdgJA63Ch0lUCj6MZp
v18EI+dRHrXv9VkHwUhjmtRzGSX/NrOt0KNOIOV/JplGtEmRik809zrNNFTAee3c
7JrZznbOCDIQZvCq+OWzQdMRFeIwz6Py195QBdbvTx07f5tKavkRbUX7tXogc3cY
4nrLnB4FRTZovyYyh62z2+YzeSNGfSdVNtmkgsETHehxcIDJtNjtaDKCLWE8LrQu
p+/axj6B4eCc1dIw5l/10OgAo9Gte3T/BRoQJU/bOVDMRFqz3WTs643x0B7ic8vQ
HvoRvs3PAjSpXvd6FAOZhO2m9b7JBPwhcIfDl2OQs1v+7wTL41qre1bkxhPr8F4f
TWbmjtxeyCSQtf6AlHo/UwV0lyaSA2GoB3jwjvn60U/lvj8rjPtrMXinM0/Bx1pL
usyhnlcyQL/OMzh5ZLVWNQrW8uAJLoBdLQKmRN+hPSJmjZ3eqqgz7xG6z0JzCiOG
NKEjlGeD0IBojFpQLTglFs7KUNcTdXjMV9DJk5z8kiryD6cYl4YfrSpA4zRklEN5
Pp6wVEpysKcDDRLT/ZQo
=XCzd
-----END PGP SIGNATURE-----
--Apple-Mail=_E06CB113-23E5-4269-A4BE-CFBF5E034A60--
.
Author: Nicol Bolas <jmckesson@gmail.com>
Date: Fri, 5 Aug 2016 09:01:33 -0700 (PDT)
Raw View
------=_Part_2244_298469709.1470412894245
Content-Type: multipart/alternative;
boundary="----=_Part_2245_1252636026.1470412894245"
------=_Part_2245_1252636026.1470412894245
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
BTW, how was P0355 received at the last meeting? Did it go over well?
The result of make_time is a struct with hours(), minutes(), etc. getters,=
=20
> though I=E2=80=99ve found in practice that I only use it for formatting (=
as opposed=20
> to using it as a data member in a larger type).=20
With C++17 getting structured binding, we might want that to be a struct=20
with public members, so that they can be unpacked more easily/efficiently.=
=20
Or at the very least, adding support for structured binding's interface for=
=20
user-defined unpacking.
--=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/0c4ba01a-886d-4340-9b8f-c2e929db6fd6%40isocpp.or=
g.
------=_Part_2245_1252636026.1470412894245
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">BTW, how was P0355 received at the last meeting? Did it go=
over well?<br><br><blockquote style=3D"margin: 0px 0px 0px 0.8ex; border-l=
eft: 1px solid rgb(204, 204, 204); padding-left: 1ex;" class=3D"gmail_quote=
">The result of make_time is a struct with hours(), minutes(), etc.=20
getters, though I=E2=80=99ve found in practice that I only use it for forma=
tting
(as opposed to using it as a data member in a larger type).
</blockquote><br>With C++17 getting structured binding, we might want that =
to be a struct with public members, so that they can be unpacked more easil=
y/efficiently. Or at the very least, adding support for structured binding&=
#39;s interface for user-defined unpacking.<br></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/0c4ba01a-886d-4340-9b8f-c2e929db6fd6%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/0c4ba01a-886d-4340-9b8f-c2e929db6fd6=
%40isocpp.org</a>.<br />
------=_Part_2245_1252636026.1470412894245--
------=_Part_2244_298469709.1470412894245--
.
Author: Richard Thorell <richard.thorell@king.com>
Date: Fri, 5 Aug 2016 09:04:37 -0700 (PDT)
Raw View
------=_Part_586_948367872.1470413077969
Content-Type: multipart/alternative;
boundary="----=_Part_587_1933847717.1470413077969"
------=_Part_587_1933847717.1470413077969
Content-Type: text/plain; charset=UTF-8
Yeah, the chrono library would need some more utilities like this. And
maybe even a way to convert to localtime etc. without using old C methods.
Found out that I put in the wrong constant in time_traits<seconds>. Should
be:
// Seconds
template <>
struct time_traits_base<1, 1>
{
static constexpr std::intmax_t num = 1;
static constexpr std::intmax_t mod = 60;
};
So my result was wrong and your were the right one :-) got the same now tho.
--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/a57979da-7312-4168-97cd-7eee1cf07dba%40isocpp.org.
------=_Part_587_1933847717.1470413077969
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr">Yeah, the chrono library would need some more utilities li=
ke this. And maybe even a way to convert to localtime etc. without using ol=
d C methods.<div><br></div><div>Found out that I put in the wrong constant =
in time_traits<seconds>. Should be:</div><div><div class=3D"prettypri=
nt" style=3D"border: 1px solid rgb(187, 187, 187); word-wrap: break-word; b=
ackground-color: rgb(250, 250, 250);"><code class=3D"prettyprint"><div clas=
s=3D"subprettyprint"><span style=3D"color: rgb(136, 0, 0);"><span style=3D"=
color: #800;" class=3D"styled-by-prettify">// Seconds</span></span><span st=
yle=3D"color: rgb(0, 0, 0);"><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"><br></span></span><span style=3D"color: rgb(0, 0, 136);"><span =
style=3D"color: #008;" class=3D"styled-by-prettify">template</span></span><=
span style=3D"color: rgb(0, 0, 0);"><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"> </span></span><span style=3D"color: rgb(102, 102, 0);">=
<span style=3D"color: #660;" class=3D"styled-by-prettify"><></span></=
span><span style=3D"color: rgb(0, 0, 0);"><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"><br></span></span><span style=3D"color: rgb(0, 0, =
136);"><span style=3D"color: #008;" class=3D"styled-by-prettify">struct</sp=
an></span><span style=3D"color: rgb(0, 0, 0);"><span style=3D"color: #000;"=
class=3D"styled-by-prettify"> time_traits_base</span></span><span style=3D=
"color: rgb(102, 102, 0);"><span style=3D"color: #660;" class=3D"styled-by-=
prettify"><</span></span><span style=3D"color: rgb(0, 102, 102);"><span =
style=3D"color: #066;" class=3D"styled-by-prettify">1</span></span><span st=
yle=3D"color: rgb(102, 102, 0);"><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">,</span></span><span style=3D"color: rgb(0, 0, 0);"><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"> </span></span><span sty=
le=3D"color: rgb(0, 102, 102);"><span style=3D"color: #066;" class=3D"style=
d-by-prettify">1</span></span><span style=3D"color: rgb(102, 102, 0);"><spa=
n style=3D"color: #660;" class=3D"styled-by-prettify">></span></span><sp=
an style=3D"color: rgb(0, 0, 0);"><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"><br></span></span><span style=3D"color: rgb(102, 102, 0);"=
><span style=3D"color: #660;" class=3D"styled-by-prettify">{</span></span><=
span style=3D"color: rgb(0, 0, 0);"><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"><br>=C2=A0 =C2=A0 </span></span><span style=3D"color: rg=
b(0, 0, 136);"><span style=3D"color: #008;" class=3D"styled-by-prettify">st=
atic</span></span><span style=3D"color: rgb(0, 0, 0);"><span style=3D"color=
: #000;" class=3D"styled-by-prettify"> </span></span><span style=3D"color: =
rgb(0, 0, 136);"><span style=3D"color: #008;" class=3D"styled-by-prettify">=
constexpr</span></span><span style=3D"color: rgb(0, 0, 0);"><span style=3D"=
color: #000;" class=3D"styled-by-prettify"> std</span></span><span style=3D=
"color: rgb(102, 102, 0);"><span style=3D"color: #660;" class=3D"styled-by-=
prettify">::</span></span><span style=3D"color: rgb(0, 0, 0);"><span style=
=3D"color: #000;" class=3D"styled-by-prettify">intmax_t num </span></span><=
span style=3D"color: rgb(102, 102, 0);"><span style=3D"color: #660;" class=
=3D"styled-by-prettify">=3D</span></span><span style=3D"color: rgb(0, 0, 0)=
;"><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span></span=
><span style=3D"color: rgb(0, 102, 102);"><span style=3D"color: #066;" clas=
s=3D"styled-by-prettify">1</span></span><span style=3D"color: rgb(102, 102,=
0);"><span style=3D"color: #660;" class=3D"styled-by-prettify">;</span></s=
pan><span style=3D"color: rgb(0, 0, 0);"><span style=3D"color: #000;" class=
=3D"styled-by-prettify"><br>=C2=A0 =C2=A0 </span></span><span style=3D"colo=
r: rgb(0, 0, 136);"><span style=3D"color: #008;" class=3D"styled-by-prettif=
y">static</span></span><span style=3D"color: rgb(0, 0, 0);"><span style=3D"=
color: #000;" class=3D"styled-by-prettify"> </span></span><span style=3D"co=
lor: rgb(0, 0, 136);"><span style=3D"color: #008;" class=3D"styled-by-prett=
ify">constexpr</span></span><span style=3D"color: rgb(0, 0, 0);"><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"> std</span></span><span sty=
le=3D"color: rgb(102, 102, 0);"><span style=3D"color: #660;" class=3D"style=
d-by-prettify">::</span></span><span style=3D"color: rgb(0, 0, 0);"><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify">intmax_t mod </span></sp=
an><span style=3D"color: rgb(102, 102, 0);"><span style=3D"color: #660;" cl=
ass=3D"styled-by-prettify">=3D</span></span><span style=3D"color: rgb(0, 0,=
0);"><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><sp=
an style=3D"color: #066;" class=3D"styled-by-prettify">60</span></span><spa=
n style=3D"color: rgb(102, 102, 0);"><span style=3D"color: #660;" class=3D"=
styled-by-prettify">;</span></span><span style=3D"color: rgb(0, 0, 0);"><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"><br></span></span><s=
pan style=3D"color: rgb(102, 102, 0);"><span style=3D"color: #660;" class=
=3D"styled-by-prettify">};</span></span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"><br></span></div></code></div><br>So my result was =
wrong and your were the right one :-) got the same now tho.</div></div>
<p></p>
-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals" group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/a57979da-7312-4168-97cd-7eee1cf07dba%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/a57979da-7312-4168-97cd-7eee1cf07dba=
%40isocpp.org</a>.<br />
------=_Part_587_1933847717.1470413077969--
------=_Part_586_948367872.1470413077969--
.
Author: Howard Hinnant <howard.hinnant@gmail.com>
Date: Fri, 5 Aug 2016 12:14:24 -0400
Raw View
--Apple-Mail=_116916D2-42B1-44A2-AFA9-E19A88243BE2
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=UTF-8
On Aug 5, 2016, at 12:04 PM, Richard Thorell <richard.thorell@king.com> wro=
te:
>=20
> Yeah, the chrono library would need some more utilities like this. And ma=
ybe even a way to convert to localtime etc. without using old C methods.
Here=E2=80=99s what I=E2=80=99m proposing for that issue:
https://howardhinnant.github.io/date/tz.html
which looks like this:
#include "tz.h"
#include <iostream>
int
main()
{
std::cout << date::make_zoned(date::current_zone(),
std::chrono::system_clock::now()) << =
'\n';
}
and just output for me:
2016-08-05 12:09:38.223655 EDT
>=20
> Found out that I put in the wrong constant in time_traits<seconds>. Shoul=
d be:
> // Seconds
> template <>
> struct time_traits_base<1, 1>
> {
> static constexpr std::intmax_t num =3D 1;
> static constexpr std::intmax_t mod =3D 60;
> };
>=20
> So my result was wrong and your were the right one :-) got the same now t=
ho.
Excellent! Glad I could help you fix it.
On Aug 5, 2016, at 12:01 PM, Nicol Bolas <jmckesson@gmail.com> wrote:
>=20
> With C++17 getting structured binding, we might want that to be a struct =
with public members, so that they can be unpacked more easily/efficiently. =
Or at the very least, adding support for structured binding's interface for=
user-defined unpacking.
Good suggestion, thanks! Looks like it is time for me to learn about struc=
tured bindings! :-) (http://www.open-std.org/jtc1/sc22/wg21/docs/papers/20=
16/p0217r3.html)
Howard
--=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/8C45F7F2-371B-43A1-820C-4E46F636C6BE%40gmail.com=
..
--Apple-Mail=_116916D2-42B1-44A2-AFA9-E19A88243BE2
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename=signature.asc
Content-Type: application/pgp-signature;
name=signature.asc
Content-Description: Message signed with OpenPGP using GPGMail
-----BEGIN PGP SIGNATURE-----
iQIcBAEBCAAGBQJXpLthAAoJEGbcHCxKqhWC/MQP/0DMpLddfymiJHrxn8fhf7kP
oV0N7YqI+3CWVNbnFeGMs5p8lEyWzLFQvXSr6GMUId6p1Lhxgelozi+8OYWP16Iw
D/8iGM6qkil1qDEcHFIXeMzJ0lxaxQLGR+za/VmREHczMsqCgKHJZlbzq2YN0zKt
IqnzcnZr3EDZ3+gdrFc1RltbEECBgB34lFLVi2K9NRibyKf7IRhFnCvBNlBWmpcc
RCyuyqcV4zOYAAHz++pvi2+WnodQjt8SCq/p6F1eBma7OTC4b5nIY6IjJqOQOnzu
u1uYsYPsRL3FhZxQLlh2B7dmItXNNaubltYaV3AIzf2YcDhHeBi4AheQzpC+TGNf
Z7PI7KC+2kZBSTuFhQ0piXsT0tpwXFdRkylz2zY9cpbi1+983LJ1REPa3Sz7sDNA
XI3rywMo22jALzGHGQGS+kDJm3kGt+iEHHhOn6mdf5HuDROO4cMAFeiCXr7UHboe
ztbRaQNY5cZofD0yZJCB+YW2uYPgJQB9JccBBqshv9pYccNktKJOqFq8iE+Wik+1
6MqQ0iZNPcneTGELfgyOar1r76Fzn0d+eIZA4t+G1QR9izUqg8WwKc+UNDAFnz5j
kgaLNINDF5IX5Lc6P2JNAIdSP1psgbhpAucXfnpuS1iZGcvzjMtWGGC2ydApankF
QYf5OIGxeXqsScaUuJPw
=/1ZP
-----END PGP SIGNATURE-----
--Apple-Mail=_116916D2-42B1-44A2-AFA9-E19A88243BE2--
.