This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: Regex refactoring
- From: Jonathan Wakely <jwakely dot gcc at gmail dot com>
- To: Tim Shen <timshen91 at gmail dot com>
- Cc: "libstdc++" <libstdc++ at gcc dot gnu dot org>
- Date: Thu, 7 Nov 2013 19:51:08 +0000
- Subject: Re: Regex refactoring
- Authentication-results: sourceware.org; auth=none
- References: <CAH6eHdQJwYAF5Yy6k3AGY_D4+fifjF5g57iZUAOeQ4C4wiazWA at mail dot gmail dot com> <CAPrifD=MTgD2rhjcWiibONcMLk9otpH6Q6vELh2siR4iovyxCQ at mail dot gmail dot com>
On 7 November 2013 18:15, Tim Shen wrote:
> On Thu, Nov 7, 2013 at 11:49 AM, Jonathan Wakely <jwakely.gcc@gmail.com> wrote:
>> The most common instantiations of _Compiler will probably use const
>> char*, std::string::iterator and std::string::const_iterator. It would
>> be good if they could all share code, since they all operate on the
>> same underlying character type, but I don't know if that's possible.
>
> We may read whole input characters into a basic_string<_CharT> then
> use it to initialize _Compiler. Now it can be simplified to:
>
> template<typename _TraitsT>
> class _Compiler
> {
> typedef typename _TraitsT::char_type _CharT;
> ...
> _Compiler(basic_string<_CharT>&& __input_string);
> };
>
> It requires more memory, but I don't think storing a string which
> describing a regex is unacceptable.
I've already added this generator function to compile a regex, to
simplify using __detail::_Compiler
template<typename _FwdIter, typename _TraitsT>
inline std::shared_ptr<_NFA<_TraitsT>>
__compile_nfa(_FwdIter __first, _FwdIter __last, const _TraitsT& __traits,
regex_constants::syntax_option_type __flags)
{
using _Cmplr = _Compiler<_FwdIter, _TraitsT>;
return _Cmplr(__first, __last, __traits, __flags)._M_get_nfa();
}
So I can overload it for std::basic_string<C, T, A> and std::vector<C,
A> iterators to dispatch to the specialization for _Compiler<const
C*>.
That will use the same compiler for most contiguous ranges of type C,
without allocating any memory.