Boost logo

Boost :

From: Fernando Cacciola (fcacciola_at_[hidden])
Date: 2003-03-25 21:57:10


"Joe Gottman" <jgottman_at_[hidden]> escribió en el mensaje
news:b5oblv$rhp$1_at_main.gmane.org...
> It would be nice if boost::optional<T> had operator< defined whenever
> operator< was defined for T. This would allow us to use optional<T> as
the
> key of an associative container. I suggest the following semantics:
>
> bool operator<(optional<T> const &x, optional<T> const &y);
>
> Returns: If y is uninitialized, false. If y is initialized and x is
> uninitialized, true. If x and y are both initialized, (*x < *y).
>
>
>
> This results in a strict weak ordering with uninitialized optional<T>
> objects being sorted first.
>
>
I don't see any problem introducing this with the given semantic as long
as the choice is well documented and a rationale for it is included.

I like the semantic you are proposing, it looks right to me:
'nothing' is always less than 'something' but never less then 'nothing'.

I'll try to find some other background on this sort of ordering to see
other possible semantics (if any), and if there are any subtelties with
this one.

If it still looks OK after that, I'll add it.

Thank you.

Fernando Cacciola


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