C++ 参考手册

位置:首页 > C++ 参考手册 >C++ 标准库头文件 > 标准库头文件 <regex>

此头文件是正则表达式库的一部分。

命名空间 std::regex_constants

类型
定义于命名空间 std::regex_constants
控制正则表达式行为的通用选项
(typedef)
特定于匹配的选项
(typedef)
描述不同类型的匹配错误
(typedef)
本节未完成
原因:列出所有常量


正则表达式对象
(类模板)
(C++11)
标识子表达式所匹配的字符序列
(类模板)
标识一个正则表达式匹配,包含所有子表达式匹配
(类模板)
迭代一个字符序列中的所有正则表达式匹配
(类模板)
迭代给定字符串中的所有正则表达式匹配中的指定子表达式,或迭代未匹配的子字符串
(类模板)
报告正则表达式库生成的错误
(类)
提供正则表达式库所需的关于字符类型的元信息
(类模板)

函数

算法
尝试匹配一个正则表达式到整个字符序列
(函数模板)
尝试匹配一个正则表达式到字符序列的任何部分
(函数模板)
以格式化的替换文本来替换正则表达式匹配的出现位置
(函数模板)
非成员函数
特化 std::swap 算法
(函数模板)
(C++20 中移除)(C++20 中移除)(C++20 中移除)(C++20 中移除)(C++20 中移除)(C++20)
比较一个 sub_match 与另一 sub_match 、字符串或字符
(函数模板)
输出匹配的字符序列
(函数模板)
(C++20 中移除)
以字典序比较两个匹配结果的值
(函数模板)
特化 std::swap() 算法
(函数模板)


概要

#include <initializer_list>
 
namespace std {
 
    // regex 常量:
    namespace regex_constants {
        enum error_type;
    } // namespace regex_constants
 
    // 类 regex_error:
    class regex_error;
    // 类模板 regex_traits:
    template <class charT> struct regex_traits;
    // 类模板 basic_regex:
    template <class charT, class traits = regex_traits<charT> > class basic_regex;
 
    typedef basic_regex<char> regex;
    typedef basic_regex<wchar_t> wregex;
 
    // basic_regex 交换:
    template <class charT, class traits>
        void swap(basic_regex<charT, traits>& e1, basic_regex<charT, traits>& e2);
 
    // 类模板 sub_match:
    template <class BidirectionalIterator> class sub_match;
 
    typedef sub_match<const char*>              csub_match;
    typedef sub_match<const wchar_t*>           wcsub_match;
    typedef sub_match<string::const_iterator>   ssub_match;
    typedef sub_match<wstring::const_iterator>  wssub_match;
 
    // sub_match 非成员运算符:
    template <class BiIter>
        bool operator==(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
    template <class BiIter>
        bool operator!=(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
    template <class BiIter>
        bool operator<(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
    template <class BiIter>
        bool operator<=(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
    template <class BiIter>
        bool operator>=(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
    template <class BiIter>
        bool operator>(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
 
    template <class BiIter, class ST, class SA>
        bool operator==(
            const basic_string<
                typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
            const sub_match<BiIter>& rhs);
    template <class BiIter, class ST, class SA>
        bool operator!=(
            const basic_string<
                typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
            const sub_match<BiIter>& rhs);
    template <class BiIter, class ST, class SA>
        bool operator<(
            const basic_string<
                typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
            const sub_match<BiIter>& rhs);
    template <class BiIter, class ST, class SA>
        bool operator>(
            const basic_string<
                typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
            const sub_match<BiIter>& rhs);
    template <class BiIter, class ST, class SA>
        bool operator>=(
            const basic_string<
                typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
            const sub_match<BiIter>& rhs);
    template <class BiIter, class ST, class SA>
        bool operator<=(
            const basic_string<
                typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
            const sub_match<BiIter>& rhs);
 
 
    template <class BiIter, class ST, class SA>
        bool operator==(
            const sub_match<BiIter>& lhs,
            const basic_string<
                typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
    template <class BiIter, class ST, class SA>
        bool operator!=(
            const sub_match<BiIter>& lhs,
            const basic_string<
                typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
    template <class BiIter, class ST, class SA>
        bool operator<(
            const sub_match<BiIter>& lhs,
            const basic_string<
                typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
    template <class BiIter, class ST, class SA>
        bool operator>(
            const sub_match<BiIter>& lhs,
            const basic_string<
                typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
    template <class BiIter, class ST, class SA>
        bool operator<=(
            const sub_match<BiIter>& lhs,
            const basic_string<
                typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
    template <class BiIter, class ST, class SA>
        bool operator>=(
            const sub_match<BiIter>& lhs,
            const basic_string<
                typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
 
    template <class BiIter>
        bool operator==(typename iterator_traits<BiIter>::value_type const* lhs,
            const sub_match<BiIter>& rhs);
    template <class BiIter>
        bool operator!=(typename iterator_traits<BiIter>::value_type const* lhs,
            const sub_match<BiIter>& rhs);
    template <class BiIter>
        bool operator<(typename iterator_traits<BiIter>::value_type const* lhs,
            const sub_match<BiIter>& rhs);
    template <class BiIter>
        bool operator>(typename iterator_traits<BiIter>::value_type const* lhs,
            const sub_match<BiIter>& rhs);
    template <class BiIter>
        bool operator>=(typename iterator_traits<BiIter>::value_type const* lhs,
            const sub_match<BiIter>& rhs);
    template <class BiIter>
        bool operator<=(typename iterator_traits<BiIter>::value_type const* lhs,
            const sub_match<BiIter>& rhs);
 
    template <class BiIter>
        bool operator==(const sub_match<BiIter>& lhs,
            typename iterator_traits<BiIter>::value_type const* rhs);
    template <class BiIter>
        bool operator!=(const sub_match<BiIter>& lhs,
            typename iterator_traits<BiIter>::value_type const* rhs);
    template <class BiIter>
        bool operator<=(const sub_match<BiIter>& lhs,
            typename iterator_traits<BiIter>::value_type const* rhs);
    template <class BiIter>
        bool operator>=(const sub_match<BiIter>& lhs,
            typename iterator_traits<BiIter>::value_type const* rhs);
    template <class BiIter>
        bool operator<(const sub_match<BiIter>& lhs,
            typename iterator_traits<BiIter>::value_type const* rhs);
    template <class BiIter>
        bool operator>(const sub_match<BiIter>& lhs,
            typename iterator_traits<BiIter>::value_type const* rhs);
 
 
    template <class BiIter>
        bool operator==(typename iterator_traits<BiIter>::value_type const& lhs,
            const sub_match<BiIter>& rhs);
    template <class BiIter>
        bool operator!=(typename iterator_traits<BiIter>::value_type const& lhs,
            const sub_match<BiIter>& rhs);
    template <class BiIter>
        bool operator>=(typename iterator_traits<BiIter>::value_type const& lhs,
            const sub_match<BiIter>& rhs);
    template <class BiIter>
        bool operator<=(typename iterator_traits<BiIter>::value_type const& lhs,
            const sub_match<BiIter>& rhs);
    template <class BiIter>
        bool operator>(typename iterator_traits<BiIter>::value_type const& lhs,
            const sub_match<BiIter>& rhs);
    template <class BiIter>
        bool operator<(typename iterator_traits<BiIter>::value_type const& lhs,
            const sub_match<BiIter>& rhs);
 
    template <class BiIter>
        bool operator==(const sub_match<BiIter>& lhs,
            typename iterator_traits<BiIter>::value_type const& rhs);
    template <class BiIter>
        bool operator!=(const sub_match<BiIter>& lhs,
            typename iterator_traits<BiIter>::value_type const& rhs);
    template <class BiIter>
        bool operator>=(const sub_match<BiIter>& lhs,
            typename iterator_traits<BiIter>::value_type const& rhs);
    template <class BiIter>
        bool operator<=(const sub_match<BiIter>& lhs,
            typename iterator_traits<BiIter>::value_type const& rhs);
    template <class BiIter>
        bool operator<(const sub_match<BiIter>& lhs,
            typename iterator_traits<BiIter>::value_type const& rhs);
    template <class BiIter>
        bool operator>(const sub_match<BiIter>& lhs,
            typename iterator_traits<BiIter>::value_type const& rhs);
 
    template <class charT, class ST, class BiIter>
        basic_ostream<charT, ST>&
        operator<<(basic_ostream<charT, ST>& os, const sub_match<BiIter>& m);
 
    // 类模板 match_results:
    template <class BidirectionalIterator,
              class Allocator = allocator<sub_match<BidirectionalIterator> > >
        class match_results;
 
    typedef match_results<const char*>              cmatch;
    typedef match_results<const wchar_t*>           wcmatch;
    typedef match_results<string::const_iterator>   smatch;
    typedef match_results<wstring::const_iterator>  wsmatch;
 
    // match_results 比较
    template <class BidirectionalIterator, class Allocator>
        bool operator== (const match_results<BidirectionalIterator, Allocator>& m1,
                         const match_results<BidirectionalIterator, Allocator>& m2);
    template <class BidirectionalIterator, class Allocator>
        bool operator!= (const match_results<BidirectionalIterator, Allocator>& m1,
                         const match_results<BidirectionalIterator, Allocator>& m2);
 
    // match_results 交换:
    template <class BidirectionalIterator, class Allocator>
        void swap(match_results<BidirectionalIterator, Allocator>& m1,
                  match_results<BidirectionalIterator, Allocator>& m2);
 
    //  函数模板 regex_match:
    template <class BidirectionalIterator, class Allocator,
              class charT, class traits>
        bool regex_match(BidirectionalIterator first, BidirectionalIterator last,
                         match_results<BidirectionalIterator, Allocator>& m,
                         const basic_regex<charT, traits>& e,
                         regex_constants::match_flag_type flags =
                            regex_constants::match_default);
    template <class BidirectionalIterator, class charT, class traits>
        bool regex_match(BidirectionalIterator first, BidirectionalIterator last,
                         const basic_regex<charT, traits>& e,
                         regex_constants::match_flag_type flags =
                            regex_constants::match_default);
    template <class charT, class Allocator, class traits>
        bool regex_match(const charT* str, match_results<const charT*, Allocator>& m,
                         const basic_regex<charT, traits>& e,
                         regex_constants::match_flag_type flags =
                            regex_constants::match_default);
    template <class ST, class SA, class Allocator, class charT, class traits>
        bool regex_match(const basic_string<charT, ST, SA>& s,
            match_results<
                typename basic_string<charT, ST, SA>::const_iterator,
                Allocator>& m,
            const basic_regex<charT, traits>& e,
            regex_constants::match_flag_type flags =
                regex_constants::match_default);
    template <class charT, class traits>
        bool regex_match(const charT* str,
            const basic_regex<charT, traits>& e,
            regex_constants::match_flag_type flags =
                regex_constants::match_default);
    template <class ST, class SA, class charT, class traits>
        bool regex_match(const basic_string<charT, ST, SA>& s,
            const basic_regex<charT, traits>& e,
            regex_constants::match_flag_type flags =
                regex_constants::match_default);
 
    // 函数模板 regex_search:
    template <class BidirectionalIterator, class Allocator,
              class charT, class traits>
        bool regex_search(BidirectionalIterator first, BidirectionalIterator last,
            match_results<BidirectionalIterator, Allocator>& m,
            const basic_regex<charT, traits>& e,
            regex_constants::match_flag_type flags =
                regex_constants::match_default);
    template <class BidirectionalIterator, class charT, class traits>
        bool regex_search(BidirectionalIterator first, BidirectionalIterator last,
            const basic_regex<charT, traits>& e,
            regex_constants::match_flag_type flags =
                regex_constants::match_default);
    template <class charT, class Allocator, class traits>
        bool regex_search(const charT* str,
            match_results<const charT*, Allocator>& m,
            const basic_regex<charT, traits>& e,
            regex_constants::match_flag_type flags =
                regex_constants::match_default);
    template <class charT, class traits>
        bool regex_search(const charT* str,
            const basic_regex<charT, traits>& e,
                regex_constants::match_flag_type flags =
                    regex_constants::match_default);
    template <class ST, class SA, class charT, class traits>
        bool regex_search(const basic_string<charT, ST, SA>& s,
            const basic_regex<charT, traits>& e,
            regex_constants::match_flag_type flags =
                regex_constants::match_default);
    template <class ST, class SA, class Allocator, class charT, class traits>
        bool regex_search(const basic_string<charT, ST, SA>& s,
            match_results<
                typename basic_string<charT, ST, SA>::const_iterator,
                Allocator>& m,
            const basic_regex<charT, traits>& e,
            regex_constants::match_flag_type flags =
                regex_constants::match_default);
 
    // 函数模板 regex_replace:
    template <class OutputIterator, class BidirectionalIterator,
              class traits, class charT, class ST, class SA>
        OutputIterator
        regex_replace(  OutputIterator out,
                        BidirectionalIterator first, 
                        BidirectionalIterator last,
                        const basic_regex<charT, traits>& e,
                        const basic_string<charT, ST, SA>& fmt,
                        regex_constants::match_flag_type flags =
                            regex_constants::match_default);
    template <class OutputIterator, class BidirectionalIterator,
              class traits, class charT>
        OutputIterator
        regex_replace(  OutputIterator out,
                        BidirectionalIterator first, 
                        BidirectionalIterator last,
                        const basic_regex<charT, traits>& e,
                        const charT* fmt,
                        regex_constants::match_flag_type flags =
                            regex_constants::match_default);
    template <class traits, class charT, class ST, class SA,
              class FST, class FSA>
        basic_string<charT, ST, SA>
        regex_replace(  const basic_string<charT, ST, SA>& s,
                        const basic_regex<charT, traits>& e,
                        const basic_string<charT, FST, FSA>& fmt,
                        regex_constants::match_flag_type flags =
                            regex_constants::match_default);
    template <class traits, class charT, class ST, class SA>
        basic_string<charT, ST, SA>
        regex_replace(  const basic_string<charT, ST, SA>& s,
                        const basic_regex<charT, traits>& e,
                        const charT* fmt,
                        regex_constants::match_flag_type flags =
                            regex_constants::match_default);
    template <class traits, class charT, class ST, class SA>
        basic_string<charT>
        regex_replace(  const charT* s,
                        const basic_regex<charT, traits>& e,
                        const basic_string<charT, ST, SA>& fmt,
                        regex_constants::match_flag_type flags =
                            regex_constants::match_default);
    template <class traits, class charT>
        basic_string<charT>
        regex_replace(  const charT* s,
                        const basic_regex<charT, traits>& e,
                        const charT* fmt,
                        regex_constants::match_flag_type flags =
                            regex_constants::match_default);
 
    // 类模板 regex_iterator:
    template <class BidirectionalIterator,
              class charT = typename iterator_traits<
                    BidirectionalIterator>::value_type,
              class traits = regex_traits<charT> >
        class regex_iterator;
 
    typedef regex_iterator<const char*>             cregex_iterator;
    typedef regex_iterator<const wchar_t*>          wcregex_iterator;
    typedef regex_iterator<string::const_iterator>  sregex_iterator;
    typedef regex_iterator<wstring::const_iterator> wsregex_iterator;
 
    // 类模板 regex_token_iterator:
    template <class BidirectionalIterator,
              class charT = typename iterator_traits<
                BidirectionalIterator>::value_type,
              class traits = regex_traits<charT> >
        class regex_token_iterator;
 
    typedef regex_token_iterator<const char*>               cregex_token_iterator;
    typedef regex_token_iterator<const wchar_t*>            wcregex_token_iterator;
    typedef regex_token_iterator<string::const_iterator>    scregex_token_iterator;
    typedef regex_token_iterator<wstring::const_iterator>   wscregex_token_iterator;
 
 
} // namespace std


命名空间 std::regex_constants

namespace regex_constants {
    typedef /*T1*/ syntax_option_type;
    static constexpr syntax_option_type icase = /* 未指明 */ ;
    static constexpr syntax_option_type nosubs = /* 未指明 */ ;
    static constexpr syntax_option_type optimize = /* 未指明 */ ;
    static constexpr syntax_option_type collate = /* 未指明 */ ;
    static constexpr syntax_option_type ECMAScript = /* 未指明 */ ;
    static constexpr syntax_option_type basic = /* 未指明 */ ;
    static constexpr syntax_option_type extended = /* 未指明 */ ;
    static constexpr syntax_option_type awk = /* 未指明 */ ;
    static constexpr syntax_option_type grep = /* 未指明 */ ;
    static constexpr syntax_option_type egrep = /* 未指明 */ ;
 
    typedef /*T2*/ match_flag_type;
    static constexpr match_flag_type match_default = 0;
    static constexpr match_flag_type match_not_bol = /* 未指明 */ ;
    static constexpr match_flag_type match_not_eol = /* 未指明 */ ;
    static constexpr match_flag_type match_not_bow = /* 未指明 */ ;
    static constexpr match_flag_type match_not_eow = /* 未指明 */ ;
    static constexpr match_flag_type match_any = /* 未指明 */ ;
    static constexpr match_flag_type match_not_null = /* 未指明 */ ;
    static constexpr match_flag_type match_continuous = /* 未指明 */ ;
    static constexpr match_flag_type match_prev_avail = /* 未指明 */ ;
    static constexpr match_flag_type format_default = 0;
    static constexpr match_flag_type format_sed = /* 未指明 */ ;
    static constexpr match_flag_type format_no_copy = /* 未指明 */ ;
    static constexpr match_flag_type format_first_only = /* 未指明 */ ;
 
    typedef /*T3*/ error_type;
    static constexpr error_type error_collate = /* 未指明 */ ;
    static constexpr error_type error_ctype = /* 未指明 */ ;
    static constexpr error_type error_escape = /* 未指明 */ ;
    static constexpr error_type error_backref = /* 未指明 */ ;
    static constexpr error_type error_brack = /* 未指明 */ ;
    static constexpr error_type error_paren = /* 未指明 */ ;
    static constexpr error_type error_brace = /* 未指明 */ ;
    static constexpr error_type error_badbrace = /* 未指明 */ ;
    static constexpr error_type error_range = /* 未指明 */ ;
    static constexpr error_type error_space = /* 未指明 */ ;
    static constexpr error_type error_badrepeat = /* 未指明 */ ;
    static constexpr error_type error_complexity = /* 未指明 */ ;
    static constexpr error_type error_stack = /* 未指明 */ ;
 
}

std::regex_error

class regex_error : public std::runtime_error {
public:
    explicit regex_error(regex_constants::error_type ecode);
    regex_constants::error_type code() const;
};


std::regex_traits

template <class charT>
struct regex_traits {
public:
    typedef charT                           char_type;
    typedef std::basic_string<char_type>    string_type;
    typedef std::locale                     locale_type;
    typedef /*bitmask_type*/                char_class_type;
 
    regex_traits();
    static std::size_t length(const char_type* p);
    charT translate(charT c) const;
    charT translate_nocase(charT c) const;
    template <class ForwardIterator>
        string_type transform(ForwardIterator first, ForwardIterator last) const;
    template <class ForwardIterator>
        string_type transform_primary(
            ForwardIterator first, ForwardIterator last) const;
    template <class ForwardIterator>
        string_type lookup_collatename(
            ForwardIterator first, ForwardIterator last) const;
    template <class ForwardIterator>
        char_class_type lookup_classname(
            ForwardIterator first, ForwardIterator last, bool icase = false) const;
    bool isctype(charT c, char_class_type f) const;
    int value(charT ch, int radix) const;
    locale_type imbue(locale_type l);
    locale_type getloc()const;
};

std::regex

template <class charT,
    class traits = regex_traits<charT> >
class basic_regex {
public:
    // 类型:
    typedef          charT                                  value_type;
    typedef          traits                                 traits_type;
    typedef typename traits::string_type                    string_type;
    typedef          regex_constants::syntax_option_type    flag_type;
    typedef typename traits::locale_type                    locale_type;
 
    // 常量:
    static constexpr regex_constants::syntax_option_type
        icase = regex_constants::icase;
    static constexpr regex_constants::syntax_option_type
        nosubs = regex_constants::nosubs;
    static constexpr regex_constants::syntax_option_type
        optimize = regex_constants::optimize;
    static constexpr regex_constants::syntax_option_type
        collate = regex_constants::collate;
    static constexpr regex_constants::syntax_option_type
        ECMAScript = regex_constants::ECMAScript;
    static constexpr regex_constants::syntax_option_type
        basic = regex_constants::basic;
    static constexpr regex_constants::syntax_option_type
        extended = regex_constants::extended;
    static constexpr regex_constants::syntax_option_type
        awk = regex_constants::awk;
    static constexpr regex_constants::syntax_option_type
        grep = regex_constants::grep;
    static constexpr regex_constants::syntax_option_type
        egrep = regex_constants::egrep;
 
    // 构造/复制/销毁:
    basic_regex();
    explicit basic_regex(const charT* p,
        flag_type f = regex_constants::ECMAScript);
    basic_regex(const charT* p, size_t len, flag_type f = regex_constants::ECMAScript);
    basic_regex(const basic_regex&);
    basic_regex(basic_regex&&) noexcept;
    template <class ST, class SA>
        explicit basic_regex(const basic_string<charT, ST, SA>& p,
            flag_type f = regex_constants::ECMAScript);
    template <class ForwardIterator>
        basic_regex(ForwardIterator first, ForwardIterator last,
            flag_type f = regex_constants::ECMAScript);
    basic_regex(initializer_list<charT>,
        flag_type = regex_constants::ECMAScript);
 
    ~basic_regex();
    basic_regex& operator=(const basic_regex&);
    basic_regex& operator=(basic_regex&&) noexcept;
    basic_regex& operator=(const charT* ptr);
    basic_regex& operator=(initializer_list<charT> il);
    template <class ST, class SA>
        basic_regex& operator=(const basic_string<charT, ST, SA>& p);
 
    // 赋值:
    basic_regex& assign(const basic_regex& that);
    basic_regex& assign(basic_regex&& that) noexcept;
    basic_regex& assign(const charT* ptr,
        flag_type f = regex_constants::ECMAScript);
    basic_regex& assign(const charT* p, size_t len, flag_type f);
    template <class string_traits, class A>
        basic_regex& assign(const basic_string<charT, string_traits, A>& s,
            flag_type f = regex_constants::ECMAScript);
    template <class InputIterator>
        basic_regex& assign(InputIterator first, InputIterator last,
            flag_type f = regex_constants::ECMAScript);
    basic_regex& assign(initializer_list<charT>,
        flag_type = regex_constants::ECMAScript);
 
    // const 操作:
    unsigned mark_count() const;
    flag_type flags() const;
 
    // 本地环境:
    locale_type imbue(locale_type loc);
    locale_type getloc() const;
 
    // 交换:
    void swap(basic_regex&);
};

std::sub_match

template <class BidirectionalIterator>
class sub_match : public std::pair<BidirectionalIterator, BidirectionalIterator> {
public:
    typedef typename iterator_traits<BidirectionalIterator>::
        value_type                                              value_type;
    typedef typename iterator_traits<BidirectionalIterator>::
    difference_type                                             difference_type;
    typedef BidirectionalIterator                               iterator;
    typedef basic_string<value_type>                            string_type;
 
    bool matched;
 
    constexpr sub_match();
    difference_type length() const;
    operator string_type() const;
    string_type str() const;
 
    int compare(const sub_match& s) const;
    int compare(const string_type& s) const;
    int compare(const value_type* s) const;
};

std::match_results

template <class BidirectionalIterator,
            class Allocator = allocator<sub_match<BidirectionalIterator> >
class match_results {
public:
    typedef sub_match<BidirectionalIterator>                    value_type;
    typedef const value_type&                                   const_reference;
    typedef const_reference                                     reference;
    typedef /* 由实现定义 */                                     const_iterator;
    typedef const_iterator                                      iterator;
    typedef typename 
        iterator_traits<BidirectionalIterator>::difference_type difference_type;
    typedef typename allocator_traits<Allocator>::size_type     size_type;
    typedef Allocator                                           allocator_type;
    typedef typename 
        iterator_traits<BidirectionalIterator>::value_type      char_type;
    typedef basic_string<char_type>                             string_type;
 
    // 构造/复制/销毁:
    explicit match_results(const Allocator& a = Allocator());
    match_results(const match_results& m);
    match_results(match_results&& m) noexcept;
    match_results& operator=(const match_results& m);
    match_results& operator=(match_results&& m);
    ~match_results();
 
    // 状态:
    bool ready() const;
 
    // 大小:
    size_type size() const;
    size_type max_size() const;
    bool empty() const;
 
    // 元素访问:
    difference_type length(size_type sub = 0) const;
    difference_type position(size_type sub = 0) const;
    string_type str(size_type sub = 0) const;
    const_reference operator[](size_type n) const;
 
    const_reference prefix() const;
    const_reference suffix() const;
    const_iterator  begin() const;
    const_iterator  end() const;
    const_iterator  cbegin() const;
    const_iterator  cend() const;
 
    // 格式:
    template <class OutputIter>
        OutputIter
        format(OutputIter out,
            const char_type* fmt_first, const char_type* fmt_last,
            regex_constants::match_flag_type flags =
            regex_constants::format_default) const;
    template <class OutputIter, class ST, class SA>
        OutputIter
        format(OutputIter out,
            const basic_string<char_type, ST, SA>& fmt,
            regex_constants::match_flag_type flags =
            regex_constants::format_default) const;
    template <class ST, class SA>
        basic_string<char_type, ST, SA>
        format(const basic_string<char_type, ST, SA>& fmt,
            regex_constants::match_flag_type flags =
            regex_constants::format_default) const;
    string_type
        format(const char_type* fmt,
            regex_constants::match_flag_type flags =
            regex_constants::format_default) const;
 
    // 分配器:
    allocator_type get_allocator() const;
 
    // 交换:
    void swap(match_results& that);
 
};