Debian Codegraph @

yo/namespaces/chrono/examples/durationmembers.cc

raw
1 #include <chrono>
2 #include <iostream>
3
4 using namespace std;
5 using namespace chrono;
6
7 int main()
8 {
9 milliseconds amount(30);
10
11 amount = seconds{5};
12
13 minutes halfHour{ 30 };
14
15 hours oneHour{ 1 };
16
17 cout << (halfHour + oneHour).count() << '\n'; // displays 90
18
19 halfHour += oneHour; // halfHour.count() == 90
20 // oneHour += halfHour; // won't compile
21
22 minutes min{ 1h };
23
24 cout << min.count() << '\n';
25
26 minutes fullHour = minutes{ 30 } + halfHour;
27
28 halfHour = 2 * fullHour;
29 halfHour = fullHour / 2;
30 fullHour = halfHour + halfHour;
31
32 halfHour /= 2;
33 halfHour *= 2;
34
35 cout << halfHour.count() << ' ' << fullHour.count() << '\n';
36 cout << seconds::zero().count() << '\n';
37 cout << minutes::min().count() << ' ' << minutes::max().count() << '\n';
38
39 }