Нужно сделать небольшой парсер, работающий со строкой двухбайтных символов, решил заюзать boost::spirit. Если не использовать callbacks и определять грамматику непосредственно в вызове parse, то все работает. Чуть посложнее - уже не компилится.
#include <iostream>
#include <string>
#include <boost/spirit/core.hpp>
#include <boost/function.hpp>
#include <boost/mem_fn.hpp>
#include <boost/bind.hpp>
using namespace std;
using namespace boost;
using namespace boost::spirit;
typedef unsigned short int my_char;
typedef basic_string<my_char> my_string;
struct A {
A () {
typedef boost::function<
void (const my_string::iterator&, const my_string::iterator&)
> cp_t;
cp_t hook_p = bind( mem_fn(&A::hook1), *this, _1, _2);
r = chlit<my_char>('1') >> chlit<my_char>('2')[hook_p];
};
bool operator() (const my_string& ms) {
return parse(ms.begin(), ms.end(), r).full;
}
void hook1 (const my_string::iterator& it1, const my_string::iterator& it2) {
cout << "A::hook1 " << *it1 << endl;
}
rule<> r;
};
int main(void) {
my_char ar[] = {'1', '2', 0};
A()(my_string(ar));
}