Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

problems with C++11-library and g++ 4.4.7

Tags:

c++

random

I am working on a server with GCC version 4.4.7, and I am forced to work with this version unfortunately. I want to make use of the <random> library of C++0x, but I read here that in this version uniform_real_distribution is called uniform_real. When I try to call this function and normal_distribution, I don't get useful output. See this example:

#include <random>
#include <iostream>

using namespace std;

int main()
{
    typedef std::mt19937 Engine;
    typedef std::uniform_real<double> Dis1;
    typedef std::normal_distribution<double> Dis2;

    Engine eng(0);

    Dis1 dis1(0, 1);
    cout << dis1(eng) << endl; //OUTPUTS 3.49921e+09

    Dis2 dis2(0, 1);
    cout << dis2(eng) << endl; //STALLS, NO OUTPUT

    return 0;
}

I compile with g++44 -std=c++0x main.cpp and I have shown what output I get. What is the issue here?

like image 416
BillyJean Avatar asked Oct 05 '22 10:10

BillyJean


1 Answers

C++11 support in gcc 4.4 is rather sparse.

The release notes for gcc 4.5 include

Improved experimental support for the upcoming ISO C++ standard, C++0x

specifically mentioning <random>.

like image 171
Drew Dormann Avatar answered Oct 13 '22 11:10

Drew Dormann