
Boris wrote:
Can anyone tell me why Boost.Spirit (which reuses Boost.Regex for regular expressions) works while the code below where Boost.Regex is used directly can not be compiled?
std::string in = "test";
boost::wregex expr(L"test"); boost::match_resultsstd::string::const_iterator what; boost::regex_search(in, what, expr); // COMPILER ERROR
std::string out; boost::spirit::rxstrlit
expr2(L"test"); boost::spirit::parse(in.c_str(), expr2[boost::spirit::assign_a(out)]); The basic problem is of course that the regular expressions are based on wchar_t while the input string is based on char. Thus I'm not so much surprised why Boost.Regex does not work.
Right, by design that doesn't compile.
I'm much more surprised though that my compiler (VC++ 2008) doesn't report an error with the code above which uses Boost.Spirit.
I don't know why the code using Boost.Spirit compiles (is this implementation-dependent or guaranteed behavior)? It would make using regular expressions in templates much easier though as regular expressions don't seem to depend on the Char type of strings (assuming this is a feature I can rely on)?
Well that depends on the regular expression, something like "[\x{0370}-\x{03ff}]+" most certainly does depend upon the character type! ;-) John.