Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jinay1991 opened this issue Sep 4, 2022 · 2 comments
Open

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

jinay1991 opened this issue Sep 4, 2022 · 2 comments

Comments

@jinay1991
Copy link

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

@jinay1991 jinay1991 changed the title Interchangeable unit for time Implicit conversion of the time units to/from std::chrono Sep 4, 2022
@nholthaus
Copy link
Owner

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

@andipeer
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants