O'Reilly logo

Using the C++ Standard Template Libraries by Ivor Horton

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required