Re: printing in C++
Rui Maciel <rui.maciel@gmail.com> wrote in
news:ki4ubb$mjv$1@dont-email.me:
C?C? Tiib wrote:
Iterator on common case is not "shoving pointer under hood" but
"erasing all the broken interface" of pointer
This is obviously false, because even standard C++ iterators were
defined with the express purpose of mimicking C++ pointers.
No, the reason for introducing iterators was not to mimick C++ pointers
(that would be rather pointless, wouldn't it?). Here is the proof that
iterators "fail" to mimick C++ pointers in several ways:
#include <set>
int main() {
int* p = NULL; // OK
std::set<int>::iterator q = NULL; // Error
}
test.cpp(4): error C2440: 'initializing' : cannot convert from 'int' to
'std::_Tree_const_iterator<_Mytree>'
---------------------------------
#include <set>
int f(int* p) {
return *(p+1); // OK
}
int g(std::set<int>::iterator p) {
return *(p+1); // Error
}
test.cpp(7): error C2784: 'std::_String_iterator<_Elem,_Traits,_Alloc>
std::operator +(_String_iterator<_Elem,_Traits,
_Alloc>::difference_type,std::_String_iterator<_Elem,_Traits,_Alloc>)' :
could not deduce template argument for 'std::_String_iterator<_Elem,
_Traits,_Alloc>' from 'int'