nholthaus / units

a compile-time, header-only, dimensional analysis and unit conversion library built on c++14 with no dependencies.

Home Page:http://nholthaus.github.io/units/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Implicit conversion of the time units to/from `std::chrono`

jinay1991 opened this issue · comments

Feature Request for supporting implicit safe conversion of time units between std::chrono and units::time.

Library used: v2.3.1
Compilers used: GCC v12, Clang v12

This is supported in the 3.0 series of releases. Consider backporting to 2.3.

Parts of this seems to got broken from 3.0.0 Beta to 3.0.0 Beta 2. The following code compiled on Beta, but does not compile on Beta 2 any more:

units::seconds<> s(0);
s += std::chrono::seconds(0);

The problem seems to got introduced with 26242aa where an additional overload for operator+= with signature

template<class UnitTypeLhs, class T, std::enable_if_t<traits::is_unit_v<UnitTypeLhs> && !traits::is_unit_v<T>, int> = 0>
constexpr UnitTypeLhs& operator+=(UnitTypeLhs& lhs, T rhs) noexcept;

has been introduced. For std::chrono types on the lhs, this operator now gets precedence and fails in finding the corresponding operator+ used in its implementation.