Reverse Iterator errors with Android Native C++

When building for Android NDK, I am getting errors when compiling a cpp file with reverse iterators in them.

1
2
3
4
5
6
7
8
9
10
11

list<int> Foo;

...
Foo.push_back(Index);
...

for(list<int>::const_reverse_iterator it = Foo.rbegin(); it != Foo.rend(); it++){
 ...
}


Here is the error message:

1
2
3
4
5

error: invalid operands to binary expression ('list<int>::const_reverse_iterator' (aka
      'reverse_iterator<_List_iterator<int, _Const_traits<int> > >') and 'reverse_iterator' (aka
      'reverse_iterator<_List_iterator<int, _Nonconst_traits<int> > >'))


Any ideas?
Last edited on
crbegin() and crend()
thanks @lastchance, but I am getting a no member named crbegin() and crend() error.

If I just use reverse_iterator, it works on NDK. any difference or impact?
Last edited on
ruzip wrote:
If I just use reverse_iterator, it works on NDK. any difference or impact?


reverse_iterator without the const should be fine unless you are obsessed with ensuring nothing gets changed in the loop.

crbegin came in with c++11. I assume your compiler is up to date?
http://www.cplusplus.com/reference/list/list/crbegin/
Last edited on
With a conforming compiler/library that supports at least C++11, the code is fine as it is.
http://coliru.stacked-crooked.com/a/688844ec6206cbdf

You may need to update the compiler to a more modern version and/or explicitly instruct it to conform to C++11.
for example, with: g++ -std=c++11 -pedantic-errors
@againtry

I compiled this in MinGW 4.8 gcc and it works fine, different results with NDK g++.

@lastchance

reverse_iterator without the const should be fine unless you are obsessed with ensuring nothing gets changed in the loop.


I see and will just check if it affects the results.

I am using Android 21 and have added the NDK_TOOLCHAIN_VERSION := 4.9 and APP_CPPFLAGS += -std=c++11 on my Android.mk file, but still getting these errors.
Last edited on
With a conforming compiler/library that supports at least C++11, the code is fine as it is.
http://coliru.stacked-crooked.com/a/688844ec6206cbdf

You may need to update the compiler to a more modern version and/or explicitly instruct it to conform to C++11.
for example, with: g++ -std=c++11 -pedantic-errors


I see and thanks for the confirmation. I have added the c++11 flags but still getting errors.

Last edited on
By checking again the guide here, I just changed stlport_static which is set and default to the project library that I am using to gnustl_static and it worked!

APP_STL := gnustl_static

I also tested it without the 4.9 toolchain version and c++11 flags and it also works.

https://www.drdobbs.com/cpp/accessing-c11-features-of-the-android-nd/240168385

I am now thinking of whether to just ignore and use reverse_iterator instead if it does not make any difference or go for gnustl_static which is now untested to work with my project.

Edit: c++static also works and now I am concerned or puzzled why stlport which is widely used doesn't have it. btw, I am new to this stl android stuff.

and so I found out that stlport is BSD vs GPL3 gnustl.. ok that's why.

Thanks guys for all the help and response.
Last edited on
Topic archived. No new replies allowed.