Boost logo

Boost Users :

Subject: Re: [Boost-users] A forward iterator need not be default-constructible
From: Dave Abrahams (dave_at_[hidden])
Date: 2011-09-29 15:59:48


on Thu Sep 29 2011, Brian Allison <brian.w.allison-AT-gmail.com> wrote:

> On Thu, Sep 29, 2011 at 9:50 AM, Dave Abrahams <dave_at_[hidden]>
> wrote:
>
>
> I'm sorry - but regarding the statement "every valid iterator is-a
> singular iterator in some sense"... I thought the Standard (2003)
> explicitly stated that singular values for an iterator had all but
> one operation as Undefined Behavior, and the only defined operation
> on an iterator with a singular value was to assign it a non-singular
> value. (24.1, para 5)

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. However, a bidirectional iterator, which you can decrement,
is-a forward iterator. In the same way, a valid iterator is-a singular
iterator.

> Results of most expressions are undefined for singular values; the
> only exception is an assignment of a non-singular value to an iterator
> that holds a singular value. In this case the singular value is
> overwritten the same way as any other value. Dereferenceable values
> are always nonsingular. Doesn't the last sentence make it true that
> "every valid iterator is-a nonsingular iterator"?

(it doesn't, even by logic, since some valid iterators are not
dereferenceable, but that aside...). In the sense I'm using is-a, a
nonsingular iterator is-a singular iterator. How's that for fun logic?
:-)

When the standard says "that's a singular iterator" it's saying you can
only assume it supports two operations. That doesn't mean it can't
support more operations. It's a constraint on the user, not on the
iterator.

> I also thought it was the case that the latest standard defines
> singular to be the same as uninitialized with respect to iterators?

There's still no definition of singular other than the text you cited.

> If that's the case then we cannot call a valid iterator a singular
> iterator in any sense.

In the sense of concept requirements, you can. Any valid iterator
supports a superset of the requirements on singular iterators

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.

-- 
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