|
Boost Users : |
Subject: Re: [Boost-users] [Spirit] qi::parse at translation unit global scope?
From: Olaf Meeuwissen (olaf.meeuwissen_at_[hidden])
Date: 2012-02-01 18:28:12
Vitaly Budovski <vbudovski+news_at_[hidden]> writes:
> On 1 February 2012 20:33, Olaf Meeuwissen <olaf.meeuwissen_at_[hidden]> wrote:
>> I noticed this when I played around with wrapping qi::parse() in a
>> parse() function that does some things before and after qi::parse().
>>
>> My code had been calling qi::parse(), with the `qi::` namespace prefix,
>> everywhere so I removed from a few calls and compiled before adding a
>> parse() declaration. Â Lo and behold, compilation unexpectedly succeeded.
>> I've reduced the behaviour in a minimalistic sample program (attached).
>>
>> I expect their to be *no* parse() function within the scope of main().
>> Can anyone clarify why the compiler has no trouble finding one and which
>> one it finds?
>>
>> Adding a global scope operator to the call, i.e. saying ::parse(), does
>> result in the expected compile error.
>
> The compiler uses Argument Dependent Lookup (ADL) to determine which
> function to call. One of the parameters is qi::rule, so the compiler
> looks in that namespace for a matching parse function.
Thanks. For anyone who needs a bit more info on ADL, here's a pointer
http://en.wikipedia.org/wiki/Argument_dependent_lookup
Based on that, the compiler fails to find a matching class member
function (doh, we're in main() ...) for the unqualified call to parse()
and then starts looking in qi which is an alias for boost::spirit::qi
and finds the parse() free function in that namespace. I see.
Hope this helps,
-- Olaf Meeuwissen, LPIC-2 FLOSS Engineer -- AVASYS CORPORATION FSF Associate Member #1962 Help support software freedom http://www.fsf.org/jf?referrer=1962
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net