std :: regex_match与另一个分配器 [英] std::regex_match with another Allocator

查看:98
本文介绍了std :: regex_match与另一个分配器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对如何在自己的Memory STL分配器中使用 regex_match 模板感到困惑.

I'm stuck how to use the regex_match template with my own Memory STL Allocator.

这是我的代码:

FaF::smatch stringResults;
std::regex expression( "expression" );
std::regex_match( FaF::string-variable, stringResults, expression );

对于 std :: match std :: string ,我成功了,因此在上面的示例中使用了它:

For std::match and std::string I was successful and therefore I use it in the above example:

namespace FaF
{
    using smatch = std::match_results<std::string::const_iterator,
                                          Allocator<std::string::const_iterator>>;
    using string = std::basic_string<char, std::char_traits<char>, Allocator<char>>;
}

我的分配器有一些日志记录,我可以清楚地看到,是的,确实可以使用.当我正确理解 cppreference 时,然后 std :: regex 没有分配器,但是 std :: regex_match 确实有.

My Allocator has some logging and I can see clearly, yes it is indeed used. When I understand the cppreference correctly, then std::regex does not have an allocator, but std::regex_match does.

我的问题:

如何根据上述类型在 namespace FaF 中定义一个基于 std :: regex_match 的附加模板,该模板正在使用我的STL内存分配器?

How to define - according the above types - in the namespace FaF an additional template based on std::regex_match which is using my STL Memory Allocator?

推荐答案

学习后,在 regex.h std :: regex_match >

After studying the definition of std::regex_match in regex.h

  template<typename _Ch_traits, typename _Ch_alloc,
       typename _Alloc, typename _Ch_type, typename _Rx_traits>
    inline bool
    regex_match(const basic_string<_Ch_type, _Ch_traits, _Ch_alloc>& __s,
        match_results<typename basic_string<_Ch_type,
        _Ch_traits, _Ch_alloc>::const_iterator, _Alloc>& __m,
        const basic_regex<_Ch_type, _Rx_traits>& __re,
        regex_constants::match_flag_type __flags
        = regex_constants::match_default)
    { return regex_match(__s.begin(), __s.end(), __m, __re, __flags); }

我了解并意识到,我自己的 FaF :: string 定义和定义我自己的 FaF :: smatch [问题有定义]就足够了,因为<在那里使用code> _Alloc .

I understood and realized that my own definition of FaF::string and defining my own FaF::smatch [definitions are in the question] is enough because the _Alloc is used there.

我的代码是这样的:

void getBarDataEntryFromMySql( const FaF::string & memcacheBarDataEntry )
{
    const char expressionString [] = "expression";

    FaF::smatch stringResults;
    std::regex expression( expressionString );
    std::regex_match( memcacheBarDataEntry, stringResults, expression );

    ...
}

,并且有效.我当时觉得太复杂了...

and it works. I was thinking too complicated...

这篇关于std :: regex_match与另一个分配器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆