Compile this code :
#include <set>
#include <iostream>
int main(int argc, char * argv[]){
std::set<int> test;
std::cout << (test.end() == std::set<int>::iterator{}) << std::endl;
std::cout << (test.begin() == std::set<int>::iterator{}) << std::endl;
std::cout << (test.begin() == test.end()) << std::endl;
return 0;
}
It outputs (tested on gcc 11.1 and clang 12.0.0):
0
0
1
...However, if I refer to https://timsong-cpp.github.io/cppwp/n4659/iterators#forward.iterators-2
The domain of == for forward iterators is that of iterators over the same underlying sequence. However, value-initialized iterators may be compared and shall compare equal to other value-initialized iterators of the same type. [ Note: Value-initialized iterators behave as if they refer past the end of the same empty sequence. — end note ]
...Then std::set<int>::iterator{}
is what I understand to be "value-initialized" (note that I get the same result using a temporary variable), and I would expect the output to be :
1
1
1
What am I missing ?