[Boost-bugs] [Boost C++ Libraries] #12777: uniform_real_distribution fails to compile with result_type having explicit conversion constructor from float

Subject: [Boost-bugs] [Boost C++ Libraries] #12777: uniform_real_distribution fails to compile with result_type having explicit conversion constructor from float
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2017-01-22 07:47:15


#12777: uniform_real_distribution fails to compile with result_type having explicit
conversion constructor from float
------------------------------+---------------------------
 Reporter: b7.10110111@… | Owner: no-maintainer
     Type: Bugs | Status: new
Milestone: To Be Determined | Component: random
  Version: Boost 1.63.0 | Severity: Problem
 Keywords: |
------------------------------+---------------------------
 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.

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/12777>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:20 UTC