jeudi 16 avril 2015

why gcc-4.9.2 can't support std::string.insert(iterator, range) to return iterator

According to here, c++11 should support:



template< class InputIt >
iterator insert( const_iterator pos, InputIt first, InputIt last );


But when I try to compile following codes by g++ 4.9.2:



std::string str{ "hello world" }, addition{ "h my" };
auto iter = str.erase(str.begin(), str.begin() + 4);
iter = str.insert(next(iter), addition.begin(), addition.end()); // Error


Error:



error: no match for 'operator=' (operand types are '__gnu_cxx::__normal_iterator<char*, std::basic_string<char> >' and 'void')
iter = str.insert(next(iter), addition.begin(), addition.end());
^


However, Visual Studio 2013 and Clang seem no problem.


Aucun commentaire:

Enregistrer un commentaire