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
952 stars 135 forks source link

Millisecond to nanosecond conversion #168

Closed kunaltyagi closed 6 years ago

kunaltyagi commented 6 years ago

Both variable declaration lines in the following snippet give build time error:

using namespace units::literals;
const units::time::nanoseconds min_delay = 5_ms;
const units::time::ns max_delay = 50.0_ms;

Error is due to no viable conversion, however, I don't understand why the conversion is not possible (for integral values, std::chrono defines the conversions, but I'm hoping to use floating point values also)

Compiler: clang v6.0.0 Units: HEAD@master

PS: the compiler tried matching it with std::chrono so maybe in future, we might get collisions with std::chrono unless my compiler just checked std::chrono because it wanted to.

EDIT:

Ran the test, and all tests succeed except UnitContainer.to_string_locale and that's my own fault.

JohelEGP commented 6 years ago

Greetings.

The units' name use their singular spelling appended with _t, so in this case the correct code reads:

using namespace units::literals;
const units::time::nanosecond_t min_delay = 5_ms;
const units::time::nanosecond_t max_delay = 50.0_ms;

159 covers their renaming to the more natural form you first used. The others are actually conversion factors, and they will be renamed as per #161, which should make any error message more clear that something wrong is being used.

kunaltyagi commented 6 years ago

Thanks for this I had been using auto along with literals so didn't run into this issue before.

This was a very dumb oversight on my part. Somehow my brain decided not to look at '_t'

nholthaus commented 6 years ago

@kunaltyagi I'm really glad you logged this as an issue, I think it shows us that we're moving in the right direction with our name refactoring.