Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

std::function<> and the Intel compiler version 11.1

Tags:

c++

lambda

intel

I'm having trouble working with lambda functions in the Intel compiler, in particular, the following code won't compile:

template<typename T>
std::function<T (int)>  make_func(T x) {
  return [=](int index) -> T
  {
     return x;
  };
}

The error I get is

error: namespace "std" has no member "function"

The code compiles and runs fine on my Mac, (macports gcc version 4.5). The error is at work, where we use the Intel compiler version 11.1. It does accept lambda functions (with the -std=c++0x option), such as:

auto lam = [=](int j) -> int {
    printf("testing for lambdas: %d\t%d\n", n, j);
    return n;
};

int g = lam(7);

The version of gcc installed at work is 4.1.2, so I'm guessing that the standard library is old?

/bin/libc.so.6

says it's version 2.5 compiled with gcc 4.1.2.

Is there a way around this?

thanks in advance for any help

like image 309
nick maxwell Avatar asked Jun 29 '11 20:06

nick maxwell


1 Answers

I get the same behavior with icc 11.1 on a system where gcc 4.5.2 is installed.

g++'s header <functional> is protected with #ifdef __GXX_EXPERIMENTAL_CXX0X__ which is not defined when icc is used.

I would consider switching to boost::function in this setup, which of course works with icc.

like image 51
Cubbi Avatar answered Oct 23 '22 15:10

Cubbi