|
Boost : |
Subject: Re: [boost] [log] Comments
From: Andrey Semashev (andrey.semashev_at_[hidden])
Date: 2010-03-16 11:34:32
On 03/16/2010 02:02 AM, Steven Watanabe wrote:
>
> Andrey Semashev wrote:
>> On 03/15/2010 11:22 PM, Vladimir Prus wrote:
>>> The corresponding code using lambda would be, presumably:
>>>
>>> flt::attr< ...>("System") == m_sys
>>>
>>> Would it be possible to make the following work in the first case:
>>>
>>> if (attrs["System"] != m_sys)
>>> return false;
>>
>> It doesn't specify the type of the value.
>
> You can deduce the type from the type of m_sys.
Ah, right. Clever trick.
>>> ? Or, if changing type/behaviour of operator[] is undesirable, what
>>> about
>>>
>>> if (attrs->get_nothrow("System") != m_sys)
>>> return false;
>>
>> That should be:
>>
>> if (attrs.get_nothrow< System >("System") != m_sys)
>> return false;
>>
>> Yes, it could be done. But as stated elsewhere in the discussion, this
>> would require System to be copyable (which might be fine in this
>> case). And it doesn't really differ from:
>>
>> bool result = false;
>> extract< System >("System", attrs, var(result) = _1 != m_sys);
>> return result;
>
> except that the former is more readable.
>
>> but with extract it doesn't have the copyability restriction.
>
> Why does this require System to be copyable? Can't you
> return a reference?
Returning a reference looks like an unsafe interface design to me.
Remember that double dispatch is taken place here, so that the caller's
visitor is invoked by the attribute value, with a reference to the
actual value. In order to return this reference from get_nothrow, it has
to be saved by the visitor and restored after returning from the
attribute value dispatch method. At this point the reference may
potentially be broken.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk