问题描述
我有以下代码可在最近的 GCC (9.3.1) 和 clang (7.0.1) 下与 -std=c++0x
一起使用。它在较旧的 GCC (4.8.5) 下不起作用,但没关系。我现在正试图让它在 ICC (19.0.5.281 20190815) 下工作。
inline std::istringstream setup_extraction_stream(const std::string buffer,const std::string searchkey)
{
const size_t offset = buffer.find(searchkey);
std::istringstream iss(buffer);
if (offset != std::string::npos)
{
iss.seekg(offset);
}
return iss;
}
我的理解是,这是可行的,因为 std::istringstream
有一个隐式移动构造函数,所以这里没有发生复制。然而ICC似乎没有这样的移动构造函数。
error: function "std::basic_istringstream<_CharT,_Traits,_Alloc>::basic_istringstream(const std::basic_istringstream<char,std::char_traits<char>,std::allocator<char>> &) [with _CharT=char,_Traits=std::char_traits<char>,_Alloc=std::allocator<char>]" (declared implicitly) cannot be referenced -- it is a deleted function
return iss;
^
我该如何解决这个问题?
解决方法
感谢@AlanBirtles 为我指明了正确的方向。问题是 ICC 不提供自己版本的标准库,它只使用 GCC 提供的头文件。这将默认为您的系统 GCC(我已经知道它不起作用)。解决方案是使用 -cxxlib=/path/to/new/gcc/usr
标志,该标志将使用来自较新 GCC 版本的标准库标头。