Boost logo

Boost :

From: Joel de Guzman (joel_at_[hidden])
Date: 2003-10-31 00:26:28


Brian McNamara <lorgon_at_[hidden]> wrote:

[...]

> Why doesn't this:
>
> template <class T>
> class match {
> optional<T> data;
> ...
> public:
> match( T x ) : data(x) {}
> ...
> void value( T y ) {
> *data = y;
> }
> };
>
> do what you want? If T is a reference type, the match's constructor
> puts the reference in the optional, and then calls to value() change the
> value of the referred-to object. If T is a non-reference type, it also
> works, as far as I can tell.
>
> I am clearly missing something, but I don't know what. :)

Oh yes, you can always coerce an API to have it your way <wink ;>

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.

Regards,

-- 
Joel de Guzman
http://www.boost-consulting.com
http://spirit.sf.net

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