Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.

std:: binding with c++0x std in icpc

PRASHANTH_T_
Beginner
1,357 Views

I am using icpc with -std=c++0x, in which "std::uniform_real_distribution<double> rnd" throws a couple of errors during compile time, like

WangLandau.h(103): error: qualified name is not allowed
   std::uniform_real_distribution<double> rnd;
   ^

WangLandau.h(103): error #77: this declaration has no storage class or type specifier
   std::uniform_real_distribution<double> rnd;
   ^

WangLandau.h(103): error: expected a ";"
   std::uniform_real_distribution<double> rnd;
                                 ^

WangLandau2d.h(92): error: qualified name is not allowed
    std::uniform_real_distribution<double> rnd; //, rnd11(-1.0,1.0),rnd0pi(0.0,2.0*M_PI);
    ^

WangLandau2d.h(92): error #77: this declaration has no storage class or type specifier
    std::uniform_real_distribution<double> rnd; //, rnd11(-1.0,1.0),rnd0pi(0.0,2.0*M_PI);
    ^

WangLandau2d.h(92): error: expected a ";"
    std::uniform_real_distribution<double> rnd; //, rnd11(-1.0,1.0),rnd0pi(0.0,2.0*M_PI);

Where am I going wrong ?

                                  ^

 

 

0 Kudos
1 Solution
pbkenned1
Employee
1,357 Views

icc depends on GCC headers and libraries.  What version of GCC is installed on your machine?  Your example runs correctly with g++-4.8.1.  It also runs correctly with icc-14.0.1.106 if you have that version of GCC (or later) installed.

$ g++ --version
g++ (GCC) 4.8.1
Copyright (C) 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ icc -V
Intel(R) C Intel(R) 64 Compiler XE for applications running on Intel(R) 64, Version 14.0.1.106 Build 20131008
Copyright (C) 1985-2013 Intel Corporation.  All rights reserved.

$ icc -std=c++11 U506774.cpp && ./a.out
1.12105 1.24086 1.94634 1.30563 1.01601 1.07346 1.17482 1.4248 1.39896 1.72678
$

patrick

View solution in original post

0 Kudos
6 Replies
JenniferJ
Moderator
1,357 Views

what is the icc version? can you post the code snippet? the gcc version?

Jennifer

0 Kudos
PRASHANTH_T_
Beginner
1,357 Views

Version of icc is  13.1.0 20130121 , It is a random number generator

// Random number generator and distribution:
  RNG rng; std::uniform_real_distribution<double> rnd;

 do {
      x = rnd(rng); y = rnd(rng);
    } while(x*x+y*y>1);

 

 

 

0 Kudos
TimP
Honored Contributor III
1,357 Views

I thought icpc 13.1 supported -std=c++11 (but not the temporary g++ option c++0x) when used with g++ 4.7 or newer, otherwise neither of those options would be supported.  I'd be reluctant to try 13.1.0; the last 13.1 or most recent 14.0 seem better bets.

0 Kudos
PRASHANTH_T_
Beginner
1,357 Views

Same problem persists even with the icpc (ICC) 14.0.1 20131008 version.

Say for example, I want to compile this code,

#include <random>
#include <iostream>
 
int main()
{
    std::random_device rd;
    std::mt19937 gen(rd());
    std::uniform_real_distribution<> dis(1, 2);
    for (int n = 0; n < 10; ++n) {
        std::cout << dis(gen) << ' ';
    }
    std::cout << '\n';
}

 

I am getting errors like 

rand.cpp(8): error: namespace "std" has no member "uniform_real_distribution"
      std::uniform_real_distribution<> dis(1, 2);
           ^

rand.cpp(8): error: expected an expression
      std::uniform_real_distribution<> dis(1, 2);
                                     ^

rand.cpp(10): error: identifier "dis" is undefined
          std::cout << dis(gen) << ' ';
                       ^

0 Kudos
pbkenned1
Employee
1,358 Views

icc depends on GCC headers and libraries.  What version of GCC is installed on your machine?  Your example runs correctly with g++-4.8.1.  It also runs correctly with icc-14.0.1.106 if you have that version of GCC (or later) installed.

$ g++ --version
g++ (GCC) 4.8.1
Copyright (C) 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ icc -V
Intel(R) C Intel(R) 64 Compiler XE for applications running on Intel(R) 64, Version 14.0.1.106 Build 20131008
Copyright (C) 1985-2013 Intel Corporation.  All rights reserved.

$ icc -std=c++11 U506774.cpp && ./a.out
1.12105 1.24086 1.94634 1.30563 1.01601 1.07346 1.17482 1.4248 1.39896 1.72678
$

patrick

0 Kudos
PRASHANTH_T_
Beginner
1,357 Views

I get it thanks :) !

0 Kudos
Reply