boostorg / boostorg/units

[Feature Request]: unit_cast

Open
#43 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
39
Forks
60
PR merge metrics
No merged PRs in 30d

Description

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 siLength;
auto cgsLength = static_cast>(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 siLength;
auto cgsLength = unit_cast(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? :thinking:

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.