mpusz / mp-units

The quantities and units library for C++
https://mpusz.github.io/mp-units/
MIT License
997 stars 79 forks source link

Improve the definition of a value-preserving conversion #517

Open mpusz opened 7 months ago

mpusz commented 7 months ago

Right now wee clone std::chrono::duration duration. Consider the usage of one of the following:

JohelEGP commented 7 months ago

From P0870R5:

[P2509R0] proposes a type trait which complements the present proposal, by detecting if a given target type can represent all the values of a given source type. This is different from detecting a narrowing conversion as defined by the core language; for instance, converting int to double is a narrowing conversion even on common platforms where double can actually precisely represent any int value.

mpusz commented 7 months ago

Yes, on the one hand, this is precisely what we want. On the other hand, this makes the code not portable.