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
934 stars 134 forks source link

Request: Implicit conversion from double-precision seconds to `std::chrono::duration<double>`. #290

Open BenFrantzDale opened 1 year ago

BenFrantzDale commented 1 year ago

Please include the following information in your issue:

  1. Using ea6d126942cb3225a341568ab57ec52513977875 (Sun Oct 11 06:46:02 2020 +0800)
  2. Apple clang version 13.1.6 (clang-1316.0.21.2.5)

If I change the tests to try to do implicit conversion to std::chrono::duration<double> instead of to std::chrono::nanoseconds, I get a compile error. This seems weird since seconds_t is duration in double seconds.:

/path/to/units/unitTests/main.cpp:2637:32: error: no viable conversion from 'units::time::second_t' (aka 'unit_t<unit<ratio<1>, base_unit<ratio<0L, 1L>, ratio<0>, ratio<1>>>>') to 'std::chrono::duration<double>'
        std::chrono::duration<double> j = second_t(1);
                                      ^   ~~~~~~~~~~~

It looks like we could change the implicit-conversion operator to convert to any/some std::chrono::duration<T, Ratio> types. As far as I'm concerned, it'd be fine to just add implicit conversion from units' double seconds to std::chrono::duration<value_type>.