Reputation: 210427
Does an input iterator have to have a const
dereferencing operator, or does a mere non-const version satisfy its requirements as well?
Upvotes: 0
Views: 525
Reputation: 264381
No.
For example the "Input Iterator".
This is usually read from a stream. De-referencing it reads a value and changes the underlying stream. Using the de-reference operator is not valid again until you use the ++ operator.
http://www.sgi.com/tech/stl/InputIterator.html
Are you asking can?
Sure it can you can do anything in C++.
Or are you asking should?
Now it depends on which bit is const:
- Do you mean should de-reference by a const method?.
- Or do you mean the reference returned (to the object) is const?
Personally I think the answer to both these questions is no.
I think am pretty sure that this does not violate the constraints of the input iterator (which are defined in the link above).
BUT I think it is unwise to return a non cost reference to an object that if mutated by the user will not mutate the underlying object in what the stream is referring too (this violates the principle of least surprise).
Overall I think you need to clarify your question.
If you explain the context in more detail and ask weather a particular signature violates constraints then I may be able to give a better answer. Currently the question is just overly vague thus I can only express the answer in an overly general fashion.
Upvotes: 1