|
Boost Users : |
Subject: Re: [Boost-users] A forward iterator need not be default-constructible
From: Dave Abrahams (dave_at_[hidden])
Date: 2011-09-30 11:03:15
on Thu Sep 29 2011, Andrew Sutton <asutton.list-AT-gmail.com> wrote:
>> Yes; this is a problem with negative requirements statements. Â Just like
>> you can't decrement a forward iterator, you can't dereference a singular
>> iterator.
>
> The characterization "just like" is a little off. Trying to decrement
> a forward iterator is a conceptual error. Trying to dereference an
> iterator with a singular value is a logic error.
Meh. They're both programming errors. The first one can be caught at
compile time, so they're different in that way, but that doesn't really
affect my point.
> I think we get into trouble when we talk about "valid iterators". I
> don't think there's such really such a thing at all. There may be
> cases where it's valid to decrement an iterator, but not dereference
> it. There may be cases where it's valid to dereference an iterator but
> not decrement. A PTE iterator is well-formed, but both incrementing
> and dereferencing is invalid.
>
>> The point is that the OP claimed every default-constructed iterator is
>> singular. Â The only way that could be true is if you take the term
>> "is-a" in the sense I'm using it here. Â That is, I can easily create an
>> iterator that, when default-constructed, supports a strict superset of
>> the required operations for singular iterators.
>
> Without any strong guarantees about the state of default constructed
> iterators in general, I don't think I'd try to use them in a generic
> algorithm.
No, of course not.
-- Dave Abrahams BoostPro Computing http://www.boostpro.com
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net