This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Eliminate _Specialized* and abstract classes in regex


I found that it's hard when I'm implementing back-reference.

I need to use a traits class to compare two characters with template
type, one of which is in a container. So I want this(not real code but
simpler):

template<typename _CharT, typename _Traits, typename _Alloc>
struct _BackRefMatcher
{
    bool _M_equal(_CharT, _CharT); // use _M_traits

    bool _M_all_match(_CharT __ch, _ContainerT<_CharT, _Alloc> __c)
    {
        for (auto __iter : __c)
            if (!_M_equal(__ch, __iter)
                return false;
        return true;
    }

    _Traits _M_traits;
};

/* Somewhere
_BackRefMatcher __matcher;
...
__matcher._M_all_match();
*/


To be more detailed, the _ContainerT is std::match_results; However in
current code base, match_results cannot be accessed easily; instead,
we shall mutate it using an abstract base class, __detail::_Results,
which is implemented by _SpecializedResults(and of course, it's a
friend of std::match_results).

_Results is not templated, so it's impossible to iterate it and get
_CharT characters out. In other situations, we can solve this problem
by calling some method of _Results and do what we want in this method.

However in above example, I can't find a way to pass _M_equal(ideally,
as a closure!) to the _Results because it's not templated.

I'm not an C++ or OOP expert, I may add more abstract classes to solve
this problem with some hard work; but is it a better idea to eliminate
all abstract classes, and use templated classes like the example
above?

Thanks!


-- 
Tim Shen


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]