Boost logo

Boost :

Subject: Re: [boost] [variant] Please vote for behavior
From: Joel de Guzman (djowel_at_[hidden])
Date: 2013-01-29 07:04:33


On 1/29/13 6:56 PM, Rob Stewart wrote:
> On Jan 28, 2013, at 5:12 PM, Joel de Guzman <djowel_at_[hidden]> wrote:
>
>> On 1/29/13 5:58 AM, Gottlob Frege wrote:
>>>>> How do I know if is it singular valued?
>>>>>>>
>>>>>
>>>>> How do you know if an iterator is singular valued? You can't. Same here.
>>>>>
>>> it == container.end()?
>>>
>>> Or am I confused?
>>
>> Nope. A singular valued iterator may not be compared. A singular valued iterator is
>> not associated with any sequence. E.g default constructed iterator pointing to
>> nowhere.
>
> Singular iterators are default constructed instances that represent a universal end
> iterator. They are not associated with any particular container, but would be returned
> by end(), and can be obtained by advancing a non-end iterator far enough. Thus, Tony's
> snippet is a means to discover a singular instance, as would comparing with a default
> constructed iterator. Is the same now to be possible with recursive_wrapper?

Singular valued iterators cannot be compared (*). The only valid operations are
assignment, destruction and move. There is no way to detect a singular
valued iterator.

(* 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.)

Regards,

-- 
Joel de Guzman
http://www.boostpro.com
http://boost-spirit.com

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk