I cannot seem to find any standard algorithms that would demonstrate the requirement for default-constructing a ForwardIterator.
Is there any actual reason for it, or am I safe to ignore it?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It is there to ease the use of these kind of iterators, for both the standard algorithms and client users.
For example (remember that
RandomAccessIteratoris a subtype ofForwardIterator):If they were not default constructible you would need to assign them to
firstorlastjust for it to compile.You do not need it to be set to a default value. Any use of such uninitialized iterator is undefined. Not that is would not be wise to add some check, particularly in debug builds.
And no, you should not throw in the default constructor. It would be technically conformant, but many algorithms will fail unexpectedly.