units
units copied to clipboard
Binary operators between units' units and `std::chrono::duration`s
Time units and std::chrono::duration
s are interconvertible, but the latter don't participate in the binary operators for units. This means that you have to wrap std::chrono::duration
s in some appropriate time unit before adding/subtracting them from other time units or using them with the dimensional analysis functions.
Now it is easier: 42_s + units::unit(1s)
. But not the most easy: 42_s + 1s
.
we don't have an implicit conversion to chrono
types?
So i have a file/class that I almost always copy around as a companion to units called timestamp
(this gist, units 2.3). I wrote some of it in the gist so there may be some pseudo code in there.
I've toyed with including it with units, but haven't because it's not 100% germane. I wonder if a class like this is kind of what you're trying to get at. The need for chrono
arithmetic is obviated by wrapping the clock access in units
. Our duration's are obvious far superior to chrono
.
It's your call whether this is absolutely necessary. I just though it'd be nice if the library was interoperable. Of course, I do believe that the type of 1_s + 1s
should be that of 1_s
.