|
Boost : |
Subject: Re: [boost] Rave for proposed Boost.Local (functions)
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2011-02-06 23:45:21
AMDG
On 2/6/2011 8:09 PM, Jeffrey Lee Hellrung, Jr. wrote:
> On 2/6/2011 5:46 PM, Lorenzo Caminiti wrote:
>> On Sun, Feb 6, 2011 at 3:23 PM, Jeffrey Lee Hellrung, Jr.
>> <jhellrung_at_[hidden]> wrote:
>>> On 2/6/2011 9:17 AM, Lorenzo Caminiti wrote:
>>> [...]
>>>>
>>>> boost::scope_exit::aux::declared< boost::scope_exit::aux::resolve<
>>>> sizeof(boost_local_auxXargs)>::cmp1<0>::cmp2>
>>>> boost_local_auxXargs;
>>>
>>> Shouldn't the name boost_local_auxXargs have some kind of line number or
>>> counter or function name pasted into it to prevent name collision of
>>> multiple BOOST_LOCAL_FUNCTION declarations in the same scope?
>>
>> No, this has to be a global extern variable declared as:
>>
>> extern boost::scope_exit::aux::undeclared boost_local_auxXargs;
>>
>> in one of Boost.Local headers. It's a trick carried over 100% from
>> Boost.ScopeExit (as I understand it, this is because only global or
>> static variables can be used from within a nested block
>> http://lists.boost.org/Archives/boost/2006/11/113658.php).
>
> Ugh, okay ;) Will read the link.
>
That link isn't very relevant. This code is one
of the most awful hacks around. Basically, it
takes advantage of the template argument list/
comparison operator ambiguity to declare a variable
iff it hasn't already been declared in that scope.
The second occurrence is parsed as
(boost::scope_exit::aux::declared< (boost::scope_exit::aux::resolve<
sizeof(boost_local_auxXargs)>::cmp1
< 0)>::cmp2 >
boost_local_auxXargs);
which is a no-op.
In Christ,
Steven Watanabe
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk