Search code examples
c++c++11move-semanticsicc

ICC not recognizing stream move semantics


I have the following piece of code that works with -std=c++0x under recent GCC (9.3.1) and clang (7.0.1). It does not work under older GCC (4.8.5), but that's OK. I am now trying to get it to work under 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;
}

My understanding is that this works because std::istringstream has an implicit move constructor, so there's no copying happening here. However ICC does not seem to have such a move constructor.

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

How can I work around this?


Solution

  • Thanks to @AlanBirtles for pointing me in the right direction. The issue was that ICC does not ship its own version of the standard library, it just uses the headers that GCC ships. This will default to your system GCC (which I already knew did not work). The solution is to use the -cxxlib=/path/to/new/gcc/usr flag which will use the standard library headers from the newer GCC version.