nholthaus / units

a compile-time, header-only, dimensional analysis and unit conversion library built on c++14 with no dependencies.
http://nholthaus.github.io/units/
MIT License
947 stars 134 forks source link

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

Open JohelEGP opened 5 years ago

JohelEGP commented 5 years ago

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 commented 3 years ago

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

nholthaus commented 3 years ago

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

nholthaus commented 3 years ago

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.

JohelEGP commented 3 years ago

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.