What does 'bound to the same object' mean for C++ iterators?

91 views Asked by At

I found this article 'How to write an STL compatible container' https://medium.com/p/fc5b994462c6

The author, Vanand Gasparyan, had issues around one of the requirements of an iterator that he refers to in his article [ If a and b are both dereferenceable, then a == b if and only if *a and *b are bound to the same object. ]. He mentions this in terms of converting a forward-iterator to a reverse-iterator.

I read the C++2x standard and found the requirement mentioned by Vanand in section 25.3.5.5, but have not yet found a 'definition' of the phrase 'bound to the same object'.

===

I want to reconstruct the key from traversal of the TRIE, and to set the value returned from find() etc to be using value_type = std::pair<const key_type, & mapped_type>; rather than using value_type = std::pair<const key_type, mapped_type>;

This seems reasonable, to me, assuming that the object referred to in the requirements is the mapped_type object.

1

There are 1 answers

0
HolyBlackCat On

For forward iterators1, the standard requires * to return a reference. Thus "bound to the same object" simply means &a == &b (or rather std::addressof(a) == std::addressof(b)).


1 I mean Cpp17ForwardIterator named requirement, not C++20 std::forward_iterator.