is_constructible has unexpected results
- Dominant language
- C++
- Stars
- 39
- Forks
- 60
- PR merge metrics
- No merged PRs in 30d
Description
```
#include
#include
#include
#include
using TLiter = boost::units::quantity;
using THour = boost::units::quantity;
static_assert(!boost::is_constructible::value, "Should not be constructible from unrelated units");
```
https://godbolt.org/z/W-7Nvg
This fails to compile before it is able to check the static assertion with the following error:
```
error: no matching function for call to 'conversion_factor(boost::units::unit >, boost::units::dimensionless_type>, boost::units::heterogeneous_system > >, boost::units::static_rational<1l> >, boost::units::dimensionless_type>, boost::units::list >, boost::units::dimensionless_type>, boost::units::dimensionless_type> >, void>, boost::units::unit >, boost::units::dimensionless_type>, boost::units::heterogeneous_system >, boost::units::dimensionless_type>, boost::units::list >, boost::units::dimensionless_type>, boost::units::dimensionless_type> >, void>)'
return(destination_type::from_value(static_cast(source.value() * conversion_factor(Unit1(), Unit2()))));
```
This has consequences for using boost::units inside a boost::variant as the constructor of the variant cannot reliably detect if the given source operand can be converted to any of the contained storage types of the variant.
In our source code base with a vendored-in copy of Boost, I fixed the issue by adding a check that `conversion_factor` is a defined function for the given source and target units of a quantity. If that is not the case, the constructor for explicit conversions is disabled. This does not work with [an output test case](https://github.com/boostorg/units/blob/develop/test/test_output.cpp#L262) at this point in time.
Furthermore, the current solution only fixes the problem in C++11 and beyond.
Before digging deeper and creating a proper PR, I wanted to know if I am looking at the right approach or if I am off on the wrong foot.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.