Boost logo

Boost :

From: Tanton Gibbs (thgibbs_at_[hidden])
Date: 2002-12-11 16:17:30

> 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
> However, not all types wrapped in optional<T> will be comparable... so,
> I'm not adverse to leaving comparison operators out just to simplify the
> interface. I just don't agree with the current rationale.
> William E. Kempf

I assume you mean
assert( d == optional<>(2) );

However, I still think this is incorrect....consider
char c = 'c', d = 'c';
char *p, *q;
p = &c; q = &d;
assert( p != q );

It doesn't matter what their values is the addresses of those
values that matter.

Therefore, I think that, if optional<> is a smart ptr,
assert( d != optional<>(2) );
must be true. Only if two elements are uninitialized should they be
equal...otherwise, we must compare their "pointer" values, not their element


Boost list run by bdawes at, gregod at, cpdaniel at, john at