On 03/14/2017 10:55 PM, Howard Hinnant wrote:
> I will definitely reconsider my position. I would like to hear more about the errors you encountered.
Most errors occurred in calculations that used both duration and
floating-point numbers. These calculations used <cmath> so they were
done with double. Sometimes they needed to use a constant (e.g.
a threshold value) that was specified as a duration. We used .count()
on those constants. If one of these constants was declared as, say,
chrono::milliseconds, and somebody later changed it to chrono::seconds
the calculations would be off by a factor of 1000.
> I also find myself wondering why this simpler syntax did not suffice:
>
> chrono::seconds s{2};
> auto ms = chrono::milliseconds{s}.count();
That will solve the duration case. It is less attractive for the
time_point case, but I realize that this is insufficient motivation for
a proposal.
> Was it the need to convert to coarser units prior to the cast? Overuse of duration_cast (when an implicit conversion would do) is another common mistake I see. Overuse of duration_cast leads to the hiding of those conversions that have truncation errors under the hood. In case you have to track down an error that you suspect is caused by truncation, it is easier if those conversions that didn’t require duration_cast didn’t use it.
I suggested duration_cast because I thought that was the way to convert
between duration types.