You cannot express the sum of the duration values d1 and d2 as an integral multiple of .2 seconds so the value of the result is slightly out. If the value for d2 was 54, the correct result of 77 would be obtained.

The duration type supports assignment so you can assign the value of one duration object to another. Implicit conversion will apply if the condition I described at the beginning of this section applies; otherwise you need to cast the right operand explicitly.

For example, you can write the following:

std::chrono::duration<int, std::ratio<1, 5>> d1 {50};      // 10 secondsstd::chrono::duration<int, std::ratio<1, 10>> d2 {53};     // 5.3 secondsd2 = d1;                                                   // d2 is 100 = 10 seconds

Comparing ...

Get Using the C++ Standard Template Libraries now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.