Wanna make a blazingly fast rule? Use BOOST_AUTO! Check it out here. The code defines a named rule using C++0x auto when available and falls back to some template wizardry on older compilers. This code:
BOOST_AUTO(comment, "/*" >> *(char_ - "*/") >> "*/");
defines a rule named comment that can be used just like any parser. If you have a compiler that can handle the new auto keyword, this code is equivalent to:
auto comment = "/*" >> *(char_ - "*/") >> "*/";
Now you can use this `comment` rule to parse:
bool r = parse(iter, end, comment);
Unlike Spirit rules, however, this one is a lot more efficient in terms of speed (no indirection), code size (virtually zero code bloat) and memory usage (the size of the comment rule above is just 8 bytes on MSVC. Just the footprint needed for the static strings, almost. The expression has zero overhead thanks to Boost.Proto). It is very suitable for skip-parsers, for example (if you want to know the actual type, you can use BOOST_TYPEOF). Be aware though that this is only good for non-recursive rules. There is no way to define recursive rules using this. But then, there are lots of rules that really aren’t recursive anyway. For example, we often need to break overly complex rules into manageable parts.So… there ya go… have fun!
(UPDATE: See the comments below. It turns out that MSVC segfaults. Provided below is a workaround)