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

[Feature Request]: unit_cast #43

Open
Krzmbrzl opened this issue Nov 29, 2019 · 0 comments
Open

[Feature Request]: unit_cast #43

Krzmbrzl opened this issue Nov 29, 2019 · 0 comments

Comments

@Krzmbrzl
Copy link

When I try to cast a quantity to it's numerical representation I can use quantity_cast. That's great. What I think could also be very helpful is a shorthand for casting a quantity to a different unit. Now I know that this can be done like so:

boost::units::quantity<boost::units::si::length, double> siLength;
auto cgsLength = static_cast<boost::units::quantity<boost::units::cgs::length, double>>(siLength);

However this feels kinda more bulky than it'd need to be. It would be very neat if something like this would be possible:

boost::units::quantity<boost::units::si::length, double> siLength;
auto cgsLength = unit_cast<boost::units::cgs::length>(siLength);

So essentially I am asking for a way to cast to a different (compatible) unit without having to explicitly write that I want to cast it to a quantity again. That should be deduced. Thus when starting from a quantity of double, I'd expect this cast to automatically cast to a quantity of double as well. Same for int and all other types.

Would something like this be possible? 🤔

@Krzmbrzl Krzmbrzl changed the title Quantity_cast for unit [Feature Request]: unit_cast Nov 29, 2019
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

1 participant