Вопрос

First a bit of background:

I've been writing for a programming assignment, which requires that I parse a text grammar file. In this, I need to replace a placeholder string in a std::list<string> with its corresponding expansion (the string represents a sentence).

I iterate through the list, and erase the matching string with:

itr = ls.erase(itr)

where itr is an iterator and ls is my std::list<string>

I then insert the expansion like

itr = ls.insert(itr, other.begin(), other.end());

where other is a container storing the expansion.

My problem is that the previous line apparently doesn't work. It's supposedly valid c++11 syntax, and I would really like for the iterator to point to the start of what I just inserted. But I get compile errors, as insert apparently returns void.

I've checked with cplusplus.com, and as far as i can see, I don't see anything wrong with how I'm using it. The standard (or at least the one that i can see) states:

iterator insert(const_iterator position, InputIterator first,
    InputIterator last);

I'm compiling using g++ (4.8.1) with the -std=c++11 flag but when I look at stl_list.h in (gcc-directory)/include/c++/4.8.1/bits i see:

void
    insert(iterator __position, _InputIterator __first,_InputIterator __last)

Is this just because gcc hasn't fully implemented the c++11 library? Did they overlook this bit? Doesn't seem hard to do, and all the other insert functions surrounding it return an iterator.

I know I can work around this without too much hassle, but still it would be nice to know what's going on.

Thanks!

edit apparently this answers my question. Sorry to bother you, pity I couldn't find it before.

Это было полезно?

Решение

Libstdc++ just hadn't been updated to return an iterator from that function yet.

That was fixed on the subversion trunk two months ago by this patch: http://gcc.gnu.org/ml/libstdc++/2013-07/msg00000.html

That change was made after the GCC 4.8.1 release, and I don't think the change has been backported to the 4.8 branch anyway.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top