|
|
The individual components of a Duration can be viewed by the `component extractor' operations:
Duration d = Duration::seconds(-1); cout << d.day_part() << "d " << d.hour_part() << "h " << d.minute_part() << "m " << d.second_part() << "s" << endl;
which prints
0d 0h 0m -1s
The fact that Duration arguments are `normalized' means that the values returned by the component extractors satisfy the following invariant:
Duration d = Duration::hours(1);cout << seconds(d) << endl;
which prints 3600.
Finally, operator void*() provides a convenient test for zero-length Durations through implicit conversion in contexts like if and loop conditions, which expect integral or pointer values. The following loop depends on implicit conversion for its termination condition:
for(Duration d = Duration::days(100); d; d -= Duration::days(1)){ ... }