Boost logo

Boost :

From: Brian McNamara (lorgon_at_[hidden])
Date: 2003-10-31 11:52:48


On Fri, Oct 31, 2003 at 01:26:28PM +0800, Joel de Guzman wrote:
> Oh yes, you can always coerce an API to have it your way <wink ;>

So, if I understand your recent message, aside from nits, this does
work. So...

> Give me a practical example that shows why your preferred semantics
> is better than the tried and true semantics of true C++ references.
> I've given mine, following the premise that the match<T> is conceptually
> an optional<T>. IMO, the match<T> perfectly fits the description of an
> optional<T>. Hence, a use case.

Here is my use-case:

Inside Spirit, the match<T> class may or may not contain a value of
type T depending on whether or not the parse fails. Thus we use an
optional<T> in its implementation. Thanks to the clever current design
of optional, this enables match<T> to be implemented with this nice
generic code:

> > template <class T>
> > class match {
> > optional<T> data;
> > ...
> > public:
> > match( T x ) : data(x) {}
> > ...
> > void value( T y ) {
> > *data = y;
> > }
> > };

Hurray for the current semantics of optional!

I know that sounds sarcastic, but seriously: is there anything wrong
with this use-case? As far as I can tell, optional already works fine
for your needs. (If it ain't broke, ...)

-- 
-Brian McNamara (lorgon_at_[hidden])

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