units icon indicating copy to clipboard operation
units copied to clipboard

Binary operators between units' units and `std::chrono::duration`s

Open JohelEGP opened this issue 5 years ago • 4 comments

Time units and std::chrono::durations are interconvertible, but the latter don't participate in the binary operators for units. This means that you have to wrap std::chrono::durations in some appropriate time unit before adding/subtracting them from other time units or using them with the dimensional analysis functions.

JohelEGP avatar Nov 08 '18 00:11 JohelEGP

Now it is easier: 42_s + units::unit(1s). But not the most easy: 42_s + 1s.

JohelEGP avatar Oct 06 '20 01:10 JohelEGP

we don't have an implicit conversion to chrono types?

nholthaus avatar Oct 10 '20 22:10 nholthaus

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.

nholthaus avatar Oct 10 '20 22:10 nholthaus

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.

JohelEGP avatar Oct 10 '20 22:10 JohelEGP