Boost logo

Boost Users :

From: John Maddock (john_at_[hidden])
Date: 2008-04-02 11:32:56


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_results<std::string::const_iterator> what;
> boost::regex_search(in, what, expr); // COMPILER ERROR
>
> std::string out;
> boost::spirit::rxstrlit<wchar_t> 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.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net