Reputation: 76778
I am writing a custom input iterator that adapts an underlying sequence and yields transformed values (I know about boost::transform_iterator
, but this is special).
I am unsure how to define pointer
-type for this iterator. Since the iterator generates values on the fly, reference
is defined as an alias for value_type
(which is allowed for input iterators, reference
must merely be convertible to value_type
). My intuition is that it would still just be value_type *
, and I can't really think of anything else that would make sense.
However, I haven't found any information about the context in which pointer
is expected to be used, and hence don't know what requirements are placed on it, and the documentation of boost::transform_iterator
(which usually offers useful advice) is silent on this issue.
So my question is, is it generally safe to just define pointer
as value_type *
? If not, what are the alternatives?
Upvotes: 2
Views: 119
Reputation: 180424
The only thing I can find in the standard that calls out what they should refers to comes from [iterator.traits]
[...]In addition, the types
iterator_traits<Iterator>::reference iterator_traits<Iterator>::pointer
shall be defined as the iterator’s reference and pointer types, that is, for an iterator object
a
, the same type as the type of*a
anda->
, respectively.
Upvotes: 2