Jean-Bernard Jansen
Jean-Bernard Jansen

Reputation: 7872

Why boost::qi rules' attributes must be declared with parenthesis?

I wonder why a qi::rule with an attribute must be declared like this:

qi::rule<string::iterator, std::string(), ascii:space_type>

And not like this

qi::rule<string::iterator, std::string, ascii:space_type>

Which would be more natural to me. I did not even know that the first form would be a valid template instantiation, and I still do not understand how it can be.

Can you explain that trick ?

Upvotes: 2

Views: 99

Answers (1)

Konrad Rudolph
Konrad Rudolph

Reputation: 545618

There’s no trick. The attribute type is not std::string. It’s a function which returns std::string. Because that’s essentially what a Qi rule is (if you squint hard enough): it’s a function which parses a piece of text and returns the parsed value.

These are just one possible attribute type. Other rules accept values, and consequently are functions which have a parameter:

qi::rule<string::iterator, void(std::string), ascii::space_type> end_tag;

This is an example from the Qi documentation.

Upvotes: 4

Related Questions