std :: function<>和英特尔编译器版本11.1 [英] std::function<> and the Intel compiler version 11.1

查看:96
本文介绍了std :: function<>和英特尔编译器版本11.1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用Intel编译器中的lambda函数时遇到了麻烦,特别是以下代码无法编译:

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;
  };
}

我得到的错误是

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

代码可以在我的Mac(macports gcc版本4.5)上编译并正常运行.该错误正在起作用,我们使用的是Intel编译器版本11.1.它确实接受lambda函数(带有-std = c ++ 0x选项),例如:

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);

在工作中安装的gcc版本是4.1.2,所以我猜标准库很旧?

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

说它是用gcc 4.1.2编译的2.5版.

says it's version 2.5 compiled with gcc 4.1.2.

有没有办法解决这个问题?

Is there a way around this?

在此先感谢您的帮助

推荐答案

在安装了gcc 4.5.2的系统上,与icc 11.1的行为相同.

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

g++的标头<functional>#ifdef __GXX_EXPERIMENTAL_CXX0X__保护,而使用icc时未定义.

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

在这种设置中,我会考虑切换到 boost :: function ,哪个当然适用于icc.

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

这篇关于std :: function&lt;&gt;和英特尔编译器版本11.1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆