diff --git a/include/boost/regex/v4/perl_matcher_common.hpp b/include/boost/regex/v4/perl_matcher_common.hpp index af2139b6..54edaa15 100644 --- a/include/boost/regex/v4/perl_matcher_common.hpp +++ b/include/boost/regex/v4/perl_matcher_common.hpp @@ -682,12 +682,32 @@ bool perl_matcher::match_restart_continue() template bool perl_matcher::match_backstep() { - std::ptrdiff_t maxlen = ::boost::re_detail::distance(backstop, position); - if(maxlen < static_cast(pstate)->index) - return false; - std::advance(position, -static_cast(pstate)->index); +#ifdef BOOST_MSVC +#pragma warning(push) +#pragma warning(disable:4127) +#endif + if( ::boost::is_random_access_iterator::value) + { + std::ptrdiff_t maxlen = ::boost::re_detail::distance(backstop, position); + if(maxlen < static_cast(pstate)->index) + return false; + std::advance(position, -static_cast(pstate)->index); + } + else + { + int c = static_cast(pstate)->index; + while(c--) + { + if(position == backstop) + return false; + --position; + } + } pstate = pstate->next.p; return true; +#ifdef BOOST_MSVC +#pragma warning(pop) +#endif } template