get iterator position after find if

Hi!

I want to get the iterator position after to use find if:

1
2
3
4
5
6
7
8
std::list<Texture*>::iterator result = find_if(
                                          texturelist.begin(),
                                          texturelist.end(),
                                          std::bind2nd<CompareTEX>(CompareTEX(),n_tex));
    if (result != texturelist.end())
    {
        return // position result
    }
Pretty sure you could do return result - texturelist.begin();.
Pretty sure you could do return result - texturelist.begin();.


Pretty sure you can't. list iterators aren't random access iterators.

The smart thing to do would be to return either the iterator or a copy, pointer or reference to the value in the list found. Otherwise, you'll need to iterate through the list to find the position the iterator is pointing to, in which case you could've skipped find and done it directly.
I'm aware that they aren't random access, but I could swear I remember that the - is overloaded to return the difference in position of the two as if they were in an array. Could be wrong but at least try what I said.
Thank you very much.
Topic archived. No new replies allowed.