Hide key template instances behind factory functions.

And provide a separate "module library"
Update testing scripts.
This commit is contained in:
jzmaddock
2024-04-18 16:37:12 +01:00
parent fbfdda66fd
commit 2c0058a902
45 changed files with 489 additions and 362 deletions
+27 -11
View File
@@ -650,22 +650,38 @@ private:
// and are designed to provide the strong exception guarantee
// (in the event of a throw, the state of the object remains unchanged).
//
namespace detail
{
template <class charT, class F, class Traits>
std::shared_ptr<BOOST_REGEX_DETAIL_NS::basic_regex_implementation<charT, Traits> > create_implemenation(const charT* p1, const charT* p2, F f, std::shared_ptr<boost::regex_traits_wrapper<Traits> > ptraits)
{
std::shared_ptr<BOOST_REGEX_DETAIL_NS::basic_regex_implementation<charT, Traits> > result;
if (!ptraits.get())
{
result = std::shared_ptr<BOOST_REGEX_DETAIL_NS::basic_regex_implementation<charT, Traits> >(new BOOST_REGEX_DETAIL_NS::basic_regex_implementation<charT, Traits>());
}
else
{
result = std::shared_ptr<BOOST_REGEX_DETAIL_NS::basic_regex_implementation<charT, Traits> >(new BOOST_REGEX_DETAIL_NS::basic_regex_implementation<charT, Traits>(ptraits));
}
result->assign(p1, p2, f);
return result;
}
#ifdef BOOST_REGEX_AS_MODULE
std::shared_ptr<BOOST_REGEX_DETAIL_NS::basic_regex_implementation<char, basic_regex<char>::traits_type> >
create_implemenation(const char* p1, const char* p2, basic_regex<char>::flag_type f, std::shared_ptr<boost::regex_traits_wrapper<basic_regex<char>::traits_type> > ptraits);
std::shared_ptr<BOOST_REGEX_DETAIL_NS::basic_regex_implementation<wchar_t, basic_regex<wchar_t>::traits_type> >
create_implemenation(const wchar_t* p1, const wchar_t* p2, basic_regex<wchar_t>::flag_type f, std::shared_ptr<boost::regex_traits_wrapper<basic_regex<wchar_t>::traits_type> > ptraits);
#endif
}
template <class charT, class traits>
basic_regex<charT, traits>& basic_regex<charT, traits>::do_assign(const charT* p1,
const charT* p2,
flag_type f)
{
std::shared_ptr<BOOST_REGEX_DETAIL_NS::basic_regex_implementation<charT, traits> > temp;
if(!m_pimpl.get())
{
temp = std::shared_ptr<BOOST_REGEX_DETAIL_NS::basic_regex_implementation<charT, traits> >(new BOOST_REGEX_DETAIL_NS::basic_regex_implementation<charT, traits>());
}
else
{
temp = std::shared_ptr<BOOST_REGEX_DETAIL_NS::basic_regex_implementation<charT, traits> >(new BOOST_REGEX_DETAIL_NS::basic_regex_implementation<charT, traits>(m_pimpl->m_ptraits));
}
temp->assign(p1, p2, f);
temp.swap(m_pimpl);
m_pimpl = detail::create_implemenation(p1, p2, f, m_pimpl.get() ? m_pimpl->m_ptraits : std::shared_ptr<boost::regex_traits_wrapper<traits> >());
return *this;
}
+27
View File
@@ -558,6 +558,33 @@ private:
#endif
};
template <class Matcher>
inline bool factory_match(Matcher& m)
{
return m.match();
}
template <class Matcher>
inline bool factory_find(Matcher& m)
{
return m.find();
}
#ifdef BOOST_REGEX_AS_MODULE
bool factory_match(perl_matcher<const char*, match_results<const char*>::allocator_type, regex::traits_type>& m);
bool factory_match(perl_matcher<const wchar_t*, match_results<const wchar_t*>::allocator_type, wregex::traits_type>& m);
bool factory_match(perl_matcher<std::string::const_iterator, match_results<std::string::const_iterator>::allocator_type, regex::traits_type>& m);
bool factory_match(perl_matcher<std::wstring::const_iterator, match_results<std::wstring::const_iterator>::allocator_type, wregex::traits_type>& m);
bool factory_match(perl_matcher<std::string::iterator, match_results<std::string::iterator>::allocator_type, regex::traits_type>& m);
bool factory_match(perl_matcher<std::wstring::iterator, match_results<std::wstring::iterator>::allocator_type, wregex::traits_type>& m);
bool factory_find(perl_matcher<const char*, match_results<const char*>::allocator_type, regex::traits_type>& m);
bool factory_find(perl_matcher<const wchar_t*, match_results<const wchar_t*>::allocator_type, wregex::traits_type>& m);
bool factory_find(perl_matcher<std::string::const_iterator, match_results<std::string::const_iterator>::allocator_type, regex::traits_type>& m);
bool factory_find(perl_matcher<std::wstring::const_iterator, match_results<std::wstring::const_iterator>::allocator_type, wregex::traits_type>& m);
bool factory_find(perl_matcher<std::string::iterator, match_results<std::string::iterator>::allocator_type, regex::traits_type>& m);
bool factory_find(perl_matcher<std::wstring::iterator, match_results<std::wstring::iterator>::allocator_type, wregex::traits_type>& m);
#endif
} // namespace BOOST_REGEX_DETAIL_NS
#ifdef BOOST_REGEX_MSVC
+2 -2
View File
@@ -41,7 +41,7 @@ inline unsigned int regex_grep(Predicate foo,
match_results<BidiIterator> m;
BOOST_REGEX_DETAIL_NS::perl_matcher<BidiIterator, match_allocator_type, traits> matcher(first, last, m, e, flags, first);
unsigned int count = 0;
while(matcher.find())
while(BOOST_REGEX_DETAIL_NS::factory_find(matcher))
{
++count;
if(0 == foo(m))
@@ -56,7 +56,7 @@ inline unsigned int regex_grep(Predicate foo,
// a non-NULL one at the same position:
match_results<BidiIterator, match_allocator_type> m2(m);
matcher.setf(match_not_null | match_continuous);
if(matcher.find())
if(BOOST_REGEX_DETAIL_NS::factory_find(matcher))
{
++count;
if(0 == foo(m))
+1 -1
View File
@@ -36,7 +36,7 @@ bool regex_match(BidiIterator first, BidiIterator last,
match_flag_type flags = match_default)
{
BOOST_REGEX_DETAIL_NS::perl_matcher<BidiIterator, Allocator, traits> matcher(first, last, m, e, flags, first);
return matcher.match();
return BOOST_REGEX_DETAIL_NS::factory_match(matcher);
}
BOOST_REGEX_MODULE_EXPORT template <class iterator, class charT, class traits>
bool regex_match(iterator first, iterator last,
+2 -2
View File
@@ -42,7 +42,7 @@ bool regex_search(BidiIterator first, BidiIterator last,
return false;
BOOST_REGEX_DETAIL_NS::perl_matcher<BidiIterator, Allocator, traits> matcher(first, last, m, e, flags, base);
return matcher.find();
return BOOST_REGEX_DETAIL_NS::factory_find(matcher);
}
//
@@ -77,7 +77,7 @@ bool regex_search(BidiIterator first, BidiIterator last,
match_results<BidiIterator> m;
typedef typename match_results<BidiIterator>::allocator_type match_alloc_type;
BOOST_REGEX_DETAIL_NS::perl_matcher<BidiIterator, match_alloc_type, traits> matcher(first, last, m, e, flags | regex_constants::match_any, first);
return matcher.find();
return BOOST_REGEX_DETAIL_NS::factory_find(matcher);
}
BOOST_REGEX_MODULE_EXPORT template <class charT, class traits>