Opened 8 years ago

Closed 8 years ago

#10182 closed Bugs (fixed)

Header order dependency for boost/multiprecision/random.hpp

Reported by: pcfreak <coolpcfreak@…> Owned by: John Maddock
Milestone: To Be Determined Component: multiprecision
Version: Boost 1.54.0 Severity: Problem
Keywords: multiprecision random uniform_int_distribution Cc:

Description

Using boost/multiprecision/random.hpp requires that it gets included before boost/random/uniform_int_distribution.hpp when using it in combination with that.
See example code:

#include <gmp.h>
#include <cstdlib>
#include <iostream>
#include <boost/multiprecision/gmp.hpp>
//#include <boost/multiprecision/random.hpp> // fails unless this header is included first
#include <boost/random/random_device.hpp>
#include <boost/random/uniform_int_distribution.hpp>
#include <boost/multiprecision/random.hpp> // does not work if included here

using namespace std;
using namespace boost;

int main() {
        typedef multiprecision::number<multiprecision::gmp_int> MpzInt;
        random::random_device rndDevice;
        MpzInt rndRangeTo(MpzInt(1) << 256);
        const MpzInt rndRangeFrom(rndRangeTo >> 1);
        random::uniform_int_distribution<MpzInt> rndRange(rndRangeFrom, rndRangeTo);
        const MpzInt rndValue(rndRange(rndDevice));
        cout << rndValue << endl;

        return EXIT_SUCCESS;
}

Change History (2)

comment:1 by gfurnish, 8 years ago

Per some irc discussions I have been encouraged to post that I tested this on latest master 80b9d8d13617c487c5ebaf06fb8ba757a91e6a0c with gcc version 4.8.3 20140624 (Red Hat 4.8.3-1) and can confirm.

comment:2 by John Maddock, 8 years ago

Resolution: fixed
Status: newclosed

This is actually a known limitation. However, the latest develop code for Boost.Multiprecision plus Boost.Random removes the need for boost/multiprecision/random.hpp altergether and fixes this issue. Unfortunately this code is too late for the next (1.59) release.

Note: See TracTickets for help on using tickets.