开发者

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

开发者 https://www.devze.com 2023-03-16 13:16 出处:网络
I\'m having trouble working with lambda functions in the Intel compiler, in particular, the following code won\'t compile:

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 f开发者_StackOverflow中文版or any help


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.


Well, the code shown doesn't include a single header. And yet you refer to the standard library std::function.

So no, it doesn't compile. As with any other part of the standard library, you need to include the header where std::function is defined: <functional>.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号