Boost logo

Boost :

From: Fernando Cacciola (fernando_cacciola_at_[hidden])
Date: 2005-10-18 08:50:42

Hamish Mackenzie wrote:
> On Mon, 2005-10-17 at 16:09 -0300, Fernando Cacciola wrote:
>> But that's not because optional<> is a pointer, is becasue both
>> optional<> and pointer's are somehing else: OptionalPointees.
> Let me say first I don't use optional references (yet anyway) and I am
> quite happy with your explanation of the need to rebind on assignment.

> I am, however, still not convinced that OptionalPointees is
> justification for using the interface of a pointer.


> I still sometimes
> think of optional as a vector with a maximum size of one, but I now
> think it would be a bad idea to copy member names from std::vector, as
> it is likely to cause confusion when using optional< vector< T > >.
> For
> the same reason I think optional< bool > is very problematic with the
> current interface (see my earlier post in this thread).

The problems with optional<bool> are totally unrelated to the choice of
operators * and ->.
It is the safe_bool() operator _alone_ which causes that.
We can of course discuss whether such operator is worth it given the
ambiguity it creates with optional<bool>. That was discussed at length at
the time optional<> was reviewed (with me initially opposing safe_bool()),
in the end, we agreed that it had more benefits than this simple

> Could the unifying concept OptionalPointee be implemented as free
> functions?

Of course.

Notice that there are alternatives for safe_bool() that doesn't require
dropping * and ->.
These alternatives fix the problem with optional<bool>.
One example is to simply provide operator !, used like this:

if ( !!opt )

(this is what my initial boost submission did)

Fernando Cacciola

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