Opened 6 years ago
#12777 new Bugs
uniform_real_distribution fails to compile with result_type having explicit conversion constructor from float
| Reported by: | Owned by: | No-Maintainer | |
|---|---|---|---|
| Milestone: | To Be Determined | Component: | random |
| Version: | Boost 1.63.0 | Severity: | Problem |
| Keywords: | Cc: |
Description
Consider the following test program:
#include <random>
#include <boost/random/uniform_real_distribution.hpp>
#include <half.hpp>
template<typename Float>
void test()
{
std::random_device rd;
std::mt19937 mt(rd());
boost::random::uniform_real_distribution<Float> rnd(Float(1),Float(10));
rnd(mt);
}
int main()
{
test<float>(); // this works
test<half_float::half>(); // and this doesn't compile
}
It uses half.hpp from half.sourceforge.net. This type has a peculiar behavior with arithmetic involving types other than it: the variable converts implicitly to float, and then the explicit constructor half_float::half(float) prevents some code from compiling.
Namely, the code above doesn't compile due to the return 2 * generate_uniform_real(...) in generate_uniform_real(). I've seen there already exist explicit casts like for the arguments T(min_value / 2) and the like. I've been able to fix it locally with the attached patch.
Attachments (1)
Note:
See TracTickets
for help on using tickets.

Proposed patch