Boost logo

Boost :

From: Fernando Cacciola (fernando_cacciola_at_[hidden])
Date: 2003-09-17 11:05:09


Mat Marcus <mmarcus-boost_at_[hidden]> wrote in message
news:318546735.1063785477_at_aleph.sea.adobe.com...
>
>
> --On Tuesday, September 09, 2003 6:43 PM -0300 Fernando Cacciola
> <fernando_cacciola_at_[hidden]> wrote:
>
> > Hi boosters,
> >
> > Following the suggestions that had been made since Optional's
> > acceptance I've updated the library.
> > I will upload the new version on main CVS tomorrow noon unless
> > someone objects.
>
> Thanks a lot for updating optional! The new version really simplifies
> my optional usage to the point where I'm willing to commit to it in my
> current project.
>
Great!

Thanks for your feedback!

> [snip]
>
> This is rather convenient. It is a little bit less convenient to
> construct the end out_edge_iterator. In my case end is represented by
> an iterator with uninitialized optional state. Here I apparently have
> to write:
>
> out_edge_iterator i(optional<out_edge_iterator>());
> file://longer in its fully qualified glory
>
I think the line above should probably be:

out_edge_iterator i(optional<edge_descriptor>());

> I imagine that it could be useful to have something like a universal
> 'none' object that could be passed to functions expecting optionals. I
> would expect its effect to be the same as passing the anonymously
> constructed optional in the line of code directly above. That is I
> would like to write:
>
> out_edge_iterator end(none); file://optional::none?
>
Well, something like this can be done, though I wonder why couldn't
you just use the default constructor as in:

out_edge_iterator end;

which is the cannonical way to introduce an uninitialized optional<>.

>
> * Safe optional<bool>'s as tri-bools would be quite useful to me. I
> personally would sacrifice the convenience of testing without using
> is_initialized() to gain tri-bools but I don't want to cover old
> territory. Perhaps there's some other way of making optional<bool>'s
> safer to use. What would you think of, say, using enable_if (or better
> disable_if) to disable implicit bool conversion and operator! for when
> T == bool (or when T already is_convertible to bool)?
>
I decided not to treat optional<bool> specially since as Doug just said
there is boost::tribool.
In order to use optional "safely" and uniformly in the presence of
[T=possibly bool] all you have to do is not to use the safe_bool feature.
For instance, you can consistently use the double-bang idiom:

if ( !!opt ) ....

HTH

Fernando Cacciola


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