Boost logo

Boost :

From: Joel de Guzman (joel_at_[hidden])
Date: 2003-10-31 04:20:50


Brian McNamara <lorgon_at_[hidden]> wrote:
> On Fri, Oct 31, 2003 at 01:26:28PM +0800, Joel de Guzman wrote:
>> 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 ;>
>
> So does my code above work for you? If not, can you show me the problem?
> I'm still confused what the issue is here.

Here's one problem with your solution:

    match<int&> m(i);
    m = 3; // compile error

Cheers,

-- 
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