I've read this from Cppreference
I'm confusing about what is the difference between:
std::iterator_traits<it>::value_type *
std::iterator_traits<it>::pointer.
I did dive in the text and try to figure out the difference, but the more I read the more I get confusing.
Something tells me they would be the same, but logically they seem not.
So what is the actual difference between them, I would like an example if possible.
value_type
is supposed to have cv-qualifiers (const
and/or volatile
) removed from it, so you could have e.g.:
using value_type = int;
using pointer = const int *;
using reference = const int &;
Also, for the quirky iterators that compute the result of dereferencing on the fly (such as std::vector<bool>::iterator
), reference
(the return type of operator*
) and pointer
(the return type of operator->
) can be proxy classes that merely pretend to be pointers/references.
The exact requirements on those proxy classes appear to be underspecified, but at least reference
is expected to be convertible to value_type
, and pointer
is expected to overload ->
and work with std::to_address
.