Search code examples
boost-spirit

Compile error due boost spirit placeholder limit not more than 10


I'm getting a

"qi::_10 is not a member of qi "

error when compiling grammar for qi.

Is there a way to increase the maximum allowed?


Solution

  • Off-hand: Avoid the code smell of large numbers of function arguments.

    That said,

    Before:

    Live On Coliru

    #define SPIRIT_ARGUMENTS_LIMIT 10
    #include <boost/spirit/include/qi.hpp>
    
    int main() {
        auto& _10 = boost::spirit::labels::_10;
    }
    

    After:

    Live On Coliru

    #define SPIRIT_ARGUMENTS_LIMIT 11
    #include <boost/spirit/include/qi.hpp>
    
    int main() {
        auto& _10 = boost::spirit::labels::_10;
    }
    

    BONUS

    You can cheat and hard-code your own placeholders:

    boost::phoenix::actor<boost::spirit::argument<998> > const _999;
    

    Note the discrepancy between 998 and _999; this is an implementation detail that is not documented, so it's probably better not rely on it, or at least have tests.