Question

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 ?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top