Add support for Boost.Ref in match_results::format.

Update docs accordingly.
Fixes #4020.

[SVN r60678]
This commit is contained in:
John Maddock
2010-03-17 18:20:09 +00:00
parent 446604c734
commit 67f5369cae
37 changed files with 391 additions and 255 deletions

View File

@ -468,9 +468,9 @@ private:
// matching flags in use:
match_flag_type m_match_flags;
// how many states we have examined so far:
boost::uintmax_t state_count;
std::ptrdiff_t state_count;
// max number of states to examine before giving up:
boost::uintmax_t max_state_count;
std::ptrdiff_t max_state_count;
// whether we should ignore case or not:
bool icase;
// set to true when (position == last), indicates that we may have a partial match:

View File

@ -98,23 +98,23 @@ void perl_matcher<BidiIterator, Allocator, traits>::estimate_max_state_count(std
//
// Calculate NS^2 first:
//
static const boost::uintmax_t k = 100000;
boost::uintmax_t dist = boost::re_detail::distance(base, last);
static const std::ptrdiff_t k = 100000;
std::ptrdiff_t dist = boost::re_detail::distance(base, last);
if(dist == 0)
dist = 1;
boost::uintmax_t states = re.size();
std::ptrdiff_t states = re.size();
if(states == 0)
states = 1;
states *= states;
if((std::numeric_limits<boost::uintmax_t>::max)() / dist < states)
if((std::numeric_limits<std::ptrdiff_t>::max)() / dist < states)
{
max_state_count = (std::numeric_limits<boost::uintmax_t>::max)() - 2;
max_state_count = (std::min)((std::ptrdiff_t)BOOST_REGEX_MAX_STATE_COUNT, (std::numeric_limits<std::ptrdiff_t>::max)() - 2);
return;
}
states *= dist;
if((std::numeric_limits<boost::uintmax_t>::max)() - k < states)
if((std::numeric_limits<std::ptrdiff_t>::max)() - k < states)
{
max_state_count = (std::numeric_limits<boost::uintmax_t>::max)() - 2;
max_state_count = (std::min)((std::ptrdiff_t)BOOST_REGEX_MAX_STATE_COUNT, (std::numeric_limits<std::ptrdiff_t>::max)() - 2);
return;
}
states += k;
@ -125,15 +125,15 @@ void perl_matcher<BidiIterator, Allocator, traits>::estimate_max_state_count(std
// Now calculate N^2:
//
states = dist;
if((std::numeric_limits<boost::uintmax_t>::max)() / dist < states)
if((std::numeric_limits<std::ptrdiff_t>::max)() / dist < states)
{
max_state_count = (std::numeric_limits<boost::uintmax_t>::max)() - 2;
max_state_count = (std::min)((std::ptrdiff_t)BOOST_REGEX_MAX_STATE_COUNT, (std::numeric_limits<std::ptrdiff_t>::max)() - 2);
return;
}
states *= dist;
if((std::numeric_limits<boost::uintmax_t>::max)() - k < states)
if((std::numeric_limits<std::ptrdiff_t>::max)() - k < states)
{
max_state_count = (std::numeric_limits<boost::uintmax_t>::max)() - 2;
max_state_count = (std::min)((std::ptrdiff_t)BOOST_REGEX_MAX_STATE_COUNT, (std::numeric_limits<std::ptrdiff_t>::max)() - 2);
return;
}
states += k;

View File

@ -34,6 +34,7 @@
#ifndef BOOST_NO_SFINAE
#include <boost/mpl/has_xxx.hpp>
#endif
#include <boost/ref.hpp>
namespace boost{
@ -895,7 +896,7 @@ private:
// F must be a pointer, a function, or a class with a function call operator:
//
BOOST_STATIC_ASSERT((::boost::is_pointer<F>::value || ::boost::is_function<F>::value || ::boost::is_class<F>::value));
static formatter_wrapper<F> f;
static formatter_wrapper<typename unwrap_reference<F>::type> f;
static M m;
static O out;
static boost::regex_constants::match_flag_type flags;
@ -963,7 +964,7 @@ struct format_functor3
template <class OutputIter>
OutputIter operator()(const Match& m, OutputIter i, boost::regex_constants::match_flag_type f)
{
return func(m, i, f);
return unwrap_ref(func)(m, i, f);
}
template <class OutputIter, class Traits>
OutputIter operator()(const Match& m, OutputIter i, boost::regex_constants::match_flag_type f, const Traits&)
@ -983,7 +984,7 @@ struct format_functor2
template <class OutputIter>
OutputIter operator()(const Match& m, OutputIter i, boost::regex_constants::match_flag_type /*f*/)
{
return func(m, i);
return unwrap_ref(func)(m, i);
}
template <class OutputIter, class Traits>
OutputIter operator()(const Match& m, OutputIter i, boost::regex_constants::match_flag_type f, const Traits&)
@ -1020,7 +1021,7 @@ struct format_functor1
template <class OutputIter>
OutputIter operator()(const Match& m, OutputIter i, boost::regex_constants::match_flag_type /*f*/)
{
return do_format_string(func(m), i);
return do_format_string(unwrap_ref(func)(m), i);
}
template <class OutputIter, class Traits>
OutputIter operator()(const Match& m, OutputIter i, boost::regex_constants::match_flag_type f, const Traits&)