The confusion between boost :: bind and boost :: phoenix placeholders

The documentation boost::spirithas this important warning

There are different ways to write the semantic action for Spirit.Qi: the use of simple functions Boost.Bind, Boost.Lambdaor Phoenix. The last three allow you to use special placeholders to control the placement parameter ( _1, _2etc.). Each of these libraries has its own implementation of placeholders, all in different namespaces. You have to not mix placeholders with a library to which they don't belong. and do not use different libraries when writing semantic actions.

Generally for Boost.Binduse ::_1, ::_2etc. (yes, these placeholders are defined in the global namespace).

For Boost.Lambdause placeholders defined in the namespace boost::lambda.

For semantic actions written using Phoenix, use placeholders defined in the namespace boost::spirit. Please note that all existing placeholders are also available from the namespace for your convenience.boost::spirit::qi

( documentation )

Ok so i write this code

template <typename Iterator>
struct ruleset_grammar : qi::grammar<Iterator>
{
    template <typename TokenDef>
    ruleset_grammar(TokenDef const& tok)
      : ruleset_grammar::base_type(start)
    {

        start =  *(  tok.set_name [ boost::bind( &cRuleSet::setName, &theRuleSet, ::_1 ) ]
                  )
              ;
    }

    qi::rule<Iterator> start;
};

Pay attention to use ::_1

However, I still get this compiler error

c:\documents and settings\james\spirit_test.cpp(138) : error C2872: '_1' : ambiguous symbol
        could be 'c:\program files\boost\boost_1_44\boost\spirit\home\support\argument.hpp(124) : const boost::phoenix::actor<Eval> boost::spirit::_1'
        with
        [
            Eval=boost::spirit::argument<0>
        ]
        or       'c:\program files\boost\boost_1_44\boost\bind\placeholders.hpp(43) : boost::arg<I> `anonymous-namespace'::_1'
        with
        [
            I=1
        ]

How to fix this compiler error?

+5
source share
1 answer

, using namespace boost::spirit; - ? , , , . qi:: , namespace qi = boost::spirit::qi.

+7

All Articles