Boost logo

Boost :

From: William E. Kempf (wekempf_at_[hidden])
Date: 2002-12-11 16:21:23


David Abrahams said:
> "William E. Kempf" <wekempf_at_[hidden]> writes:
>
>> Tanton Gibbs said:
>>>> optional<int> opt0(1);
>>>> optional<int> opt1(2);
>>>> (opt0 == opt1) // true
>>>
>>> I would not have any problem with this returning false. In the
>>> normal ptr world:
>>> char c, d;
>>> char* p, *q;
>>> p = &c;
>>> q = &d;
>>>
>>> if( p == q ) // false
>>>
>>> People expect it to compare memory locations, not initialization
>>> status. Therefore, I would have no problem with operator== returning
>>> true only if both
>>> were uninitialized.
>>
>> I agree with this. The optional<> concept takes some type and extends
>> it's possible values to include a new "uninitialized" value. It seems
>> wholly logical to me for this:
>>
>> optional<int> a();
>> optional<int> b();
>> optional<int> c(1);
>> optional<int> d(2);
>> optional<int> e(2);
>>
>> assert(a == b); // both uninitialized
>> assert(a != c); // one uninitialized
>> assert(c != d); // both initialized to different values
>> assert(d == 3); // both initialized to same value
> "2?"----------^

Actually, "e"... the keys were close enough together for my small fingers
to smash the wrong one ;).

William E. Kempf


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