문제

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 ?

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top