Boost logo

Boost Users :

Subject: Re: [Boost-users] A forward iterator need not be default-constructible
From: Roman Perepelitsa (roman.perepelitsa_at_[hidden])
Date: 2011-09-29 09:31:34


2011/9/29 Krzysztof Czainski <1czajnik_at_[hidden]>

> I disagree. I think requiring default-constructed iterstors to be singular
> would make plain old pointers not meet the requirements. For example:
> vector<int>::iterator a; // (1)
> vector<int>::iterator b = a; // (2)
>
> Correct me if I'm wrong: line (1) is legal, and the value of a may be
> singular, or a may be uninitialized. Therefore line (2) is undefined
> behavior.
>
> However, if we change the example a bit to make a value-initialized:
> vector<int>::iterator a = vector<int>::iterator(); // (3)
> vector<int>::iterator b = a; // (4)
>

In C++11 singular means what you call uninitialized.

iterator.requirements.general p5

 Iterators can also have singular values that are not associated with any
sequence. [ Example:
After the declaration of an uninitialized pointer x (as with int* x;), x
must always be assumed to have a
singular value of a pointer. — end example ] Results of most expressions are
undefined for singular values;
   the only exceptions are destroying an iterator that holds a singular
value, the assignment of a non-singular
  value to an iterator that holds a singular value, and, for iterators that
satisfy the DefaultConstructible
 requirements, using a value-initialized iterator as the source of a copy or
move operation. [ Note: This
guarantee is not offered for default initialization, although the
distinction only matters for types with trivial
 default constructors such as pointers or aggregates holding pointers. — end
note ] In these cases the singular
  value is overwritten the same way as any other value. Dereferenceable
values are always non-singular.

Roman Perepelitsa.



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