xref: /freebsd/contrib/llvm-project/libcxx/include/regex (revision 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583)
10b57cec5SDimitry Andric// -*- C++ -*-
2349cc55cSDimitry Andric//===----------------------------------------------------------------------===//
30b57cec5SDimitry Andric//
40b57cec5SDimitry Andric// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
50b57cec5SDimitry Andric// See https://llvm.org/LICENSE.txt for license information.
60b57cec5SDimitry Andric// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
70b57cec5SDimitry Andric//
80b57cec5SDimitry Andric//===----------------------------------------------------------------------===//
90b57cec5SDimitry Andric
100b57cec5SDimitry Andric#ifndef _LIBCPP_REGEX
110b57cec5SDimitry Andric#define _LIBCPP_REGEX
120b57cec5SDimitry Andric
130b57cec5SDimitry Andric/*
140b57cec5SDimitry Andric    regex synopsis
150b57cec5SDimitry Andric
1606c3fb27SDimitry Andric#include <compare>
170b57cec5SDimitry Andric#include <initializer_list>
180b57cec5SDimitry Andric
190b57cec5SDimitry Andricnamespace std
200b57cec5SDimitry Andric{
210b57cec5SDimitry Andric
220b57cec5SDimitry Andricnamespace regex_constants
230b57cec5SDimitry Andric{
240b57cec5SDimitry Andric
255ffd83dbSDimitry Andricenum syntax_option_type
260b57cec5SDimitry Andric{
270b57cec5SDimitry Andric    icase      = unspecified,
280b57cec5SDimitry Andric    nosubs     = unspecified,
290b57cec5SDimitry Andric    optimize   = unspecified,
300b57cec5SDimitry Andric    collate    = unspecified,
310b57cec5SDimitry Andric    ECMAScript = unspecified,
320b57cec5SDimitry Andric    basic      = unspecified,
330b57cec5SDimitry Andric    extended   = unspecified,
340b57cec5SDimitry Andric    awk        = unspecified,
350b57cec5SDimitry Andric    grep       = unspecified,
36e8d8bef9SDimitry Andric    egrep      = unspecified,
37e8d8bef9SDimitry Andric    multiline  = unspecified
380b57cec5SDimitry Andric};
390b57cec5SDimitry Andric
400b57cec5SDimitry Andricconstexpr syntax_option_type operator~(syntax_option_type f);
410b57cec5SDimitry Andricconstexpr syntax_option_type operator&(syntax_option_type lhs, syntax_option_type rhs);
420b57cec5SDimitry Andricconstexpr syntax_option_type operator|(syntax_option_type lhs, syntax_option_type rhs);
430b57cec5SDimitry Andric
440b57cec5SDimitry Andricenum match_flag_type
450b57cec5SDimitry Andric{
460b57cec5SDimitry Andric    match_default     = 0,
470b57cec5SDimitry Andric    match_not_bol     = unspecified,
480b57cec5SDimitry Andric    match_not_eol     = unspecified,
490b57cec5SDimitry Andric    match_not_bow     = unspecified,
500b57cec5SDimitry Andric    match_not_eow     = unspecified,
510b57cec5SDimitry Andric    match_any         = unspecified,
520b57cec5SDimitry Andric    match_not_null    = unspecified,
530b57cec5SDimitry Andric    match_continuous  = unspecified,
540b57cec5SDimitry Andric    match_prev_avail  = unspecified,
550b57cec5SDimitry Andric    format_default    = 0,
560b57cec5SDimitry Andric    format_sed        = unspecified,
570b57cec5SDimitry Andric    format_no_copy    = unspecified,
580b57cec5SDimitry Andric    format_first_only = unspecified
590b57cec5SDimitry Andric};
600b57cec5SDimitry Andric
610b57cec5SDimitry Andricconstexpr match_flag_type operator~(match_flag_type f);
620b57cec5SDimitry Andricconstexpr match_flag_type operator&(match_flag_type lhs, match_flag_type rhs);
630b57cec5SDimitry Andricconstexpr match_flag_type operator|(match_flag_type lhs, match_flag_type rhs);
640b57cec5SDimitry Andric
650b57cec5SDimitry Andricenum error_type
660b57cec5SDimitry Andric{
670b57cec5SDimitry Andric    error_collate    = unspecified,
680b57cec5SDimitry Andric    error_ctype      = unspecified,
690b57cec5SDimitry Andric    error_escape     = unspecified,
700b57cec5SDimitry Andric    error_backref    = unspecified,
710b57cec5SDimitry Andric    error_brack      = unspecified,
720b57cec5SDimitry Andric    error_paren      = unspecified,
730b57cec5SDimitry Andric    error_brace      = unspecified,
740b57cec5SDimitry Andric    error_badbrace   = unspecified,
750b57cec5SDimitry Andric    error_range      = unspecified,
760b57cec5SDimitry Andric    error_space      = unspecified,
770b57cec5SDimitry Andric    error_badrepeat  = unspecified,
780b57cec5SDimitry Andric    error_complexity = unspecified,
790b57cec5SDimitry Andric    error_stack      = unspecified
800b57cec5SDimitry Andric};
810b57cec5SDimitry Andric
820b57cec5SDimitry Andric}  // regex_constants
830b57cec5SDimitry Andric
840b57cec5SDimitry Andricclass regex_error
850b57cec5SDimitry Andric    : public runtime_error
860b57cec5SDimitry Andric{
870b57cec5SDimitry Andricpublic:
880b57cec5SDimitry Andric    explicit regex_error(regex_constants::error_type ecode);
890b57cec5SDimitry Andric    regex_constants::error_type code() const;
900b57cec5SDimitry Andric};
910b57cec5SDimitry Andric
920b57cec5SDimitry Andrictemplate <class charT>
930b57cec5SDimitry Andricstruct regex_traits
940b57cec5SDimitry Andric{
950b57cec5SDimitry Andricpublic:
960b57cec5SDimitry Andric    typedef charT                   char_type;
970b57cec5SDimitry Andric    typedef basic_string<char_type> string_type;
980b57cec5SDimitry Andric    typedef locale                  locale_type;
990b57cec5SDimitry Andric    typedef /bitmask_type/          char_class_type;
1000b57cec5SDimitry Andric
1010b57cec5SDimitry Andric    regex_traits();
1020b57cec5SDimitry Andric
1030b57cec5SDimitry Andric    static size_t length(const char_type* p);
1040b57cec5SDimitry Andric    charT translate(charT c) const;
1050b57cec5SDimitry Andric    charT translate_nocase(charT c) const;
1060b57cec5SDimitry Andric    template <class ForwardIterator>
1070b57cec5SDimitry Andric        string_type
1080b57cec5SDimitry Andric        transform(ForwardIterator first, ForwardIterator last) const;
1090b57cec5SDimitry Andric    template <class ForwardIterator>
1100b57cec5SDimitry Andric        string_type
1110b57cec5SDimitry Andric        transform_primary( ForwardIterator first, ForwardIterator last) const;
1120b57cec5SDimitry Andric    template <class ForwardIterator>
1130b57cec5SDimitry Andric        string_type
1140b57cec5SDimitry Andric        lookup_collatename(ForwardIterator first, ForwardIterator last) const;
1150b57cec5SDimitry Andric    template <class ForwardIterator>
1160b57cec5SDimitry Andric        char_class_type
1170b57cec5SDimitry Andric        lookup_classname(ForwardIterator first, ForwardIterator last,
1180b57cec5SDimitry Andric                         bool icase = false) const;
1190b57cec5SDimitry Andric    bool isctype(charT c, char_class_type f) const;
1200b57cec5SDimitry Andric    int value(charT ch, int radix) const;
1210b57cec5SDimitry Andric    locale_type imbue(locale_type l);
1220b57cec5SDimitry Andric    locale_type getloc()const;
1230b57cec5SDimitry Andric};
1240b57cec5SDimitry Andric
1250b57cec5SDimitry Andrictemplate <class charT, class traits = regex_traits<charT>>
1260b57cec5SDimitry Andricclass basic_regex
1270b57cec5SDimitry Andric{
1280b57cec5SDimitry Andricpublic:
1290b57cec5SDimitry Andric    // types:
1300b57cec5SDimitry Andric    typedef charT                               value_type;
1310b57cec5SDimitry Andric    typedef traits                              traits_type;
1320b57cec5SDimitry Andric    typedef typename traits::string_type        string_type;
1330b57cec5SDimitry Andric    typedef regex_constants::syntax_option_type flag_type;
1340b57cec5SDimitry Andric    typedef typename traits::locale_type        locale_type;
1350b57cec5SDimitry Andric
1360b57cec5SDimitry Andric    // constants:
1370b57cec5SDimitry Andric    static constexpr regex_constants::syntax_option_type icase = regex_constants::icase;
1380b57cec5SDimitry Andric    static constexpr regex_constants::syntax_option_type nosubs = regex_constants::nosubs;
1390b57cec5SDimitry Andric    static constexpr regex_constants::syntax_option_type optimize = regex_constants::optimize;
1400b57cec5SDimitry Andric    static constexpr regex_constants::syntax_option_type collate = regex_constants::collate;
1410b57cec5SDimitry Andric    static constexpr regex_constants::syntax_option_type ECMAScript = regex_constants::ECMAScript;
1420b57cec5SDimitry Andric    static constexpr regex_constants::syntax_option_type basic = regex_constants::basic;
1430b57cec5SDimitry Andric    static constexpr regex_constants::syntax_option_type extended = regex_constants::extended;
1440b57cec5SDimitry Andric    static constexpr regex_constants::syntax_option_type awk = regex_constants::awk;
1450b57cec5SDimitry Andric    static constexpr regex_constants::syntax_option_type grep = regex_constants::grep;
1460b57cec5SDimitry Andric    static constexpr regex_constants::syntax_option_type egrep = regex_constants::egrep;
147e8d8bef9SDimitry Andric    static constexpr regex_constants::syntax_option_type multiline = regex_constants::multiline;
1480b57cec5SDimitry Andric
1490b57cec5SDimitry Andric    // construct/copy/destroy:
1500b57cec5SDimitry Andric    basic_regex();
1510b57cec5SDimitry Andric    explicit basic_regex(const charT* p, flag_type f = regex_constants::ECMAScript);
1520b57cec5SDimitry Andric    basic_regex(const charT* p, size_t len, flag_type f = regex_constants::ECMAScript);
1530b57cec5SDimitry Andric    basic_regex(const basic_regex&);
1540b57cec5SDimitry Andric    basic_regex(basic_regex&&) noexcept;
1550b57cec5SDimitry Andric    template <class ST, class SA>
1560b57cec5SDimitry Andric        explicit basic_regex(const basic_string<charT, ST, SA>& p,
1570b57cec5SDimitry Andric                             flag_type f = regex_constants::ECMAScript);
1580b57cec5SDimitry Andric    template <class ForwardIterator>
1590b57cec5SDimitry Andric        basic_regex(ForwardIterator first, ForwardIterator last,
1600b57cec5SDimitry Andric                    flag_type f = regex_constants::ECMAScript);
1610b57cec5SDimitry Andric    basic_regex(initializer_list<charT>, flag_type = regex_constants::ECMAScript);
1620b57cec5SDimitry Andric
1630b57cec5SDimitry Andric    ~basic_regex();
1640b57cec5SDimitry Andric
1650b57cec5SDimitry Andric    basic_regex& operator=(const basic_regex&);
1660b57cec5SDimitry Andric    basic_regex& operator=(basic_regex&&) noexcept;
1670b57cec5SDimitry Andric    basic_regex& operator=(const charT* ptr);
1680b57cec5SDimitry Andric    basic_regex& operator=(initializer_list<charT> il);
1690b57cec5SDimitry Andric    template <class ST, class SA>
1700b57cec5SDimitry Andric        basic_regex& operator=(const basic_string<charT, ST, SA>& p);
1710b57cec5SDimitry Andric
1720b57cec5SDimitry Andric    // assign:
1730b57cec5SDimitry Andric    basic_regex& assign(const basic_regex& that);
1740b57cec5SDimitry Andric    basic_regex& assign(basic_regex&& that) noexcept;
1750b57cec5SDimitry Andric    basic_regex& assign(const charT* ptr,           flag_type f = regex_constants::ECMAScript);
176e40139ffSDimitry Andric    basic_regex& assign(const charT* p, size_t len, flag_type f = regex_constants::ECMAScript);
1770b57cec5SDimitry Andric    template <class string_traits, class A>
1780b57cec5SDimitry Andric        basic_regex& assign(const basic_string<charT, string_traits, A>& s,
1790b57cec5SDimitry Andric                                                    flag_type f = regex_constants::ECMAScript);
1800b57cec5SDimitry Andric    template <class InputIterator>
1810b57cec5SDimitry Andric        basic_regex& assign(InputIterator first, InputIterator last,
1820b57cec5SDimitry Andric                                                    flag_type f = regex_constants::ECMAScript);
183e40139ffSDimitry Andric    basic_regex& assign(initializer_list<charT>,    flag_type f = regex_constants::ECMAScript);
1840b57cec5SDimitry Andric
1850b57cec5SDimitry Andric    // const operations:
1860b57cec5SDimitry Andric    unsigned mark_count() const;
1870b57cec5SDimitry Andric    flag_type flags() const;
1880b57cec5SDimitry Andric
1890b57cec5SDimitry Andric    // locale:
1900b57cec5SDimitry Andric    locale_type imbue(locale_type loc);
1910b57cec5SDimitry Andric    locale_type getloc() const;
1920b57cec5SDimitry Andric
1930b57cec5SDimitry Andric    // swap:
1940b57cec5SDimitry Andric    void swap(basic_regex&);
1950b57cec5SDimitry Andric};
1960b57cec5SDimitry Andric
1970b57cec5SDimitry Andrictemplate<class ForwardIterator>
1980b57cec5SDimitry Andricbasic_regex(ForwardIterator, ForwardIterator,
1990b57cec5SDimitry Andric            regex_constants::syntax_option_type = regex_constants::ECMAScript)
2000b57cec5SDimitry Andric    -> basic_regex<typename iterator_traits<ForwardIterator>::value_type>; // C++17
2010b57cec5SDimitry Andric
2020b57cec5SDimitry Andrictypedef basic_regex<char>    regex;
2030b57cec5SDimitry Andrictypedef basic_regex<wchar_t> wregex;
2040b57cec5SDimitry Andric
2050b57cec5SDimitry Andrictemplate <class charT, class traits>
2060b57cec5SDimitry Andric    void swap(basic_regex<charT, traits>& e1, basic_regex<charT, traits>& e2);
2070b57cec5SDimitry Andric
2080b57cec5SDimitry Andrictemplate <class BidirectionalIterator>
2090b57cec5SDimitry Andricclass sub_match
2100b57cec5SDimitry Andric    : public pair<BidirectionalIterator, BidirectionalIterator>
2110b57cec5SDimitry Andric{
2120b57cec5SDimitry Andricpublic:
2130b57cec5SDimitry Andric    typedef typename iterator_traits<BidirectionalIterator>::value_type value_type;
2140b57cec5SDimitry Andric    typedef typename iterator_traits<BidirectionalIterator>::difference_type difference_type;
2150b57cec5SDimitry Andric    typedef BidirectionalIterator                                      iterator;
2160b57cec5SDimitry Andric    typedef basic_string<value_type>                                string_type;
2170b57cec5SDimitry Andric
2180b57cec5SDimitry Andric    bool matched;
2190b57cec5SDimitry Andric
2200b57cec5SDimitry Andric    constexpr sub_match();
2210b57cec5SDimitry Andric
2220b57cec5SDimitry Andric    difference_type length() const;
2230b57cec5SDimitry Andric    operator string_type() const;
2240b57cec5SDimitry Andric    string_type str() const;
2250b57cec5SDimitry Andric
2260b57cec5SDimitry Andric    int compare(const sub_match& s) const;
2270b57cec5SDimitry Andric    int compare(const string_type& s) const;
2280b57cec5SDimitry Andric    int compare(const value_type* s) const;
22906c3fb27SDimitry Andric
23006c3fb27SDimitry Andric    void swap(sub_match& s) noexcept(see below);
2310b57cec5SDimitry Andric};
2320b57cec5SDimitry Andric
2330b57cec5SDimitry Andrictypedef sub_match<const char*>             csub_match;
2340b57cec5SDimitry Andrictypedef sub_match<const wchar_t*>          wcsub_match;
2350b57cec5SDimitry Andrictypedef sub_match<string::const_iterator>  ssub_match;
2360b57cec5SDimitry Andrictypedef sub_match<wstring::const_iterator> wssub_match;
2370b57cec5SDimitry Andric
2380b57cec5SDimitry Andrictemplate <class BiIter>
2390b57cec5SDimitry Andric    bool
2400b57cec5SDimitry Andric    operator==(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
2410b57cec5SDimitry Andric
2420b57cec5SDimitry Andrictemplate <class BiIter>
24306c3fb27SDimitry Andric    auto
24406c3fb27SDimitry Andric    operator<=>(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs); // Since C++20
24506c3fb27SDimitry Andric
24606c3fb27SDimitry Andric template <class BiIter>                                                     // Removed in C++20
2470b57cec5SDimitry Andric    bool
2480b57cec5SDimitry Andric    operator!=(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
2490b57cec5SDimitry Andric
25006c3fb27SDimitry Andrictemplate <class BiIter>                                                      // Removed in C++20
2510b57cec5SDimitry Andric    bool
2520b57cec5SDimitry Andric    operator<(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
2530b57cec5SDimitry Andric
25406c3fb27SDimitry Andrictemplate <class BiIter>                                                      // Removed in C++20
2550b57cec5SDimitry Andric    bool
2560b57cec5SDimitry Andric    operator<=(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
2570b57cec5SDimitry Andric
25806c3fb27SDimitry Andrictemplate <class BiIter>                                                      // Removed in C++20
2590b57cec5SDimitry Andric    bool
2600b57cec5SDimitry Andric    operator>=(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
2610b57cec5SDimitry Andric
26206c3fb27SDimitry Andrictemplate <class BiIter>                                                      // Removed in C++20
2630b57cec5SDimitry Andric    bool
2640b57cec5SDimitry Andric    operator>(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
2650b57cec5SDimitry Andric
26606c3fb27SDimitry Andrictemplate <class BiIter, class ST, class SA>                                  // Removed in C++20
2670b57cec5SDimitry Andric    bool
2680b57cec5SDimitry Andric    operator==(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
2690b57cec5SDimitry Andric               const sub_match<BiIter>& rhs);
2700b57cec5SDimitry Andric
27106c3fb27SDimitry Andrictemplate <class BiIter, class ST, class SA>                                  // Removed in C++20
2720b57cec5SDimitry Andric    bool
2730b57cec5SDimitry Andric    operator!=(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
2740b57cec5SDimitry Andric               const sub_match<BiIter>& rhs);
2750b57cec5SDimitry Andric
27606c3fb27SDimitry Andrictemplate <class BiIter, class ST, class SA>                                  // Removed in C++20
2770b57cec5SDimitry Andric    bool
2780b57cec5SDimitry Andric    operator<(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
2790b57cec5SDimitry Andric              const sub_match<BiIter>& rhs);
2800b57cec5SDimitry Andric
28106c3fb27SDimitry Andrictemplate <class BiIter, class ST, class SA>                                  // Removed in C++20
2820b57cec5SDimitry Andric    bool
2830b57cec5SDimitry Andric    operator>(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
2840b57cec5SDimitry Andric              const sub_match<BiIter>& rhs);
2850b57cec5SDimitry Andric
28606c3fb27SDimitry Andrictemplate <class BiIter, class ST, class SA>                                  // Removed in C++20
2870b57cec5SDimitry Andric    bool operator>=(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
2880b57cec5SDimitry Andric                    const sub_match<BiIter>& rhs);
2890b57cec5SDimitry Andric
29006c3fb27SDimitry Andrictemplate <class BiIter, class ST, class SA>                                  // Removed in C++20
2910b57cec5SDimitry Andric    bool
2920b57cec5SDimitry Andric    operator<=(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
2930b57cec5SDimitry Andric               const sub_match<BiIter>& rhs);
2940b57cec5SDimitry Andric
2950b57cec5SDimitry Andrictemplate <class BiIter, class ST, class SA>
2960b57cec5SDimitry Andric    bool
2970b57cec5SDimitry Andric    operator==(const sub_match<BiIter>& lhs,
2980b57cec5SDimitry Andric               const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
2990b57cec5SDimitry Andric
30006c3fb27SDimitry Andrictemplate <class BiIter, class ST, class SA>                                  // Since C++20
30106c3fb27SDimitry Andric    auto
30206c3fb27SDimitry Andric    operator<=>(const sub_match<BiIter>& lhs,
30306c3fb27SDimitry Andric                const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
30406c3fb27SDimitry Andric
30506c3fb27SDimitry Andrictemplate <class BiIter, class ST, class SA>                                  // Removed in C++20
3060b57cec5SDimitry Andric    bool
3070b57cec5SDimitry Andric    operator!=(const sub_match<BiIter>& lhs,
3080b57cec5SDimitry Andric               const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
3090b57cec5SDimitry Andric
31006c3fb27SDimitry Andrictemplate <class BiIter, class ST, class SA>                                  // Removed in C++20
3110b57cec5SDimitry Andric    bool
3120b57cec5SDimitry Andric    operator<(const sub_match<BiIter>& lhs,
3130b57cec5SDimitry Andric              const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
3140b57cec5SDimitry Andric
31506c3fb27SDimitry Andrictemplate <class BiIter, class ST, class SA>                                  // Removed in C++20
31606c3fb27SDimitry Andric    bool
31706c3fb27SDimitry Andric    operator>(const sub_match<BiIter>& lhs,
3180b57cec5SDimitry Andric                   const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
3190b57cec5SDimitry Andric
32006c3fb27SDimitry Andrictemplate <class BiIter, class ST, class SA>                                  // Removed in C++20
3210b57cec5SDimitry Andric    bool
3220b57cec5SDimitry Andric    operator>=(const sub_match<BiIter>& lhs,
3230b57cec5SDimitry Andric               const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
3240b57cec5SDimitry Andric
32506c3fb27SDimitry Andrictemplate <class BiIter, class ST, class SA>                                  // Removed in C++20
3260b57cec5SDimitry Andric    bool
3270b57cec5SDimitry Andric    operator<=(const sub_match<BiIter>& lhs,
3280b57cec5SDimitry Andric               const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
3290b57cec5SDimitry Andric
33006c3fb27SDimitry Andrictemplate <class BiIter>                                                      // Removed in C++20
3310b57cec5SDimitry Andric    bool
3320b57cec5SDimitry Andric    operator==(typename iterator_traits<BiIter>::value_type const* lhs,
3330b57cec5SDimitry Andric               const sub_match<BiIter>& rhs);
3340b57cec5SDimitry Andric
33506c3fb27SDimitry Andrictemplate <class BiIter>                                                      // Removed in C++20
3360b57cec5SDimitry Andric    bool
3370b57cec5SDimitry Andric    operator!=(typename iterator_traits<BiIter>::value_type const* lhs,
3380b57cec5SDimitry Andric               const sub_match<BiIter>& rhs);
3390b57cec5SDimitry Andric
34006c3fb27SDimitry Andrictemplate <class BiIter>                                                      // Removed in C++20
3410b57cec5SDimitry Andric    bool
3420b57cec5SDimitry Andric    operator<(typename iterator_traits<BiIter>::value_type const* lhs,
3430b57cec5SDimitry Andric              const sub_match<BiIter>& rhs);
3440b57cec5SDimitry Andric
34506c3fb27SDimitry Andrictemplate <class BiIter>                                                      // Removed in C++20
3460b57cec5SDimitry Andric    bool
3470b57cec5SDimitry Andric    operator>(typename iterator_traits<BiIter>::value_type const* lhs,
3480b57cec5SDimitry Andric              const sub_match<BiIter>& rhs);
3490b57cec5SDimitry Andric
35006c3fb27SDimitry Andrictemplate <class BiIter>                                                      // Removed in C++20
3510b57cec5SDimitry Andric    bool
3520b57cec5SDimitry Andric    operator>=(typename iterator_traits<BiIter>::value_type const* lhs,
3530b57cec5SDimitry Andric               const sub_match<BiIter>& rhs);
3540b57cec5SDimitry Andric
35506c3fb27SDimitry Andrictemplate <class BiIter>                                                      // Removed in C++20
3560b57cec5SDimitry Andric    bool
3570b57cec5SDimitry Andric    operator<=(typename iterator_traits<BiIter>::value_type const* lhs,
3580b57cec5SDimitry Andric               const sub_match<BiIter>& rhs);
3590b57cec5SDimitry Andric
3600b57cec5SDimitry Andrictemplate <class BiIter>
3610b57cec5SDimitry Andric    bool
3620b57cec5SDimitry Andric    operator==(const sub_match<BiIter>& lhs,
3630b57cec5SDimitry Andric               typename iterator_traits<BiIter>::value_type const* rhs);
3640b57cec5SDimitry Andric
36506c3fb27SDimitry Andrictemplate <class BiIter>                                                      // Since C++20
36606c3fb27SDimitry Andric    auto
36706c3fb27SDimitry Andric    operator<=>(const sub_match<BiIter>& lhs,
36806c3fb27SDimitry Andric                typename iterator_traits<BiIter>::value_type const* rhs);
36906c3fb27SDimitry Andric
37006c3fb27SDimitry Andrictemplate <class BiIter, class ST, class SA>                                  // Removed in C++20
3710b57cec5SDimitry Andric    bool
3720b57cec5SDimitry Andric    operator!=(const sub_match<BiIter>& lhs,
3730b57cec5SDimitry Andric               typename iterator_traits<BiIter>::value_type const* rhs);
3740b57cec5SDimitry Andric
37506c3fb27SDimitry Andrictemplate <class BiIter>                                                      // Removed in C++20
3760b57cec5SDimitry Andric    bool
3770b57cec5SDimitry Andric    operator<(const sub_match<BiIter>& lhs,
3780b57cec5SDimitry Andric              typename iterator_traits<BiIter>::value_type const* rhs);
3790b57cec5SDimitry Andric
38006c3fb27SDimitry Andrictemplate <class BiIter>                                                      // Removed in C++20
3810b57cec5SDimitry Andric    bool
3820b57cec5SDimitry Andric    operator>(const sub_match<BiIter>& lhs,
3830b57cec5SDimitry Andric              typename iterator_traits<BiIter>::value_type const* rhs);
3840b57cec5SDimitry Andric
38506c3fb27SDimitry Andrictemplate <class BiIter>                                                      // Removed in C++20
3860b57cec5SDimitry Andric    bool
3870b57cec5SDimitry Andric    operator>=(const sub_match<BiIter>& lhs,
3880b57cec5SDimitry Andric               typename iterator_traits<BiIter>::value_type const* rhs);
3890b57cec5SDimitry Andric
39006c3fb27SDimitry Andrictemplate <class BiIter>                                                      // Removed in C++20
3910b57cec5SDimitry Andric    bool
3920b57cec5SDimitry Andric    operator<=(const sub_match<BiIter>& lhs,
3930b57cec5SDimitry Andric               typename iterator_traits<BiIter>::value_type const* rhs);
3940b57cec5SDimitry Andric
39506c3fb27SDimitry Andrictemplate <class BiIter>                                                      // Removed in C++20
3960b57cec5SDimitry Andric    bool
3970b57cec5SDimitry Andric    operator==(typename iterator_traits<BiIter>::value_type const& lhs,
3980b57cec5SDimitry Andric               const sub_match<BiIter>& rhs);
3990b57cec5SDimitry Andric
40006c3fb27SDimitry Andrictemplate <class BiIter>                                                      // Removed in C++20
4010b57cec5SDimitry Andric    bool
4020b57cec5SDimitry Andric    operator!=(typename iterator_traits<BiIter>::value_type const& lhs,
4030b57cec5SDimitry Andric               const sub_match<BiIter>& rhs);
4040b57cec5SDimitry Andric
40506c3fb27SDimitry Andrictemplate <class BiIter>                                                      // Removed in C++20
4060b57cec5SDimitry Andric    bool
4070b57cec5SDimitry Andric    operator<(typename iterator_traits<BiIter>::value_type const& lhs,
4080b57cec5SDimitry Andric              const sub_match<BiIter>& rhs);
4090b57cec5SDimitry Andric
41006c3fb27SDimitry Andrictemplate <class BiIter>                                                      // Removed in C++20
4110b57cec5SDimitry Andric    bool
4120b57cec5SDimitry Andric    operator>(typename iterator_traits<BiIter>::value_type const& lhs,
4130b57cec5SDimitry Andric              const sub_match<BiIter>& rhs);
4140b57cec5SDimitry Andric
41506c3fb27SDimitry Andrictemplate <class BiIter>                                                      // Removed in C++20
4160b57cec5SDimitry Andric    bool
4170b57cec5SDimitry Andric    operator>=(typename iterator_traits<BiIter>::value_type const& lhs,
4180b57cec5SDimitry Andric               const sub_match<BiIter>& rhs);
4190b57cec5SDimitry Andric
42006c3fb27SDimitry Andrictemplate <class BiIter>                                                      // Removed in C++20
4210b57cec5SDimitry Andric    bool
4220b57cec5SDimitry Andric    operator<=(typename iterator_traits<BiIter>::value_type const& lhs,
4230b57cec5SDimitry Andric               const sub_match<BiIter>& rhs);
4240b57cec5SDimitry Andric
4250b57cec5SDimitry Andrictemplate <class BiIter>
4260b57cec5SDimitry Andric    bool
4270b57cec5SDimitry Andric    operator==(const sub_match<BiIter>& lhs,
4280b57cec5SDimitry Andric               typename iterator_traits<BiIter>::value_type const& rhs);
4290b57cec5SDimitry Andric
43006c3fb27SDimitry Andrictemplate <class BiIter>                                                      // Since C++20
43106c3fb27SDimitry Andric    auto
43206c3fb27SDimitry Andric    operator<=>(const sub_match<BiIter>& lhs,
43306c3fb27SDimitry Andric                typename iterator_traits<BiIter>::value_type const& rhs);
43406c3fb27SDimitry Andric
43506c3fb27SDimitry Andrictemplate <class BiIter>                                                      // Removed in C++20
4360b57cec5SDimitry Andric    bool
4370b57cec5SDimitry Andric    operator!=(const sub_match<BiIter>& lhs,
4380b57cec5SDimitry Andric               typename iterator_traits<BiIter>::value_type const& rhs);
4390b57cec5SDimitry Andric
44006c3fb27SDimitry Andrictemplate <class BiIter>                                                      // Removed in C++20
4410b57cec5SDimitry Andric    bool
4420b57cec5SDimitry Andric    operator<(const sub_match<BiIter>& lhs,
4430b57cec5SDimitry Andric              typename iterator_traits<BiIter>::value_type const& rhs);
4440b57cec5SDimitry Andric
44506c3fb27SDimitry Andrictemplate <class BiIter>                                                      // Removed in C++20
4460b57cec5SDimitry Andric    bool
4470b57cec5SDimitry Andric    operator>(const sub_match<BiIter>& lhs,
4480b57cec5SDimitry Andric              typename iterator_traits<BiIter>::value_type const& rhs);
4490b57cec5SDimitry Andric
45006c3fb27SDimitry Andrictemplate <class BiIter>                                                      // Removed in C++20
4510b57cec5SDimitry Andric    bool
4520b57cec5SDimitry Andric    operator>=(const sub_match<BiIter>& lhs,
4530b57cec5SDimitry Andric               typename iterator_traits<BiIter>::value_type const& rhs);
4540b57cec5SDimitry Andric
45506c3fb27SDimitry Andrictemplate <class BiIter>                                                      // Removed in C++20
4560b57cec5SDimitry Andric    bool
4570b57cec5SDimitry Andric    operator<=(const sub_match<BiIter>& lhs,
4580b57cec5SDimitry Andric               typename iterator_traits<BiIter>::value_type const& rhs);
4590b57cec5SDimitry Andric
4600b57cec5SDimitry Andrictemplate <class charT, class ST, class BiIter>
4610b57cec5SDimitry Andric    basic_ostream<charT, ST>&
4620b57cec5SDimitry Andric    operator<<(basic_ostream<charT, ST>& os, const sub_match<BiIter>& m);
4630b57cec5SDimitry Andric
4640b57cec5SDimitry Andrictemplate <class BidirectionalIterator,
4650b57cec5SDimitry Andric          class Allocator = allocator<sub_match<BidirectionalIterator>>>
4660b57cec5SDimitry Andricclass match_results
4670b57cec5SDimitry Andric{
4680b57cec5SDimitry Andricpublic:
4690b57cec5SDimitry Andric    typedef sub_match<BidirectionalIterator>                  value_type;
4700b57cec5SDimitry Andric    typedef const value_type&                                 const_reference;
4710b57cec5SDimitry Andric    typedef value_type&                                       reference;
4720b57cec5SDimitry Andric    typedef /implementation-defined/                          const_iterator;
4730b57cec5SDimitry Andric    typedef const_iterator                                    iterator;
4740b57cec5SDimitry Andric    typedef typename iterator_traits<BidirectionalIterator>::difference_type difference_type;
4750b57cec5SDimitry Andric    typedef typename allocator_traits<Allocator>::size_type   size_type;
4760b57cec5SDimitry Andric    typedef Allocator                                         allocator_type;
4770b57cec5SDimitry Andric    typedef typename iterator_traits<BidirectionalIterator>::value_type char_type;
4780b57cec5SDimitry Andric    typedef basic_string<char_type>                           string_type;
4790b57cec5SDimitry Andric
4800b57cec5SDimitry Andric    // construct/copy/destroy:
481e8d8bef9SDimitry Andric    explicit match_results(const Allocator& a = Allocator()); // before C++20
482e8d8bef9SDimitry Andric    match_results() : match_results(Allocator()) {}           // C++20
483e8d8bef9SDimitry Andric    explicit match_results(const Allocator& a);               // C++20
4840b57cec5SDimitry Andric    match_results(const match_results& m);
4850b57cec5SDimitry Andric    match_results(match_results&& m) noexcept;
4860b57cec5SDimitry Andric    match_results& operator=(const match_results& m);
4870b57cec5SDimitry Andric    match_results& operator=(match_results&& m);
4880b57cec5SDimitry Andric    ~match_results();
4890b57cec5SDimitry Andric
4900b57cec5SDimitry Andric    bool ready() const;
4910b57cec5SDimitry Andric
4920b57cec5SDimitry Andric    // size:
4930b57cec5SDimitry Andric    size_type size() const;
4940b57cec5SDimitry Andric    size_type max_size() const;
4950b57cec5SDimitry Andric    bool empty() const;
4960b57cec5SDimitry Andric
4970b57cec5SDimitry Andric    // element access:
4980b57cec5SDimitry Andric    difference_type length(size_type sub = 0) const;
4990b57cec5SDimitry Andric    difference_type position(size_type sub = 0) const;
5000b57cec5SDimitry Andric    string_type str(size_type sub = 0) const;
5010b57cec5SDimitry Andric    const_reference operator[](size_type n) const;
5020b57cec5SDimitry Andric
5030b57cec5SDimitry Andric    const_reference prefix() const;
5040b57cec5SDimitry Andric    const_reference suffix() const;
5050b57cec5SDimitry Andric
5060b57cec5SDimitry Andric    const_iterator begin() const;
5070b57cec5SDimitry Andric    const_iterator end() const;
5080b57cec5SDimitry Andric    const_iterator cbegin() const;
5090b57cec5SDimitry Andric    const_iterator cend() const;
5100b57cec5SDimitry Andric
5110b57cec5SDimitry Andric    // format:
5120b57cec5SDimitry Andric    template <class OutputIter>
5130b57cec5SDimitry Andric        OutputIter
5140b57cec5SDimitry Andric        format(OutputIter out, const char_type* fmt_first,
5150b57cec5SDimitry Andric               const char_type* fmt_last,
5160b57cec5SDimitry Andric               regex_constants::match_flag_type flags = regex_constants::format_default) const;
5170b57cec5SDimitry Andric    template <class OutputIter, class ST, class SA>
5180b57cec5SDimitry Andric        OutputIter
5190b57cec5SDimitry Andric        format(OutputIter out, const basic_string<char_type, ST, SA>& fmt,
5200b57cec5SDimitry Andric               regex_constants::match_flag_type flags = regex_constants::format_default) const;
5210b57cec5SDimitry Andric    template <class ST, class SA>
5220b57cec5SDimitry Andric        basic_string<char_type, ST, SA>
5230b57cec5SDimitry Andric        format(const basic_string<char_type, ST, SA>& fmt,
5240b57cec5SDimitry Andric               regex_constants::match_flag_type flags = regex_constants::format_default) const;
5250b57cec5SDimitry Andric    string_type
5260b57cec5SDimitry Andric        format(const char_type* fmt,
5270b57cec5SDimitry Andric               regex_constants::match_flag_type flags = regex_constants::format_default) const;
5280b57cec5SDimitry Andric
5290b57cec5SDimitry Andric    // allocator:
5300b57cec5SDimitry Andric    allocator_type get_allocator() const;
5310b57cec5SDimitry Andric
5320b57cec5SDimitry Andric    // swap:
5330b57cec5SDimitry Andric    void swap(match_results& that);
5340b57cec5SDimitry Andric};
5350b57cec5SDimitry Andric
5360b57cec5SDimitry Andrictypedef match_results<const char*>             cmatch;
5370b57cec5SDimitry Andrictypedef match_results<const wchar_t*>          wcmatch;
5380b57cec5SDimitry Andrictypedef match_results<string::const_iterator>  smatch;
5390b57cec5SDimitry Andrictypedef match_results<wstring::const_iterator> wsmatch;
5400b57cec5SDimitry Andric
5410b57cec5SDimitry Andrictemplate <class BidirectionalIterator, class Allocator>
5420b57cec5SDimitry Andric    bool
5430b57cec5SDimitry Andric    operator==(const match_results<BidirectionalIterator, Allocator>& m1,
5440b57cec5SDimitry Andric               const match_results<BidirectionalIterator, Allocator>& m2);
5450b57cec5SDimitry Andric
54606c3fb27SDimitry Andrictemplate <class BidirectionalIterator, class Allocator>                    // Removed in C++20
5470b57cec5SDimitry Andric    bool
5480b57cec5SDimitry Andric    operator!=(const match_results<BidirectionalIterator, Allocator>& m1,
5490b57cec5SDimitry Andric               const match_results<BidirectionalIterator, Allocator>& m2);
5500b57cec5SDimitry Andric
5510b57cec5SDimitry Andrictemplate <class BidirectionalIterator, class Allocator>
5520b57cec5SDimitry Andric    void
5530b57cec5SDimitry Andric    swap(match_results<BidirectionalIterator, Allocator>& m1,
5540b57cec5SDimitry Andric         match_results<BidirectionalIterator, Allocator>& m2);
5550b57cec5SDimitry Andric
5560b57cec5SDimitry Andrictemplate <class BidirectionalIterator, class Allocator, class charT, class traits>
5570b57cec5SDimitry Andric    bool
5580b57cec5SDimitry Andric    regex_match(BidirectionalIterator first, BidirectionalIterator last,
5590b57cec5SDimitry Andric                match_results<BidirectionalIterator, Allocator>& m,
5600b57cec5SDimitry Andric                const basic_regex<charT, traits>& e,
5610b57cec5SDimitry Andric                regex_constants::match_flag_type flags = regex_constants::match_default);
5620b57cec5SDimitry Andric
5630b57cec5SDimitry Andrictemplate <class BidirectionalIterator, class charT, class traits>
5640b57cec5SDimitry Andric    bool
5650b57cec5SDimitry Andric    regex_match(BidirectionalIterator first, BidirectionalIterator last,
5660b57cec5SDimitry Andric                const basic_regex<charT, traits>& e,
5670b57cec5SDimitry Andric                regex_constants::match_flag_type flags = regex_constants::match_default);
5680b57cec5SDimitry Andric
5690b57cec5SDimitry Andrictemplate <class charT, class Allocator, class traits>
5700b57cec5SDimitry Andric    bool
5710b57cec5SDimitry Andric    regex_match(const charT* str, match_results<const charT*, Allocator>& m,
5720b57cec5SDimitry Andric                const basic_regex<charT, traits>& e,
5730b57cec5SDimitry Andric                regex_constants::match_flag_type flags = regex_constants::match_default);
5740b57cec5SDimitry Andric
5750b57cec5SDimitry Andrictemplate <class ST, class SA, class Allocator, class charT, class traits>
5760b57cec5SDimitry Andric    bool
5770b57cec5SDimitry Andric    regex_match(const basic_string<charT, ST, SA>& s,
5780b57cec5SDimitry Andric                match_results<typename basic_string<charT, ST, SA>::const_iterator, Allocator>& m,
5790b57cec5SDimitry Andric                const basic_regex<charT, traits>& e,
5800b57cec5SDimitry Andric                regex_constants::match_flag_type flags = regex_constants::match_default);
5810b57cec5SDimitry Andric
5820b57cec5SDimitry Andrictemplate <class ST, class SA, class Allocator, class charT, class traits>
5830b57cec5SDimitry Andric    bool
5840b57cec5SDimitry Andric    regex_match(const basic_string<charT, ST, SA>&& s,
5850b57cec5SDimitry Andric                match_results<typename basic_string<charT, ST, SA>::const_iterator, Allocator>& m,
5860b57cec5SDimitry Andric                const basic_regex<charT, traits>& e,
5870b57cec5SDimitry Andric                regex_constants::match_flag_type flags = regex_constants::match_default) = delete; // C++14
5880b57cec5SDimitry Andric
5890b57cec5SDimitry Andrictemplate <class charT, class traits>
5900b57cec5SDimitry Andric    bool
5910b57cec5SDimitry Andric    regex_match(const charT* str, const basic_regex<charT, traits>& e,
5920b57cec5SDimitry Andric                regex_constants::match_flag_type flags = regex_constants::match_default);
5930b57cec5SDimitry Andric
5940b57cec5SDimitry Andrictemplate <class ST, class SA, class charT, class traits>
5950b57cec5SDimitry Andric    bool
5960b57cec5SDimitry Andric    regex_match(const basic_string<charT, ST, SA>& s,
5970b57cec5SDimitry Andric                const basic_regex<charT, traits>& e,
5980b57cec5SDimitry Andric                regex_constants::match_flag_type flags = regex_constants::match_default);
5990b57cec5SDimitry Andric
6000b57cec5SDimitry Andrictemplate <class BidirectionalIterator, class Allocator, class charT, class traits>
6010b57cec5SDimitry Andric    bool
6020b57cec5SDimitry Andric    regex_search(BidirectionalIterator first, BidirectionalIterator last,
6030b57cec5SDimitry Andric                 match_results<BidirectionalIterator, Allocator>& m,
6040b57cec5SDimitry Andric                 const basic_regex<charT, traits>& e,
6050b57cec5SDimitry Andric                 regex_constants::match_flag_type flags = regex_constants::match_default);
6060b57cec5SDimitry Andric
6070b57cec5SDimitry Andrictemplate <class BidirectionalIterator, class charT, class traits>
6080b57cec5SDimitry Andric    bool
6090b57cec5SDimitry Andric    regex_search(BidirectionalIterator first, BidirectionalIterator last,
6100b57cec5SDimitry Andric                 const basic_regex<charT, traits>& e,
6110b57cec5SDimitry Andric                 regex_constants::match_flag_type flags = regex_constants::match_default);
6120b57cec5SDimitry Andric
6130b57cec5SDimitry Andrictemplate <class charT, class Allocator, class traits>
6140b57cec5SDimitry Andric    bool
6150b57cec5SDimitry Andric    regex_search(const charT* str, match_results<const charT*, Allocator>& m,
6160b57cec5SDimitry Andric                 const basic_regex<charT, traits>& e,
6170b57cec5SDimitry Andric                 regex_constants::match_flag_type flags = regex_constants::match_default);
6180b57cec5SDimitry Andric
6190b57cec5SDimitry Andrictemplate <class charT, class traits>
6200b57cec5SDimitry Andric    bool
6210b57cec5SDimitry Andric    regex_search(const charT* str, const basic_regex<charT, traits>& e,
6220b57cec5SDimitry Andric                 regex_constants::match_flag_type flags = regex_constants::match_default);
6230b57cec5SDimitry Andric
6240b57cec5SDimitry Andrictemplate <class ST, class SA, class charT, class traits>
6250b57cec5SDimitry Andric    bool
6260b57cec5SDimitry Andric    regex_search(const basic_string<charT, ST, SA>& s,
6270b57cec5SDimitry Andric                 const basic_regex<charT, traits>& e,
6280b57cec5SDimitry Andric                 regex_constants::match_flag_type flags = regex_constants::match_default);
6290b57cec5SDimitry Andric
6300b57cec5SDimitry Andrictemplate <class ST, class SA, class Allocator, class charT, class traits>
6310b57cec5SDimitry Andric    bool
6320b57cec5SDimitry Andric    regex_search(const basic_string<charT, ST, SA>& s,
6330b57cec5SDimitry Andric                 match_results<typename basic_string<charT, ST, SA>::const_iterator, Allocator>& m,
6340b57cec5SDimitry Andric                 const basic_regex<charT, traits>& e,
6350b57cec5SDimitry Andric                 regex_constants::match_flag_type flags = regex_constants::match_default);
6360b57cec5SDimitry Andric
6370b57cec5SDimitry Andrictemplate <class ST, class SA, class Allocator, class charT, class traits>
6380b57cec5SDimitry Andric    bool
6390b57cec5SDimitry Andric    regex_search(const basic_string<charT, ST, SA>&& s,
6400b57cec5SDimitry Andric                 match_results<typename basic_string<charT, ST, SA>::const_iterator, Allocator>& m,
6410b57cec5SDimitry Andric                 const basic_regex<charT, traits>& e,
6420b57cec5SDimitry Andric                 regex_constants::match_flag_type flags = regex_constants::match_default) = delete; // C++14
6430b57cec5SDimitry Andric
6440b57cec5SDimitry Andrictemplate <class OutputIterator, class BidirectionalIterator,
6450b57cec5SDimitry Andric          class traits, class charT, class ST, class SA>
6460b57cec5SDimitry Andric    OutputIterator
6470b57cec5SDimitry Andric    regex_replace(OutputIterator out,
6480b57cec5SDimitry Andric                  BidirectionalIterator first, BidirectionalIterator last,
6490b57cec5SDimitry Andric                  const basic_regex<charT, traits>& e,
6500b57cec5SDimitry Andric                  const basic_string<charT, ST, SA>& fmt,
6510b57cec5SDimitry Andric                  regex_constants::match_flag_type flags = regex_constants::match_default);
6520b57cec5SDimitry Andric
6530b57cec5SDimitry Andrictemplate <class OutputIterator, class BidirectionalIterator,
6540b57cec5SDimitry Andric          class traits, class charT>
6550b57cec5SDimitry Andric    OutputIterator
6560b57cec5SDimitry Andric    regex_replace(OutputIterator out,
6570b57cec5SDimitry Andric                  BidirectionalIterator first, BidirectionalIterator last,
6580b57cec5SDimitry Andric                  const basic_regex<charT, traits>& e, const charT* fmt,
6590b57cec5SDimitry Andric                  regex_constants::match_flag_type flags = regex_constants::match_default);
6600b57cec5SDimitry Andric
6615ffd83dbSDimitry Andrictemplate <class traits, class charT, class ST, class SA, class FST, class FSA>
6620b57cec5SDimitry Andric    basic_string<charT, ST, SA>
6630b57cec5SDimitry Andric    regex_replace(const basic_string<charT, ST, SA>& s,
6640b57cec5SDimitry Andric                  const basic_regex<charT, traits>& e,
6650b57cec5SDimitry Andric                  const basic_string<charT, FST, FSA>& fmt,
6660b57cec5SDimitry Andric                  regex_constants::match_flag_type flags = regex_constants::match_default);
6670b57cec5SDimitry Andric
6680b57cec5SDimitry Andrictemplate <class traits, class charT, class ST, class SA>
6690b57cec5SDimitry Andric    basic_string<charT, ST, SA>
6700b57cec5SDimitry Andric    regex_replace(const basic_string<charT, ST, SA>& s,
6710b57cec5SDimitry Andric                  const basic_regex<charT, traits>& e, const charT* fmt,
6720b57cec5SDimitry Andric                  regex_constants::match_flag_type flags = regex_constants::match_default);
6730b57cec5SDimitry Andric
6740b57cec5SDimitry Andrictemplate <class traits, class charT, class ST, class SA>
6750b57cec5SDimitry Andric    basic_string<charT>
6760b57cec5SDimitry Andric    regex_replace(const charT* s,
6770b57cec5SDimitry Andric                  const basic_regex<charT, traits>& e,
6780b57cec5SDimitry Andric                  const basic_string<charT, ST, SA>& fmt,
6790b57cec5SDimitry Andric                  regex_constants::match_flag_type flags = regex_constants::match_default);
6800b57cec5SDimitry Andric
6810b57cec5SDimitry Andrictemplate <class traits, class charT>
6820b57cec5SDimitry Andric    basic_string<charT>
6830b57cec5SDimitry Andric    regex_replace(const charT* s,
6840b57cec5SDimitry Andric                  const basic_regex<charT, traits>& e,
6850b57cec5SDimitry Andric                  const charT* fmt,
6860b57cec5SDimitry Andric                  regex_constants::match_flag_type flags = regex_constants::match_default);
6870b57cec5SDimitry Andric
6880b57cec5SDimitry Andrictemplate <class BidirectionalIterator,
6890b57cec5SDimitry Andric          class charT = typename iterator_traits< BidirectionalIterator>::value_type,
6900b57cec5SDimitry Andric          class traits = regex_traits<charT>>
6910b57cec5SDimitry Andricclass regex_iterator
6920b57cec5SDimitry Andric{
6930b57cec5SDimitry Andricpublic:
6940b57cec5SDimitry Andric    typedef basic_regex<charT, traits>           regex_type;
6950b57cec5SDimitry Andric    typedef match_results<BidirectionalIterator> value_type;
6960b57cec5SDimitry Andric    typedef ptrdiff_t                            difference_type;
6970b57cec5SDimitry Andric    typedef const value_type*                    pointer;
6980b57cec5SDimitry Andric    typedef const value_type&                    reference;
6990b57cec5SDimitry Andric    typedef forward_iterator_tag                 iterator_category;
7005f757f3fSDimitry Andric    typedef input_iterator_tag                   iterator_concept; // since C++20
7010b57cec5SDimitry Andric
7020b57cec5SDimitry Andric    regex_iterator();
7030b57cec5SDimitry Andric    regex_iterator(BidirectionalIterator a, BidirectionalIterator b,
7040b57cec5SDimitry Andric                   const regex_type& re,
7050b57cec5SDimitry Andric                   regex_constants::match_flag_type m = regex_constants::match_default);
7065ffd83dbSDimitry Andric    regex_iterator(BidirectionalIterator a, BidirectionalIterator b,
7075ffd83dbSDimitry Andric                   const regex_type&& re,
7085ffd83dbSDimitry Andric                   regex_constants::match_flag_type m
7090b57cec5SDimitry Andric                                     = regex_constants::match_default) = delete; // C++14
7100b57cec5SDimitry Andric    regex_iterator(const regex_iterator&);
7110b57cec5SDimitry Andric    regex_iterator& operator=(const regex_iterator&);
7120b57cec5SDimitry Andric
7130b57cec5SDimitry Andric    bool operator==(const regex_iterator&) const;
71406c3fb27SDimitry Andric    bool operator==(default_sentinel_t) const { return *this == regex_iterator(); } // since C++20
71506c3fb27SDimitry Andric    bool operator!=(const regex_iterator&) const;                                   // Removed in C++20
7160b57cec5SDimitry Andric
7170b57cec5SDimitry Andric    const value_type& operator*() const;
7180b57cec5SDimitry Andric    const value_type* operator->() const;
7190b57cec5SDimitry Andric
7200b57cec5SDimitry Andric    regex_iterator& operator++();
7210b57cec5SDimitry Andric    regex_iterator operator++(int);
7220b57cec5SDimitry Andric};
7230b57cec5SDimitry Andric
7240b57cec5SDimitry Andrictypedef regex_iterator<const char*>             cregex_iterator;
7250b57cec5SDimitry Andrictypedef regex_iterator<const wchar_t*>          wcregex_iterator;
7260b57cec5SDimitry Andrictypedef regex_iterator<string::const_iterator>  sregex_iterator;
7270b57cec5SDimitry Andrictypedef regex_iterator<wstring::const_iterator> wsregex_iterator;
7280b57cec5SDimitry Andric
7290b57cec5SDimitry Andrictemplate <class BidirectionalIterator,
7300b57cec5SDimitry Andric          class charT = typename iterator_traits<BidirectionalIterator>::value_type,
7310b57cec5SDimitry Andric          class traits = regex_traits<charT>>
7320b57cec5SDimitry Andricclass regex_token_iterator
7330b57cec5SDimitry Andric{
7340b57cec5SDimitry Andricpublic:
7350b57cec5SDimitry Andric    typedef basic_regex<charT, traits>       regex_type;
7360b57cec5SDimitry Andric    typedef sub_match<BidirectionalIterator> value_type;
7370b57cec5SDimitry Andric    typedef ptrdiff_t                        difference_type;
7380b57cec5SDimitry Andric    typedef const value_type*                pointer;
7390b57cec5SDimitry Andric    typedef const value_type&                reference;
7400b57cec5SDimitry Andric    typedef forward_iterator_tag             iterator_category;
7415f757f3fSDimitry Andric    typedef input_iterator_tag               iterator_concept; // since C++20
7420b57cec5SDimitry Andric
7430b57cec5SDimitry Andric    regex_token_iterator();
7440b57cec5SDimitry Andric    regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
7450b57cec5SDimitry Andric                         const regex_type& re, int submatch = 0,
7460b57cec5SDimitry Andric                         regex_constants::match_flag_type m = regex_constants::match_default);
7470b57cec5SDimitry Andric    regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
7480b57cec5SDimitry Andric                         const regex_type&& re, int submatch = 0,
7490b57cec5SDimitry Andric                         regex_constants::match_flag_type m = regex_constants::match_default) = delete; // C++14
7500b57cec5SDimitry Andric    regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
7510b57cec5SDimitry Andric                         const regex_type& re, const vector<int>& submatches,
7520b57cec5SDimitry Andric                         regex_constants::match_flag_type m = regex_constants::match_default);
7530b57cec5SDimitry Andric    regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
7540b57cec5SDimitry Andric                         const regex_type&& re, const vector<int>& submatches,
7550b57cec5SDimitry Andric                         regex_constants::match_flag_type m = regex_constants::match_default) = delete; // C++14
7560b57cec5SDimitry Andric    regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
7570b57cec5SDimitry Andric                         const regex_type& re, initializer_list<int> submatches,
7580b57cec5SDimitry Andric                         regex_constants::match_flag_type m = regex_constants::match_default);
7590b57cec5SDimitry Andric    regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
7600b57cec5SDimitry Andric                         const regex_type&& re, initializer_list<int> submatches,
7610b57cec5SDimitry Andric                         regex_constants::match_flag_type m = regex_constants::match_default) = delete; // C++14
7620b57cec5SDimitry Andric    template <size_t N>
7630b57cec5SDimitry Andric        regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
7640b57cec5SDimitry Andric                             const regex_type& re, const int (&submatches)[N],
7650b57cec5SDimitry Andric                             regex_constants::match_flag_type m = regex_constants::match_default);
7660b57cec5SDimitry Andric    template <size_t N>
7670b57cec5SDimitry Andric        regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
7685ffd83dbSDimitry Andric                             const regex_type&& re, const int (&submatches)[N],
7695ffd83dbSDimitry Andric                             regex_constants::match_flag_type m = regex_constants::match_default) = delete; // C++14
7700b57cec5SDimitry Andric    regex_token_iterator(const regex_token_iterator&);
7710b57cec5SDimitry Andric    regex_token_iterator& operator=(const regex_token_iterator&);
7720b57cec5SDimitry Andric
7730b57cec5SDimitry Andric    bool operator==(const regex_token_iterator&) const;
77406c3fb27SDimitry Andric    bool operator==(default_sentinel_t) const { return *this == regex_token_iterator(); } // since C++20
77506c3fb27SDimitry Andric    bool operator!=(const regex_token_iterator&) const;                                   // Removed in C++20
7760b57cec5SDimitry Andric
7770b57cec5SDimitry Andric    const value_type& operator*() const;
7780b57cec5SDimitry Andric    const value_type* operator->() const;
7790b57cec5SDimitry Andric
7800b57cec5SDimitry Andric    regex_token_iterator& operator++();
7810b57cec5SDimitry Andric    regex_token_iterator operator++(int);
7820b57cec5SDimitry Andric};
7830b57cec5SDimitry Andric
7840b57cec5SDimitry Andrictypedef regex_token_iterator<const char*>             cregex_token_iterator;
7850b57cec5SDimitry Andrictypedef regex_token_iterator<const wchar_t*>          wcregex_token_iterator;
7860b57cec5SDimitry Andrictypedef regex_token_iterator<string::const_iterator>  sregex_token_iterator;
7870b57cec5SDimitry Andrictypedef regex_token_iterator<wstring::const_iterator> wsregex_token_iterator;
7880b57cec5SDimitry Andric
7890b57cec5SDimitry Andric} // std
7900b57cec5SDimitry Andric*/
7910b57cec5SDimitry Andric
79281ad6265SDimitry Andric#include <__algorithm/find.h>
79381ad6265SDimitry Andric#include <__algorithm/search.h>
794*0fca6ea1SDimitry Andric#include <__assert>
7950b57cec5SDimitry Andric#include <__config>
79681ad6265SDimitry Andric#include <__iterator/back_insert_iterator.h>
79706c3fb27SDimitry Andric#include <__iterator/default_sentinel.h>
798fe6060f1SDimitry Andric#include <__iterator/wrap_iter.h>
7990b57cec5SDimitry Andric#include <__locale>
80006c3fb27SDimitry Andric#include <__memory/shared_ptr.h>
801bdd1243dSDimitry Andric#include <__memory_resource/polymorphic_allocator.h>
80206c3fb27SDimitry Andric#include <__type_traits/is_swappable.h>
80381ad6265SDimitry Andric#include <__utility/move.h>
804bdd1243dSDimitry Andric#include <__utility/pair.h>
80581ad6265SDimitry Andric#include <__utility/swap.h>
80606c3fb27SDimitry Andric#include <__verbose_abort>
8070b57cec5SDimitry Andric#include <deque>
808fe6060f1SDimitry Andric#include <stdexcept>
809fe6060f1SDimitry Andric#include <string>
810fe6060f1SDimitry Andric#include <vector>
8110b57cec5SDimitry Andric#include <version>
8120b57cec5SDimitry Andric
81381ad6265SDimitry Andric// standard-mandated includes
81481ad6265SDimitry Andric
81581ad6265SDimitry Andric// [iterator.range]
81681ad6265SDimitry Andric#include <__iterator/access.h>
81781ad6265SDimitry Andric#include <__iterator/data.h>
81881ad6265SDimitry Andric#include <__iterator/empty.h>
81981ad6265SDimitry Andric#include <__iterator/reverse_access.h>
82081ad6265SDimitry Andric#include <__iterator/size.h>
82181ad6265SDimitry Andric
82281ad6265SDimitry Andric// [re.syn]
82381ad6265SDimitry Andric#include <compare>
82481ad6265SDimitry Andric#include <initializer_list>
82581ad6265SDimitry Andric
8260b57cec5SDimitry Andric#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
8270b57cec5SDimitry Andric#  pragma GCC system_header
8280b57cec5SDimitry Andric#endif
8290b57cec5SDimitry Andric
8300b57cec5SDimitry Andric_LIBCPP_PUSH_MACROS
8310b57cec5SDimitry Andric#include <__undef_macros>
8320b57cec5SDimitry Andric
8330b57cec5SDimitry Andric#define _LIBCPP_REGEX_COMPLEXITY_FACTOR 4096
8340b57cec5SDimitry Andric
8350b57cec5SDimitry Andric_LIBCPP_BEGIN_NAMESPACE_STD
8360b57cec5SDimitry Andric
837cb14a3feSDimitry Andricnamespace regex_constants {
8380b57cec5SDimitry Andric
8390b57cec5SDimitry Andric// syntax_option_type
8400b57cec5SDimitry Andric
841cb14a3feSDimitry Andricenum syntax_option_type {
8420b57cec5SDimitry Andric  icase    = 1 << 0,
8430b57cec5SDimitry Andric  nosubs   = 1 << 1,
8440b57cec5SDimitry Andric  optimize = 1 << 2,
8450b57cec5SDimitry Andric  collate  = 1 << 3,
8460b57cec5SDimitry Andric#ifdef _LIBCPP_ABI_REGEX_CONSTANTS_NONZERO
8470b57cec5SDimitry Andric  ECMAScript = 1 << 9,
8480b57cec5SDimitry Andric#else
8490b57cec5SDimitry Andric  ECMAScript = 0,
8500b57cec5SDimitry Andric#endif
8510b57cec5SDimitry Andric  basic    = 1 << 4,
8520b57cec5SDimitry Andric  extended = 1 << 5,
8530b57cec5SDimitry Andric  awk      = 1 << 6,
8540b57cec5SDimitry Andric  grep     = 1 << 7,
855e8d8bef9SDimitry Andric  egrep    = 1 << 8,
856e8d8bef9SDimitry Andric  // 1 << 9 may be used by ECMAScript
857e8d8bef9SDimitry Andric  multiline = 1 << 10
8580b57cec5SDimitry Andric};
8590b57cec5SDimitry Andric
860cb14a3feSDimitry Andric_LIBCPP_HIDE_FROM_ABI inline _LIBCPP_CONSTEXPR syntax_option_type __get_grammar(syntax_option_type __g) {
8610b57cec5SDimitry Andric#ifdef _LIBCPP_ABI_REGEX_CONSTANTS_NONZERO
8620b57cec5SDimitry Andric  return static_cast<syntax_option_type>(__g & 0x3F0);
8630b57cec5SDimitry Andric#else
8640b57cec5SDimitry Andric  return static_cast<syntax_option_type>(__g & 0x1F0);
8650b57cec5SDimitry Andric#endif
8660b57cec5SDimitry Andric}
8670b57cec5SDimitry Andric
868cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR syntax_option_type operator~(syntax_option_type __x) {
8690b57cec5SDimitry Andric  return syntax_option_type(~int(__x) & 0x1FF);
8700b57cec5SDimitry Andric}
8710b57cec5SDimitry Andric
872cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR syntax_option_type
873cb14a3feSDimitry Andricoperator&(syntax_option_type __x, syntax_option_type __y) {
8740b57cec5SDimitry Andric  return syntax_option_type(int(__x) & int(__y));
8750b57cec5SDimitry Andric}
8760b57cec5SDimitry Andric
877cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR syntax_option_type
878cb14a3feSDimitry Andricoperator|(syntax_option_type __x, syntax_option_type __y) {
8790b57cec5SDimitry Andric  return syntax_option_type(int(__x) | int(__y));
8800b57cec5SDimitry Andric}
8810b57cec5SDimitry Andric
882cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR syntax_option_type
883cb14a3feSDimitry Andricoperator^(syntax_option_type __x, syntax_option_type __y) {
8840b57cec5SDimitry Andric  return syntax_option_type(int(__x) ^ int(__y));
8850b57cec5SDimitry Andric}
8860b57cec5SDimitry Andric
887cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI syntax_option_type& operator&=(syntax_option_type& __x, syntax_option_type __y) {
8880b57cec5SDimitry Andric  __x = __x & __y;
8890b57cec5SDimitry Andric  return __x;
8900b57cec5SDimitry Andric}
8910b57cec5SDimitry Andric
892cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI syntax_option_type& operator|=(syntax_option_type& __x, syntax_option_type __y) {
8930b57cec5SDimitry Andric  __x = __x | __y;
8940b57cec5SDimitry Andric  return __x;
8950b57cec5SDimitry Andric}
8960b57cec5SDimitry Andric
897cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI syntax_option_type& operator^=(syntax_option_type& __x, syntax_option_type __y) {
8980b57cec5SDimitry Andric  __x = __x ^ __y;
8990b57cec5SDimitry Andric  return __x;
9000b57cec5SDimitry Andric}
9010b57cec5SDimitry Andric
9020b57cec5SDimitry Andric// match_flag_type
9030b57cec5SDimitry Andric
904cb14a3feSDimitry Andricenum match_flag_type {
9050b57cec5SDimitry Andric  match_default     = 0,
9060b57cec5SDimitry Andric  match_not_bol     = 1 << 0,
9070b57cec5SDimitry Andric  match_not_eol     = 1 << 1,
9080b57cec5SDimitry Andric  match_not_bow     = 1 << 2,
9090b57cec5SDimitry Andric  match_not_eow     = 1 << 3,
9100b57cec5SDimitry Andric  match_any         = 1 << 4,
9110b57cec5SDimitry Andric  match_not_null    = 1 << 5,
9120b57cec5SDimitry Andric  match_continuous  = 1 << 6,
9130b57cec5SDimitry Andric  match_prev_avail  = 1 << 7,
9140b57cec5SDimitry Andric  format_default    = 0,
9150b57cec5SDimitry Andric  format_sed        = 1 << 8,
9160b57cec5SDimitry Andric  format_no_copy    = 1 << 9,
9170b57cec5SDimitry Andric  format_first_only = 1 << 10,
9180b57cec5SDimitry Andric  __no_update_pos   = 1 << 11,
9190b57cec5SDimitry Andric  __full_match      = 1 << 12
9200b57cec5SDimitry Andric};
9210b57cec5SDimitry Andric
922cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR match_flag_type operator~(match_flag_type __x) {
9230b57cec5SDimitry Andric  return match_flag_type(~int(__x) & 0x0FFF);
9240b57cec5SDimitry Andric}
9250b57cec5SDimitry Andric
926cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR match_flag_type operator&(match_flag_type __x, match_flag_type __y) {
9270b57cec5SDimitry Andric  return match_flag_type(int(__x) & int(__y));
9280b57cec5SDimitry Andric}
9290b57cec5SDimitry Andric
930cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR match_flag_type operator|(match_flag_type __x, match_flag_type __y) {
9310b57cec5SDimitry Andric  return match_flag_type(int(__x) | int(__y));
9320b57cec5SDimitry Andric}
9330b57cec5SDimitry Andric
934cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR match_flag_type operator^(match_flag_type __x, match_flag_type __y) {
9350b57cec5SDimitry Andric  return match_flag_type(int(__x) ^ int(__y));
9360b57cec5SDimitry Andric}
9370b57cec5SDimitry Andric
938cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI match_flag_type& operator&=(match_flag_type& __x, match_flag_type __y) {
9390b57cec5SDimitry Andric  __x = __x & __y;
9400b57cec5SDimitry Andric  return __x;
9410b57cec5SDimitry Andric}
9420b57cec5SDimitry Andric
943cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI match_flag_type& operator|=(match_flag_type& __x, match_flag_type __y) {
9440b57cec5SDimitry Andric  __x = __x | __y;
9450b57cec5SDimitry Andric  return __x;
9460b57cec5SDimitry Andric}
9470b57cec5SDimitry Andric
948cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI match_flag_type& operator^=(match_flag_type& __x, match_flag_type __y) {
9490b57cec5SDimitry Andric  __x = __x ^ __y;
9500b57cec5SDimitry Andric  return __x;
9510b57cec5SDimitry Andric}
9520b57cec5SDimitry Andric
953cb14a3feSDimitry Andricenum error_type {
9540b57cec5SDimitry Andric  error_collate = 1,
9550b57cec5SDimitry Andric  error_ctype,
9560b57cec5SDimitry Andric  error_escape,
9570b57cec5SDimitry Andric  error_backref,
9580b57cec5SDimitry Andric  error_brack,
9590b57cec5SDimitry Andric  error_paren,
9600b57cec5SDimitry Andric  error_brace,
9610b57cec5SDimitry Andric  error_badbrace,
9620b57cec5SDimitry Andric  error_range,
9630b57cec5SDimitry Andric  error_space,
9640b57cec5SDimitry Andric  error_badrepeat,
9650b57cec5SDimitry Andric  error_complexity,
9660b57cec5SDimitry Andric  error_stack,
9670b57cec5SDimitry Andric  __re_err_grammar,
9680b57cec5SDimitry Andric  __re_err_empty,
969480093f4SDimitry Andric  __re_err_unknown,
970480093f4SDimitry Andric  __re_err_parse
9710b57cec5SDimitry Andric};
9720b57cec5SDimitry Andric
9730eae32dcSDimitry Andric} // namespace regex_constants
9740b57cec5SDimitry Andric
975cb14a3feSDimitry Andricclass _LIBCPP_EXPORTED_FROM_ABI regex_error : public runtime_error {
9760b57cec5SDimitry Andric  regex_constants::error_type __code_;
977cb14a3feSDimitry Andric
9780b57cec5SDimitry Andricpublic:
9790b57cec5SDimitry Andric  explicit regex_error(regex_constants::error_type __ecode);
98006c3fb27SDimitry Andric  _LIBCPP_HIDE_FROM_ABI regex_error(const regex_error&) _NOEXCEPT = default;
981bdd1243dSDimitry Andric  ~regex_error() _NOEXCEPT override;
982cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI regex_constants::error_type code() const { return __code_; }
9830b57cec5SDimitry Andric};
9840b57cec5SDimitry Andric
9850b57cec5SDimitry Andrictemplate <regex_constants::error_type _Ev>
986cb14a3feSDimitry Andric_LIBCPP_NORETURN inline _LIBCPP_HIDE_FROM_ABI void __throw_regex_error() {
98706c3fb27SDimitry Andric#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
9880b57cec5SDimitry Andric  throw regex_error(_Ev);
9890b57cec5SDimitry Andric#else
99006c3fb27SDimitry Andric  _LIBCPP_VERBOSE_ABORT("regex_error was thrown in -fno-exceptions mode");
9910b57cec5SDimitry Andric#endif
9920b57cec5SDimitry Andric}
9930b57cec5SDimitry Andric
9940b57cec5SDimitry Andrictemplate <class _CharT>
995cb14a3feSDimitry Andricstruct _LIBCPP_TEMPLATE_VIS regex_traits {
9960b57cec5SDimitry Andricpublic:
9970b57cec5SDimitry Andric  typedef _CharT char_type;
9980b57cec5SDimitry Andric  typedef basic_string<char_type> string_type;
9990b57cec5SDimitry Andric  typedef locale locale_type;
1000bdd1243dSDimitry Andric#if defined(__BIONIC__) || defined(_NEWLIB_VERSION)
10015ffd83dbSDimitry Andric  // Originally bionic's ctype_base used its own ctype masks because the
10025ffd83dbSDimitry Andric  // builtin ctype implementation wasn't in libc++ yet. Bionic's ctype mask
10035ffd83dbSDimitry Andric  // was only 8 bits wide and already saturated, so it used a wider type here
10045ffd83dbSDimitry Andric  // to make room for __regex_word (then a part of this class rather than
10055ffd83dbSDimitry Andric  // ctype_base). Bionic has since moved to the builtin ctype_base
10065ffd83dbSDimitry Andric  // implementation, but this was not updated to match. Since then Android has
10075ffd83dbSDimitry Andric  // needed to maintain a stable libc++ ABI, and this can't be changed without
10085ffd83dbSDimitry Andric  // an ABI break.
1009bdd1243dSDimitry Andric  // We also need this workaround for newlib since _NEWLIB_VERSION is not
1010bdd1243dSDimitry Andric  // defined yet inside __config, so we can't set the
1011bdd1243dSDimitry Andric  // _LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE macro. Additionally, newlib is
1012bdd1243dSDimitry Andric  // often used for space constrained environments, so it makes sense not to
1013bdd1243dSDimitry Andric  // duplicate the ctype table.
10145ffd83dbSDimitry Andric  typedef uint16_t char_class_type;
10155ffd83dbSDimitry Andric#else
10160b57cec5SDimitry Andric  typedef ctype_base::mask char_class_type;
10175ffd83dbSDimitry Andric#endif
10180b57cec5SDimitry Andric
10190b57cec5SDimitry Andric  static const char_class_type __regex_word = ctype_base::__regex_word;
1020cb14a3feSDimitry Andric
10210b57cec5SDimitry Andricprivate:
10220b57cec5SDimitry Andric  locale __loc_;
10230b57cec5SDimitry Andric  const ctype<char_type>* __ct_;
10240b57cec5SDimitry Andric  const collate<char_type>* __col_;
10250b57cec5SDimitry Andric
10260b57cec5SDimitry Andricpublic:
10270b57cec5SDimitry Andric  regex_traits();
10280b57cec5SDimitry Andric
1029cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI static size_t length(const char_type* __p) { return char_traits<char_type>::length(__p); }
1030cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI char_type translate(char_type __c) const { return __c; }
10310b57cec5SDimitry Andric  char_type translate_nocase(char_type __c) const;
10320b57cec5SDimitry Andric  template <class _ForwardIterator>
1033cb14a3feSDimitry Andric  string_type transform(_ForwardIterator __f, _ForwardIterator __l) const;
10340b57cec5SDimitry Andric  template <class _ForwardIterator>
1035cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI string_type transform_primary(_ForwardIterator __f, _ForwardIterator __l) const {
1036cb14a3feSDimitry Andric    return __transform_primary(__f, __l, char_type());
1037cb14a3feSDimitry Andric  }
10380b57cec5SDimitry Andric  template <class _ForwardIterator>
1039cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI string_type lookup_collatename(_ForwardIterator __f, _ForwardIterator __l) const {
1040cb14a3feSDimitry Andric    return __lookup_collatename(__f, __l, char_type());
1041cb14a3feSDimitry Andric  }
10420b57cec5SDimitry Andric  template <class _ForwardIterator>
1043cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI char_class_type
1044cb14a3feSDimitry Andric  lookup_classname(_ForwardIterator __f, _ForwardIterator __l, bool __icase = false) const {
1045cb14a3feSDimitry Andric    return __lookup_classname(__f, __l, __icase, char_type());
1046cb14a3feSDimitry Andric  }
10470b57cec5SDimitry Andric  bool isctype(char_type __c, char_class_type __m) const;
1048cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI int value(char_type __ch, int __radix) const { return __regex_traits_value(__ch, __radix); }
10490b57cec5SDimitry Andric  locale_type imbue(locale_type __l);
1050cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI locale_type getloc() const { return __loc_; }
10510b57cec5SDimitry Andric
10520b57cec5SDimitry Andricprivate:
10530b57cec5SDimitry Andric  void __init();
10540b57cec5SDimitry Andric
10550b57cec5SDimitry Andric  template <class _ForwardIterator>
1056cb14a3feSDimitry Andric  string_type __transform_primary(_ForwardIterator __f, _ForwardIterator __l, char) const;
1057349cc55cSDimitry Andric#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
10580b57cec5SDimitry Andric  template <class _ForwardIterator>
1059cb14a3feSDimitry Andric  string_type __transform_primary(_ForwardIterator __f, _ForwardIterator __l, wchar_t) const;
1060349cc55cSDimitry Andric#endif
10610b57cec5SDimitry Andric  template <class _ForwardIterator>
1062cb14a3feSDimitry Andric  string_type __lookup_collatename(_ForwardIterator __f, _ForwardIterator __l, char) const;
1063349cc55cSDimitry Andric#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
10640b57cec5SDimitry Andric  template <class _ForwardIterator>
1065cb14a3feSDimitry Andric  string_type __lookup_collatename(_ForwardIterator __f, _ForwardIterator __l, wchar_t) const;
1066349cc55cSDimitry Andric#endif
10670b57cec5SDimitry Andric  template <class _ForwardIterator>
1068cb14a3feSDimitry Andric  char_class_type __lookup_classname(_ForwardIterator __f, _ForwardIterator __l, bool __icase, char) const;
1069349cc55cSDimitry Andric#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
10700b57cec5SDimitry Andric  template <class _ForwardIterator>
1071cb14a3feSDimitry Andric  char_class_type __lookup_classname(_ForwardIterator __f, _ForwardIterator __l, bool __icase, wchar_t) const;
1072349cc55cSDimitry Andric#endif
10730b57cec5SDimitry Andric
10740b57cec5SDimitry Andric  static int __regex_traits_value(unsigned char __ch, int __radix);
1075cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI int __regex_traits_value(char __ch, int __radix) const {
1076cb14a3feSDimitry Andric    return __regex_traits_value(static_cast<unsigned char>(__ch), __radix);
1077cb14a3feSDimitry Andric  }
1078349cc55cSDimitry Andric#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
1079cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI int __regex_traits_value(wchar_t __ch, int __radix) const;
1080349cc55cSDimitry Andric#endif
10810b57cec5SDimitry Andric};
10820b57cec5SDimitry Andric
10830b57cec5SDimitry Andrictemplate <class _CharT>
1084cb14a3feSDimitry Andricconst typename regex_traits<_CharT>::char_class_type regex_traits<_CharT>::__regex_word;
10850b57cec5SDimitry Andric
10860b57cec5SDimitry Andrictemplate <class _CharT>
1087cb14a3feSDimitry Andricregex_traits<_CharT>::regex_traits() {
10880b57cec5SDimitry Andric  __init();
10890b57cec5SDimitry Andric}
10900b57cec5SDimitry Andric
10910b57cec5SDimitry Andrictemplate <class _CharT>
1092cb14a3feSDimitry Andrictypename regex_traits<_CharT>::char_type regex_traits<_CharT>::translate_nocase(char_type __c) const {
10930b57cec5SDimitry Andric  return __ct_->tolower(__c);
10940b57cec5SDimitry Andric}
10950b57cec5SDimitry Andric
10960b57cec5SDimitry Andrictemplate <class _CharT>
10970b57cec5SDimitry Andrictemplate <class _ForwardIterator>
10980b57cec5SDimitry Andrictypename regex_traits<_CharT>::string_type
1099cb14a3feSDimitry Andricregex_traits<_CharT>::transform(_ForwardIterator __f, _ForwardIterator __l) const {
11000b57cec5SDimitry Andric  string_type __s(__f, __l);
11010b57cec5SDimitry Andric  return __col_->transform(__s.data(), __s.data() + __s.size());
11020b57cec5SDimitry Andric}
11030b57cec5SDimitry Andric
11040b57cec5SDimitry Andrictemplate <class _CharT>
1105cb14a3feSDimitry Andricvoid regex_traits<_CharT>::__init() {
1106bdd1243dSDimitry Andric  __ct_  = &std::use_facet<ctype<char_type> >(__loc_);
1107bdd1243dSDimitry Andric  __col_ = &std::use_facet<collate<char_type> >(__loc_);
11080b57cec5SDimitry Andric}
11090b57cec5SDimitry Andric
11100b57cec5SDimitry Andrictemplate <class _CharT>
1111cb14a3feSDimitry Andrictypename regex_traits<_CharT>::locale_type regex_traits<_CharT>::imbue(locale_type __l) {
11120b57cec5SDimitry Andric  locale __r = __loc_;
11130b57cec5SDimitry Andric  __loc_     = __l;
11140b57cec5SDimitry Andric  __init();
11150b57cec5SDimitry Andric  return __r;
11160b57cec5SDimitry Andric}
11170b57cec5SDimitry Andric
11180b57cec5SDimitry Andric// transform_primary is very FreeBSD-specific
11190b57cec5SDimitry Andric
11200b57cec5SDimitry Andrictemplate <class _CharT>
11210b57cec5SDimitry Andrictemplate <class _ForwardIterator>
11220b57cec5SDimitry Andrictypename regex_traits<_CharT>::string_type
1123cb14a3feSDimitry Andricregex_traits<_CharT>::__transform_primary(_ForwardIterator __f, _ForwardIterator __l, char) const {
11240b57cec5SDimitry Andric  const string_type __s(__f, __l);
11250b57cec5SDimitry Andric  string_type __d = __col_->transform(__s.data(), __s.data() + __s.size());
1126cb14a3feSDimitry Andric  switch (__d.size()) {
11270b57cec5SDimitry Andric  case 1:
11280b57cec5SDimitry Andric    break;
11290b57cec5SDimitry Andric  case 12:
11300b57cec5SDimitry Andric    __d[11] = __d[3];
11310b57cec5SDimitry Andric    break;
11320b57cec5SDimitry Andric  default:
11330b57cec5SDimitry Andric    __d.clear();
11340b57cec5SDimitry Andric    break;
11350b57cec5SDimitry Andric  }
11360b57cec5SDimitry Andric  return __d;
11370b57cec5SDimitry Andric}
11380b57cec5SDimitry Andric
1139349cc55cSDimitry Andric#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
11400b57cec5SDimitry Andrictemplate <class _CharT>
11410b57cec5SDimitry Andrictemplate <class _ForwardIterator>
11420b57cec5SDimitry Andrictypename regex_traits<_CharT>::string_type
1143cb14a3feSDimitry Andricregex_traits<_CharT>::__transform_primary(_ForwardIterator __f, _ForwardIterator __l, wchar_t) const {
11440b57cec5SDimitry Andric  const string_type __s(__f, __l);
11450b57cec5SDimitry Andric  string_type __d = __col_->transform(__s.data(), __s.data() + __s.size());
1146cb14a3feSDimitry Andric  switch (__d.size()) {
11470b57cec5SDimitry Andric  case 1:
11480b57cec5SDimitry Andric    break;
11490b57cec5SDimitry Andric  case 3:
11500b57cec5SDimitry Andric    __d[2] = __d[0];
11510b57cec5SDimitry Andric    break;
11520b57cec5SDimitry Andric  default:
11530b57cec5SDimitry Andric    __d.clear();
11540b57cec5SDimitry Andric    break;
11550b57cec5SDimitry Andric  }
11560b57cec5SDimitry Andric  return __d;
11570b57cec5SDimitry Andric}
1158349cc55cSDimitry Andric#endif
11590b57cec5SDimitry Andric
11600b57cec5SDimitry Andric// lookup_collatename is very FreeBSD-specific
11610b57cec5SDimitry Andric
116206c3fb27SDimitry Andric_LIBCPP_EXPORTED_FROM_ABI string __get_collation_name(const char* __s);
11630b57cec5SDimitry Andric
11640b57cec5SDimitry Andrictemplate <class _CharT>
11650b57cec5SDimitry Andrictemplate <class _ForwardIterator>
11660b57cec5SDimitry Andrictypename regex_traits<_CharT>::string_type
1167cb14a3feSDimitry Andricregex_traits<_CharT>::__lookup_collatename(_ForwardIterator __f, _ForwardIterator __l, char) const {
11680b57cec5SDimitry Andric  string_type __s(__f, __l);
11690b57cec5SDimitry Andric  string_type __r;
1170cb14a3feSDimitry Andric  if (!__s.empty()) {
1171bdd1243dSDimitry Andric    __r = std::__get_collation_name(__s.c_str());
1172cb14a3feSDimitry Andric    if (__r.empty() && __s.size() <= 2) {
11730b57cec5SDimitry Andric      __r = __col_->transform(__s.data(), __s.data() + __s.size());
11740b57cec5SDimitry Andric      if (__r.size() == 1 || __r.size() == 12)
11750b57cec5SDimitry Andric        __r = __s;
11760b57cec5SDimitry Andric      else
11770b57cec5SDimitry Andric        __r.clear();
11780b57cec5SDimitry Andric    }
11790b57cec5SDimitry Andric  }
11800b57cec5SDimitry Andric  return __r;
11810b57cec5SDimitry Andric}
11820b57cec5SDimitry Andric
1183349cc55cSDimitry Andric#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
11840b57cec5SDimitry Andrictemplate <class _CharT>
11850b57cec5SDimitry Andrictemplate <class _ForwardIterator>
11860b57cec5SDimitry Andrictypename regex_traits<_CharT>::string_type
1187cb14a3feSDimitry Andricregex_traits<_CharT>::__lookup_collatename(_ForwardIterator __f, _ForwardIterator __l, wchar_t) const {
11880b57cec5SDimitry Andric  string_type __s(__f, __l);
11890b57cec5SDimitry Andric  string __n;
11900b57cec5SDimitry Andric  __n.reserve(__s.size());
1191cb14a3feSDimitry Andric  for (typename string_type::const_iterator __i = __s.begin(), __e = __s.end(); __i != __e; ++__i) {
11920b57cec5SDimitry Andric    if (static_cast<unsigned>(*__i) >= 127)
11930b57cec5SDimitry Andric      return string_type();
11940b57cec5SDimitry Andric    __n.push_back(char(*__i));
11950b57cec5SDimitry Andric  }
11960b57cec5SDimitry Andric  string_type __r;
1197cb14a3feSDimitry Andric  if (!__s.empty()) {
11980b57cec5SDimitry Andric    __n = __get_collation_name(__n.c_str());
11990b57cec5SDimitry Andric    if (!__n.empty())
12000b57cec5SDimitry Andric      __r.assign(__n.begin(), __n.end());
1201cb14a3feSDimitry Andric    else if (__s.size() <= 2) {
12020b57cec5SDimitry Andric      __r = __col_->transform(__s.data(), __s.data() + __s.size());
12030b57cec5SDimitry Andric      if (__r.size() == 1 || __r.size() == 3)
12040b57cec5SDimitry Andric        __r = __s;
12050b57cec5SDimitry Andric      else
12060b57cec5SDimitry Andric        __r.clear();
12070b57cec5SDimitry Andric    }
12080b57cec5SDimitry Andric  }
12090b57cec5SDimitry Andric  return __r;
12100b57cec5SDimitry Andric}
1211349cc55cSDimitry Andric#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
12120b57cec5SDimitry Andric
12130b57cec5SDimitry Andric// lookup_classname
12140b57cec5SDimitry Andric
121506c3fb27SDimitry Andricregex_traits<char>::char_class_type _LIBCPP_EXPORTED_FROM_ABI __get_classname(const char* __s, bool __icase);
12160b57cec5SDimitry Andric
12170b57cec5SDimitry Andrictemplate <class _CharT>
12180b57cec5SDimitry Andrictemplate <class _ForwardIterator>
12190b57cec5SDimitry Andrictypename regex_traits<_CharT>::char_class_type
1220cb14a3feSDimitry Andricregex_traits<_CharT>::__lookup_classname(_ForwardIterator __f, _ForwardIterator __l, bool __icase, char) const {
12210b57cec5SDimitry Andric  string_type __s(__f, __l);
12220b57cec5SDimitry Andric  __ct_->tolower(&__s[0], &__s[0] + __s.size());
1223bdd1243dSDimitry Andric  return std::__get_classname(__s.c_str(), __icase);
12240b57cec5SDimitry Andric}
12250b57cec5SDimitry Andric
1226349cc55cSDimitry Andric#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
12270b57cec5SDimitry Andrictemplate <class _CharT>
12280b57cec5SDimitry Andrictemplate <class _ForwardIterator>
12290b57cec5SDimitry Andrictypename regex_traits<_CharT>::char_class_type
1230cb14a3feSDimitry Andricregex_traits<_CharT>::__lookup_classname(_ForwardIterator __f, _ForwardIterator __l, bool __icase, wchar_t) const {
12310b57cec5SDimitry Andric  string_type __s(__f, __l);
12320b57cec5SDimitry Andric  __ct_->tolower(&__s[0], &__s[0] + __s.size());
12330b57cec5SDimitry Andric  string __n;
12340b57cec5SDimitry Andric  __n.reserve(__s.size());
1235cb14a3feSDimitry Andric  for (typename string_type::const_iterator __i = __s.begin(), __e = __s.end(); __i != __e; ++__i) {
12360b57cec5SDimitry Andric    if (static_cast<unsigned>(*__i) >= 127)
12370b57cec5SDimitry Andric      return char_class_type();
12380b57cec5SDimitry Andric    __n.push_back(char(*__i));
12390b57cec5SDimitry Andric  }
12400b57cec5SDimitry Andric  return __get_classname(__n.c_str(), __icase);
12410b57cec5SDimitry Andric}
1242349cc55cSDimitry Andric#endif // _LIBCPP_HAS_NO_WIDE_CHARACTERS
12430b57cec5SDimitry Andric
12440b57cec5SDimitry Andrictemplate <class _CharT>
1245cb14a3feSDimitry Andricbool regex_traits<_CharT>::isctype(char_type __c, char_class_type __m) const {
12460b57cec5SDimitry Andric  if (__ct_->is(__m, __c))
12470b57cec5SDimitry Andric    return true;
12480b57cec5SDimitry Andric  return (__c == '_' && (__m & __regex_word));
12490b57cec5SDimitry Andric}
12500b57cec5SDimitry Andric
1251cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool __is_07(unsigned char __c) {
1252753f127fSDimitry Andric  return (__c & 0xF8u) ==
125304eeddc0SDimitry Andric#if defined(__MVS__) && !defined(__NATIVE_ASCII_F)
125404eeddc0SDimitry Andric         0xF0;
125504eeddc0SDimitry Andric#else
125604eeddc0SDimitry Andric         0x30;
125704eeddc0SDimitry Andric#endif
125804eeddc0SDimitry Andric}
125904eeddc0SDimitry Andric
1260cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool __is_89(unsigned char __c) {
1261753f127fSDimitry Andric  return (__c & 0xFEu) ==
126204eeddc0SDimitry Andric#if defined(__MVS__) && !defined(__NATIVE_ASCII_F)
126304eeddc0SDimitry Andric         0xF8;
126404eeddc0SDimitry Andric#else
126504eeddc0SDimitry Andric         0x38;
126604eeddc0SDimitry Andric#endif
126704eeddc0SDimitry Andric}
126804eeddc0SDimitry Andric
1269cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI unsigned char __to_lower(unsigned char __c) {
127004eeddc0SDimitry Andric#if defined(__MVS__) && !defined(__NATIVE_ASCII_F)
1271a4a491e2SDimitry Andric  return __c & 0xBF;
127204eeddc0SDimitry Andric#else
1273753f127fSDimitry Andric  return __c | 0x20;
127404eeddc0SDimitry Andric#endif
127504eeddc0SDimitry Andric}
127604eeddc0SDimitry Andric
12770b57cec5SDimitry Andrictemplate <class _CharT>
1278cb14a3feSDimitry Andricint regex_traits<_CharT>::__regex_traits_value(unsigned char __ch, int __radix) {
127904eeddc0SDimitry Andric  if (__is_07(__ch)) // '0' <= __ch && __ch <= '7'
12800b57cec5SDimitry Andric    return __ch - '0';
1281cb14a3feSDimitry Andric  if (__radix != 8) {
128204eeddc0SDimitry Andric    if (__is_89(__ch)) // '8' <= __ch && __ch <= '9'
12830b57cec5SDimitry Andric      return __ch - '0';
1284cb14a3feSDimitry Andric    if (__radix == 16) {
128504eeddc0SDimitry Andric      __ch = __to_lower(__ch); // tolower
12860b57cec5SDimitry Andric      if ('a' <= __ch && __ch <= 'f')
12870b57cec5SDimitry Andric        return __ch - ('a' - 10);
12880b57cec5SDimitry Andric    }
12890b57cec5SDimitry Andric  }
12900b57cec5SDimitry Andric  return -1;
12910b57cec5SDimitry Andric}
12920b57cec5SDimitry Andric
1293349cc55cSDimitry Andric#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
12940b57cec5SDimitry Andrictemplate <class _CharT>
1295cb14a3feSDimitry Andricinline int regex_traits<_CharT>::__regex_traits_value(wchar_t __ch, int __radix) const {
12960b57cec5SDimitry Andric  return __regex_traits_value(static_cast<unsigned char>(__ct_->narrow(__ch, char_type())), __radix);
12970b57cec5SDimitry Andric}
1298349cc55cSDimitry Andric#endif
12990b57cec5SDimitry Andric
1300cb14a3feSDimitry Andrictemplate <class _CharT>
1301cb14a3feSDimitry Andricclass __node;
13020b57cec5SDimitry Andric
1303cb14a3feSDimitry Andrictemplate <class _BidirectionalIterator>
1304cb14a3feSDimitry Andricclass _LIBCPP_TEMPLATE_VIS sub_match;
13050b57cec5SDimitry Andric
1306cb14a3feSDimitry Andrictemplate <class _BidirectionalIterator, class _Allocator = allocator<sub_match<_BidirectionalIterator> > >
13070b57cec5SDimitry Andricclass _LIBCPP_TEMPLATE_VIS match_results;
13080b57cec5SDimitry Andric
13090b57cec5SDimitry Andrictemplate <class _CharT>
1310cb14a3feSDimitry Andricstruct __state {
1311cb14a3feSDimitry Andric  enum {
13120b57cec5SDimitry Andric    __end_state = -1000,
13130b57cec5SDimitry Andric    __consume_input,          // -999
13140b57cec5SDimitry Andric    __begin_marked_expr,      // -998
13150b57cec5SDimitry Andric    __end_marked_expr,        // -997
13160b57cec5SDimitry Andric    __pop_state,              // -996
13170b57cec5SDimitry Andric    __accept_and_consume,     // -995
13180b57cec5SDimitry Andric    __accept_but_not_consume, // -994
13190b57cec5SDimitry Andric    __reject,                 // -993
13200b57cec5SDimitry Andric    __split,
13210b57cec5SDimitry Andric    __repeat
13220b57cec5SDimitry Andric  };
13230b57cec5SDimitry Andric
13240b57cec5SDimitry Andric  int __do_;
13250b57cec5SDimitry Andric  const _CharT* __first_;
13260b57cec5SDimitry Andric  const _CharT* __current_;
13270b57cec5SDimitry Andric  const _CharT* __last_;
13280b57cec5SDimitry Andric  vector<sub_match<const _CharT*> > __sub_matches_;
13290b57cec5SDimitry Andric  vector<pair<size_t, const _CharT*> > __loop_data_;
13300b57cec5SDimitry Andric  const __node<_CharT>* __node_;
13310b57cec5SDimitry Andric  regex_constants::match_flag_type __flags_;
13320b57cec5SDimitry Andric  bool __at_first_;
13330b57cec5SDimitry Andric
1334cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI __state()
1335cb14a3feSDimitry Andric      : __do_(0),
1336cb14a3feSDimitry Andric        __first_(nullptr),
1337cb14a3feSDimitry Andric        __current_(nullptr),
1338cb14a3feSDimitry Andric        __last_(nullptr),
1339cb14a3feSDimitry Andric        __node_(nullptr),
1340cb14a3feSDimitry Andric        __flags_(),
1341cb14a3feSDimitry Andric        __at_first_(false) {}
13420b57cec5SDimitry Andric};
13430b57cec5SDimitry Andric
13440b57cec5SDimitry Andric// __node
13450b57cec5SDimitry Andric
13460b57cec5SDimitry Andrictemplate <class _CharT>
1347cb14a3feSDimitry Andricclass __node {
13480b57cec5SDimitry Andricpublic:
13495f757f3fSDimitry Andric  typedef std::__state<_CharT> __state;
13500b57cec5SDimitry Andric
1351cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI __node() {}
1352*0fca6ea1SDimitry Andric  __node(const __node&)            = delete;
1353*0fca6ea1SDimitry Andric  __node& operator=(const __node&) = delete;
1354bdd1243dSDimitry Andric  _LIBCPP_HIDE_FROM_ABI_VIRTUAL
13550b57cec5SDimitry Andric  virtual ~__node() {}
13560b57cec5SDimitry Andric
1357bdd1243dSDimitry Andric  _LIBCPP_HIDE_FROM_ABI_VIRTUAL
13580b57cec5SDimitry Andric  virtual void __exec(__state&) const {}
1359bdd1243dSDimitry Andric  _LIBCPP_HIDE_FROM_ABI_VIRTUAL
13600b57cec5SDimitry Andric  virtual void __exec_split(bool, __state&) const {}
13610b57cec5SDimitry Andric};
13620b57cec5SDimitry Andric
13630b57cec5SDimitry Andric// __end_state
13640b57cec5SDimitry Andric
13650b57cec5SDimitry Andrictemplate <class _CharT>
1366cb14a3feSDimitry Andricclass __end_state : public __node<_CharT> {
13670b57cec5SDimitry Andricpublic:
13685f757f3fSDimitry Andric  typedef std::__state<_CharT> __state;
13690b57cec5SDimitry Andric
1370cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI __end_state() {}
13710b57cec5SDimitry Andric
137206c3fb27SDimitry Andric  _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual void __exec(__state&) const;
13730b57cec5SDimitry Andric};
13740b57cec5SDimitry Andric
13750b57cec5SDimitry Andrictemplate <class _CharT>
1376cb14a3feSDimitry Andricvoid __end_state<_CharT>::__exec(__state& __s) const {
13770b57cec5SDimitry Andric  __s.__do_ = __state::__end_state;
13780b57cec5SDimitry Andric}
13790b57cec5SDimitry Andric
13800b57cec5SDimitry Andric// __has_one_state
13810b57cec5SDimitry Andric
13820b57cec5SDimitry Andrictemplate <class _CharT>
1383cb14a3feSDimitry Andricclass __has_one_state : public __node<_CharT> {
13840b57cec5SDimitry Andric  __node<_CharT>* __first_;
13850b57cec5SDimitry Andric
13860b57cec5SDimitry Andricpublic:
1387cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI explicit __has_one_state(__node<_CharT>* __s) : __first_(__s) {}
13880b57cec5SDimitry Andric
1389cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI __node<_CharT>* first() const { return __first_; }
1390cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI __node<_CharT>*& first() { return __first_; }
13910b57cec5SDimitry Andric};
13920b57cec5SDimitry Andric
13930b57cec5SDimitry Andric// __owns_one_state
13940b57cec5SDimitry Andric
13950b57cec5SDimitry Andrictemplate <class _CharT>
1396cb14a3feSDimitry Andricclass __owns_one_state : public __has_one_state<_CharT> {
13970b57cec5SDimitry Andric  typedef __has_one_state<_CharT> base;
13980b57cec5SDimitry Andric
13990b57cec5SDimitry Andricpublic:
1400cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI explicit __owns_one_state(__node<_CharT>* __s) : base(__s) {}
14010b57cec5SDimitry Andric
1402bdd1243dSDimitry Andric  ~__owns_one_state() override;
14030b57cec5SDimitry Andric};
14040b57cec5SDimitry Andric
14050b57cec5SDimitry Andrictemplate <class _CharT>
1406cb14a3feSDimitry Andric__owns_one_state<_CharT>::~__owns_one_state() {
14070b57cec5SDimitry Andric  delete this->first();
14080b57cec5SDimitry Andric}
14090b57cec5SDimitry Andric
14100b57cec5SDimitry Andric// __empty_state
14110b57cec5SDimitry Andric
14120b57cec5SDimitry Andrictemplate <class _CharT>
1413cb14a3feSDimitry Andricclass __empty_state : public __owns_one_state<_CharT> {
14140b57cec5SDimitry Andric  typedef __owns_one_state<_CharT> base;
14150b57cec5SDimitry Andric
14160b57cec5SDimitry Andricpublic:
14175f757f3fSDimitry Andric  typedef std::__state<_CharT> __state;
14180b57cec5SDimitry Andric
1419cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI explicit __empty_state(__node<_CharT>* __s) : base(__s) {}
14200b57cec5SDimitry Andric
142106c3fb27SDimitry Andric  _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual void __exec(__state&) const;
14220b57cec5SDimitry Andric};
14230b57cec5SDimitry Andric
14240b57cec5SDimitry Andrictemplate <class _CharT>
1425cb14a3feSDimitry Andricvoid __empty_state<_CharT>::__exec(__state& __s) const {
14260b57cec5SDimitry Andric  __s.__do_   = __state::__accept_but_not_consume;
14270b57cec5SDimitry Andric  __s.__node_ = this->first();
14280b57cec5SDimitry Andric}
14290b57cec5SDimitry Andric
14300b57cec5SDimitry Andric// __empty_non_own_state
14310b57cec5SDimitry Andric
14320b57cec5SDimitry Andrictemplate <class _CharT>
1433cb14a3feSDimitry Andricclass __empty_non_own_state : public __has_one_state<_CharT> {
14340b57cec5SDimitry Andric  typedef __has_one_state<_CharT> base;
14350b57cec5SDimitry Andric
14360b57cec5SDimitry Andricpublic:
14375f757f3fSDimitry Andric  typedef std::__state<_CharT> __state;
14380b57cec5SDimitry Andric
1439cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI explicit __empty_non_own_state(__node<_CharT>* __s) : base(__s) {}
14400b57cec5SDimitry Andric
144106c3fb27SDimitry Andric  _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual void __exec(__state&) const;
14420b57cec5SDimitry Andric};
14430b57cec5SDimitry Andric
14440b57cec5SDimitry Andrictemplate <class _CharT>
1445cb14a3feSDimitry Andricvoid __empty_non_own_state<_CharT>::__exec(__state& __s) const {
14460b57cec5SDimitry Andric  __s.__do_   = __state::__accept_but_not_consume;
14470b57cec5SDimitry Andric  __s.__node_ = this->first();
14480b57cec5SDimitry Andric}
14490b57cec5SDimitry Andric
14500b57cec5SDimitry Andric// __repeat_one_loop
14510b57cec5SDimitry Andric
14520b57cec5SDimitry Andrictemplate <class _CharT>
1453cb14a3feSDimitry Andricclass __repeat_one_loop : public __has_one_state<_CharT> {
14540b57cec5SDimitry Andric  typedef __has_one_state<_CharT> base;
14550b57cec5SDimitry Andric
14560b57cec5SDimitry Andricpublic:
14575f757f3fSDimitry Andric  typedef std::__state<_CharT> __state;
14580b57cec5SDimitry Andric
1459cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI explicit __repeat_one_loop(__node<_CharT>* __s) : base(__s) {}
14600b57cec5SDimitry Andric
146106c3fb27SDimitry Andric  _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual void __exec(__state&) const;
14620b57cec5SDimitry Andric};
14630b57cec5SDimitry Andric
14640b57cec5SDimitry Andrictemplate <class _CharT>
1465cb14a3feSDimitry Andricvoid __repeat_one_loop<_CharT>::__exec(__state& __s) const {
14660b57cec5SDimitry Andric  __s.__do_   = __state::__repeat;
14670b57cec5SDimitry Andric  __s.__node_ = this->first();
14680b57cec5SDimitry Andric}
14690b57cec5SDimitry Andric
14700b57cec5SDimitry Andric// __owns_two_states
14710b57cec5SDimitry Andric
14720b57cec5SDimitry Andrictemplate <class _CharT>
1473cb14a3feSDimitry Andricclass __owns_two_states : public __owns_one_state<_CharT> {
14740b57cec5SDimitry Andric  typedef __owns_one_state<_CharT> base;
14750b57cec5SDimitry Andric
14760b57cec5SDimitry Andric  base* __second_;
14770b57cec5SDimitry Andric
14780b57cec5SDimitry Andricpublic:
1479cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI explicit __owns_two_states(__node<_CharT>* __s1, base* __s2) : base(__s1), __second_(__s2) {}
14800b57cec5SDimitry Andric
148106c3fb27SDimitry Andric  _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual ~__owns_two_states();
14820b57cec5SDimitry Andric
1483cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI base* second() const { return __second_; }
1484cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI base*& second() { return __second_; }
14850b57cec5SDimitry Andric};
14860b57cec5SDimitry Andric
14870b57cec5SDimitry Andrictemplate <class _CharT>
1488cb14a3feSDimitry Andric__owns_two_states<_CharT>::~__owns_two_states() {
14890b57cec5SDimitry Andric  delete __second_;
14900b57cec5SDimitry Andric}
14910b57cec5SDimitry Andric
14920b57cec5SDimitry Andric// __loop
14930b57cec5SDimitry Andric
14940b57cec5SDimitry Andrictemplate <class _CharT>
1495cb14a3feSDimitry Andricclass __loop : public __owns_two_states<_CharT> {
14960b57cec5SDimitry Andric  typedef __owns_two_states<_CharT> base;
14970b57cec5SDimitry Andric
14980b57cec5SDimitry Andric  size_t __min_;
14990b57cec5SDimitry Andric  size_t __max_;
15000b57cec5SDimitry Andric  unsigned __loop_id_;
15010b57cec5SDimitry Andric  unsigned __mexp_begin_;
15020b57cec5SDimitry Andric  unsigned __mexp_end_;
15030b57cec5SDimitry Andric  bool __greedy_;
15040b57cec5SDimitry Andric
15050b57cec5SDimitry Andricpublic:
15065f757f3fSDimitry Andric  typedef std::__state<_CharT> __state;
15070b57cec5SDimitry Andric
1508cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI explicit __loop(
1509cb14a3feSDimitry Andric      unsigned __loop_id,
1510cb14a3feSDimitry Andric      __node<_CharT>* __s1,
1511cb14a3feSDimitry Andric      __owns_one_state<_CharT>* __s2,
1512cb14a3feSDimitry Andric      unsigned __mexp_begin,
1513cb14a3feSDimitry Andric      unsigned __mexp_end,
15140b57cec5SDimitry Andric      bool __greedy = true,
15150b57cec5SDimitry Andric      size_t __min  = 0,
15160b57cec5SDimitry Andric      size_t __max  = numeric_limits<size_t>::max())
1517cb14a3feSDimitry Andric      : base(__s1, __s2),
1518cb14a3feSDimitry Andric        __min_(__min),
1519cb14a3feSDimitry Andric        __max_(__max),
1520cb14a3feSDimitry Andric        __loop_id_(__loop_id),
1521cb14a3feSDimitry Andric        __mexp_begin_(__mexp_begin),
1522cb14a3feSDimitry Andric        __mexp_end_(__mexp_end),
15230b57cec5SDimitry Andric        __greedy_(__greedy) {}
15240b57cec5SDimitry Andric
152506c3fb27SDimitry Andric  _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual void __exec(__state& __s) const;
152606c3fb27SDimitry Andric  _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual void __exec_split(bool __second, __state& __s) const;
15270b57cec5SDimitry Andric
15280b57cec5SDimitry Andricprivate:
1529cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void __init_repeat(__state& __s) const {
15300b57cec5SDimitry Andric    __s.__loop_data_[__loop_id_].second = __s.__current_;
1531cb14a3feSDimitry Andric    for (size_t __i = __mexp_begin_ - 1; __i != __mexp_end_ - 1; ++__i) {
15320b57cec5SDimitry Andric      __s.__sub_matches_[__i].first   = __s.__last_;
15330b57cec5SDimitry Andric      __s.__sub_matches_[__i].second  = __s.__last_;
15340b57cec5SDimitry Andric      __s.__sub_matches_[__i].matched = false;
15350b57cec5SDimitry Andric    }
15360b57cec5SDimitry Andric  }
15370b57cec5SDimitry Andric};
15380b57cec5SDimitry Andric
15390b57cec5SDimitry Andrictemplate <class _CharT>
1540cb14a3feSDimitry Andricvoid __loop<_CharT>::__exec(__state& __s) const {
1541cb14a3feSDimitry Andric  if (__s.__do_ == __state::__repeat) {
15420b57cec5SDimitry Andric    bool __do_repeat = ++__s.__loop_data_[__loop_id_].first < __max_;
15430b57cec5SDimitry Andric    bool __do_alt    = __s.__loop_data_[__loop_id_].first >= __min_;
1544cb14a3feSDimitry Andric    if (__do_repeat && __do_alt && __s.__loop_data_[__loop_id_].second == __s.__current_)
15450b57cec5SDimitry Andric      __do_repeat = false;
15460b57cec5SDimitry Andric    if (__do_repeat && __do_alt)
15470b57cec5SDimitry Andric      __s.__do_ = __state::__split;
1548cb14a3feSDimitry Andric    else if (__do_repeat) {
15490b57cec5SDimitry Andric      __s.__do_   = __state::__accept_but_not_consume;
15500b57cec5SDimitry Andric      __s.__node_ = this->first();
15510b57cec5SDimitry Andric      __init_repeat(__s);
1552cb14a3feSDimitry Andric    } else {
15530b57cec5SDimitry Andric      __s.__do_   = __state::__accept_but_not_consume;
15540b57cec5SDimitry Andric      __s.__node_ = this->second();
15550b57cec5SDimitry Andric    }
1556cb14a3feSDimitry Andric  } else {
15570b57cec5SDimitry Andric    __s.__loop_data_[__loop_id_].first = 0;
15580b57cec5SDimitry Andric    bool __do_repeat                   = 0 < __max_;
15590b57cec5SDimitry Andric    bool __do_alt                      = 0 >= __min_;
15600b57cec5SDimitry Andric    if (__do_repeat && __do_alt)
15610b57cec5SDimitry Andric      __s.__do_ = __state::__split;
1562cb14a3feSDimitry Andric    else if (__do_repeat) {
15630b57cec5SDimitry Andric      __s.__do_   = __state::__accept_but_not_consume;
15640b57cec5SDimitry Andric      __s.__node_ = this->first();
15650b57cec5SDimitry Andric      __init_repeat(__s);
1566cb14a3feSDimitry Andric    } else {
15670b57cec5SDimitry Andric      __s.__do_   = __state::__accept_but_not_consume;
15680b57cec5SDimitry Andric      __s.__node_ = this->second();
15690b57cec5SDimitry Andric    }
15700b57cec5SDimitry Andric  }
15710b57cec5SDimitry Andric}
15720b57cec5SDimitry Andric
15730b57cec5SDimitry Andrictemplate <class _CharT>
1574cb14a3feSDimitry Andricvoid __loop<_CharT>::__exec_split(bool __second, __state& __s) const {
15750b57cec5SDimitry Andric  __s.__do_ = __state::__accept_but_not_consume;
1576cb14a3feSDimitry Andric  if (__greedy_ != __second) {
15770b57cec5SDimitry Andric    __s.__node_ = this->first();
15780b57cec5SDimitry Andric    __init_repeat(__s);
1579cb14a3feSDimitry Andric  } else
15800b57cec5SDimitry Andric    __s.__node_ = this->second();
15810b57cec5SDimitry Andric}
15820b57cec5SDimitry Andric
15830b57cec5SDimitry Andric// __alternate
15840b57cec5SDimitry Andric
15850b57cec5SDimitry Andrictemplate <class _CharT>
1586cb14a3feSDimitry Andricclass __alternate : public __owns_two_states<_CharT> {
15870b57cec5SDimitry Andric  typedef __owns_two_states<_CharT> base;
15880b57cec5SDimitry Andric
15890b57cec5SDimitry Andricpublic:
15905f757f3fSDimitry Andric  typedef std::__state<_CharT> __state;
15910b57cec5SDimitry Andric
1592cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI explicit __alternate(__owns_one_state<_CharT>* __s1, __owns_one_state<_CharT>* __s2)
15930b57cec5SDimitry Andric      : base(__s1, __s2) {}
15940b57cec5SDimitry Andric
159506c3fb27SDimitry Andric  _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual void __exec(__state& __s) const;
159606c3fb27SDimitry Andric  _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual void __exec_split(bool __second, __state& __s) const;
15970b57cec5SDimitry Andric};
15980b57cec5SDimitry Andric
15990b57cec5SDimitry Andrictemplate <class _CharT>
1600cb14a3feSDimitry Andricvoid __alternate<_CharT>::__exec(__state& __s) const {
16010b57cec5SDimitry Andric  __s.__do_ = __state::__split;
16020b57cec5SDimitry Andric}
16030b57cec5SDimitry Andric
16040b57cec5SDimitry Andrictemplate <class _CharT>
1605cb14a3feSDimitry Andricvoid __alternate<_CharT>::__exec_split(bool __second, __state& __s) const {
16060b57cec5SDimitry Andric  __s.__do_ = __state::__accept_but_not_consume;
16070b57cec5SDimitry Andric  if (__second)
16080b57cec5SDimitry Andric    __s.__node_ = this->second();
16090b57cec5SDimitry Andric  else
16100b57cec5SDimitry Andric    __s.__node_ = this->first();
16110b57cec5SDimitry Andric}
16120b57cec5SDimitry Andric
16130b57cec5SDimitry Andric// __begin_marked_subexpression
16140b57cec5SDimitry Andric
16150b57cec5SDimitry Andrictemplate <class _CharT>
1616cb14a3feSDimitry Andricclass __begin_marked_subexpression : public __owns_one_state<_CharT> {
16170b57cec5SDimitry Andric  typedef __owns_one_state<_CharT> base;
16180b57cec5SDimitry Andric
16190b57cec5SDimitry Andric  unsigned __mexp_;
1620cb14a3feSDimitry Andric
16210b57cec5SDimitry Andricpublic:
16225f757f3fSDimitry Andric  typedef std::__state<_CharT> __state;
16230b57cec5SDimitry Andric
1624cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI explicit __begin_marked_subexpression(unsigned __mexp, __node<_CharT>* __s)
16250b57cec5SDimitry Andric      : base(__s), __mexp_(__mexp) {}
16260b57cec5SDimitry Andric
162706c3fb27SDimitry Andric  _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual void __exec(__state&) const;
16280b57cec5SDimitry Andric};
16290b57cec5SDimitry Andric
16300b57cec5SDimitry Andrictemplate <class _CharT>
1631cb14a3feSDimitry Andricvoid __begin_marked_subexpression<_CharT>::__exec(__state& __s) const {
16320b57cec5SDimitry Andric  __s.__do_                             = __state::__accept_but_not_consume;
16330b57cec5SDimitry Andric  __s.__sub_matches_[__mexp_ - 1].first = __s.__current_;
16340b57cec5SDimitry Andric  __s.__node_                           = this->first();
16350b57cec5SDimitry Andric}
16360b57cec5SDimitry Andric
16370b57cec5SDimitry Andric// __end_marked_subexpression
16380b57cec5SDimitry Andric
16390b57cec5SDimitry Andrictemplate <class _CharT>
1640cb14a3feSDimitry Andricclass __end_marked_subexpression : public __owns_one_state<_CharT> {
16410b57cec5SDimitry Andric  typedef __owns_one_state<_CharT> base;
16420b57cec5SDimitry Andric
16430b57cec5SDimitry Andric  unsigned __mexp_;
1644cb14a3feSDimitry Andric
16450b57cec5SDimitry Andricpublic:
16465f757f3fSDimitry Andric  typedef std::__state<_CharT> __state;
16470b57cec5SDimitry Andric
1648cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI explicit __end_marked_subexpression(unsigned __mexp, __node<_CharT>* __s)
16490b57cec5SDimitry Andric      : base(__s), __mexp_(__mexp) {}
16500b57cec5SDimitry Andric
165106c3fb27SDimitry Andric  _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual void __exec(__state&) const;
16520b57cec5SDimitry Andric};
16530b57cec5SDimitry Andric
16540b57cec5SDimitry Andrictemplate <class _CharT>
1655cb14a3feSDimitry Andricvoid __end_marked_subexpression<_CharT>::__exec(__state& __s) const {
16560b57cec5SDimitry Andric  __s.__do_                               = __state::__accept_but_not_consume;
16570b57cec5SDimitry Andric  __s.__sub_matches_[__mexp_ - 1].second  = __s.__current_;
16580b57cec5SDimitry Andric  __s.__sub_matches_[__mexp_ - 1].matched = true;
16590b57cec5SDimitry Andric  __s.__node_                             = this->first();
16600b57cec5SDimitry Andric}
16610b57cec5SDimitry Andric
16620b57cec5SDimitry Andric// __back_ref
16630b57cec5SDimitry Andric
16640b57cec5SDimitry Andrictemplate <class _CharT>
1665cb14a3feSDimitry Andricclass __back_ref : public __owns_one_state<_CharT> {
16660b57cec5SDimitry Andric  typedef __owns_one_state<_CharT> base;
16670b57cec5SDimitry Andric
16680b57cec5SDimitry Andric  unsigned __mexp_;
1669cb14a3feSDimitry Andric
16700b57cec5SDimitry Andricpublic:
16715f757f3fSDimitry Andric  typedef std::__state<_CharT> __state;
16720b57cec5SDimitry Andric
1673cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI explicit __back_ref(unsigned __mexp, __node<_CharT>* __s) : base(__s), __mexp_(__mexp) {}
16740b57cec5SDimitry Andric
167506c3fb27SDimitry Andric  _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual void __exec(__state&) const;
16760b57cec5SDimitry Andric};
16770b57cec5SDimitry Andric
16780b57cec5SDimitry Andrictemplate <class _CharT>
1679cb14a3feSDimitry Andricvoid __back_ref<_CharT>::__exec(__state& __s) const {
16800b57cec5SDimitry Andric  if (__mexp_ > __s.__sub_matches_.size())
16810b57cec5SDimitry Andric    __throw_regex_error<regex_constants::error_backref>();
16820b57cec5SDimitry Andric  sub_match<const _CharT*>& __sm = __s.__sub_matches_[__mexp_ - 1];
1683cb14a3feSDimitry Andric  if (__sm.matched) {
16840b57cec5SDimitry Andric    ptrdiff_t __len = __sm.second - __sm.first;
1685cb14a3feSDimitry Andric    if (__s.__last_ - __s.__current_ >= __len && std::equal(__sm.first, __sm.second, __s.__current_)) {
16860b57cec5SDimitry Andric      __s.__do_ = __state::__accept_but_not_consume;
16870b57cec5SDimitry Andric      __s.__current_ += __len;
16880b57cec5SDimitry Andric      __s.__node_ = this->first();
1689cb14a3feSDimitry Andric    } else {
16900b57cec5SDimitry Andric      __s.__do_   = __state::__reject;
16910b57cec5SDimitry Andric      __s.__node_ = nullptr;
16920b57cec5SDimitry Andric    }
1693cb14a3feSDimitry Andric  } else {
16940b57cec5SDimitry Andric    __s.__do_   = __state::__reject;
16950b57cec5SDimitry Andric    __s.__node_ = nullptr;
16960b57cec5SDimitry Andric  }
16970b57cec5SDimitry Andric}
16980b57cec5SDimitry Andric
16990b57cec5SDimitry Andric// __back_ref_icase
17000b57cec5SDimitry Andric
17010b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
1702cb14a3feSDimitry Andricclass __back_ref_icase : public __owns_one_state<_CharT> {
17030b57cec5SDimitry Andric  typedef __owns_one_state<_CharT> base;
17040b57cec5SDimitry Andric
17050b57cec5SDimitry Andric  _Traits __traits_;
17060b57cec5SDimitry Andric  unsigned __mexp_;
1707cb14a3feSDimitry Andric
17080b57cec5SDimitry Andricpublic:
17095f757f3fSDimitry Andric  typedef std::__state<_CharT> __state;
17100b57cec5SDimitry Andric
1711cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI explicit __back_ref_icase(const _Traits& __traits, unsigned __mexp, __node<_CharT>* __s)
17120b57cec5SDimitry Andric      : base(__s), __traits_(__traits), __mexp_(__mexp) {}
17130b57cec5SDimitry Andric
171406c3fb27SDimitry Andric  _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual void __exec(__state&) const;
17150b57cec5SDimitry Andric};
17160b57cec5SDimitry Andric
17170b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
1718cb14a3feSDimitry Andricvoid __back_ref_icase<_CharT, _Traits>::__exec(__state& __s) const {
17190b57cec5SDimitry Andric  sub_match<const _CharT*>& __sm = __s.__sub_matches_[__mexp_ - 1];
1720cb14a3feSDimitry Andric  if (__sm.matched) {
17210b57cec5SDimitry Andric    ptrdiff_t __len = __sm.second - __sm.first;
1722cb14a3feSDimitry Andric    if (__s.__last_ - __s.__current_ >= __len) {
1723cb14a3feSDimitry Andric      for (ptrdiff_t __i = 0; __i < __len; ++__i) {
1724cb14a3feSDimitry Andric        if (__traits_.translate_nocase(__sm.first[__i]) != __traits_.translate_nocase(__s.__current_[__i]))
17250b57cec5SDimitry Andric          goto __not_equal;
17260b57cec5SDimitry Andric      }
17270b57cec5SDimitry Andric      __s.__do_ = __state::__accept_but_not_consume;
17280b57cec5SDimitry Andric      __s.__current_ += __len;
17290b57cec5SDimitry Andric      __s.__node_ = this->first();
1730cb14a3feSDimitry Andric    } else {
17310b57cec5SDimitry Andric      __s.__do_   = __state::__reject;
17320b57cec5SDimitry Andric      __s.__node_ = nullptr;
17330b57cec5SDimitry Andric    }
1734cb14a3feSDimitry Andric  } else {
17350b57cec5SDimitry Andric  __not_equal:
17360b57cec5SDimitry Andric    __s.__do_   = __state::__reject;
17370b57cec5SDimitry Andric    __s.__node_ = nullptr;
17380b57cec5SDimitry Andric  }
17390b57cec5SDimitry Andric}
17400b57cec5SDimitry Andric
17410b57cec5SDimitry Andric// __back_ref_collate
17420b57cec5SDimitry Andric
17430b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
1744cb14a3feSDimitry Andricclass __back_ref_collate : public __owns_one_state<_CharT> {
17450b57cec5SDimitry Andric  typedef __owns_one_state<_CharT> base;
17460b57cec5SDimitry Andric
17470b57cec5SDimitry Andric  _Traits __traits_;
17480b57cec5SDimitry Andric  unsigned __mexp_;
1749cb14a3feSDimitry Andric
17500b57cec5SDimitry Andricpublic:
17515f757f3fSDimitry Andric  typedef std::__state<_CharT> __state;
17520b57cec5SDimitry Andric
1753cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI explicit __back_ref_collate(const _Traits& __traits, unsigned __mexp, __node<_CharT>* __s)
17540b57cec5SDimitry Andric      : base(__s), __traits_(__traits), __mexp_(__mexp) {}
17550b57cec5SDimitry Andric
175606c3fb27SDimitry Andric  _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual void __exec(__state&) const;
17570b57cec5SDimitry Andric};
17580b57cec5SDimitry Andric
17590b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
1760cb14a3feSDimitry Andricvoid __back_ref_collate<_CharT, _Traits>::__exec(__state& __s) const {
17610b57cec5SDimitry Andric  sub_match<const _CharT*>& __sm = __s.__sub_matches_[__mexp_ - 1];
1762cb14a3feSDimitry Andric  if (__sm.matched) {
17630b57cec5SDimitry Andric    ptrdiff_t __len = __sm.second - __sm.first;
1764cb14a3feSDimitry Andric    if (__s.__last_ - __s.__current_ >= __len) {
1765cb14a3feSDimitry Andric      for (ptrdiff_t __i = 0; __i < __len; ++__i) {
1766cb14a3feSDimitry Andric        if (__traits_.translate(__sm.first[__i]) != __traits_.translate(__s.__current_[__i]))
17670b57cec5SDimitry Andric          goto __not_equal;
17680b57cec5SDimitry Andric      }
17690b57cec5SDimitry Andric      __s.__do_ = __state::__accept_but_not_consume;
17700b57cec5SDimitry Andric      __s.__current_ += __len;
17710b57cec5SDimitry Andric      __s.__node_ = this->first();
1772cb14a3feSDimitry Andric    } else {
17730b57cec5SDimitry Andric      __s.__do_   = __state::__reject;
17740b57cec5SDimitry Andric      __s.__node_ = nullptr;
17750b57cec5SDimitry Andric    }
1776cb14a3feSDimitry Andric  } else {
17770b57cec5SDimitry Andric  __not_equal:
17780b57cec5SDimitry Andric    __s.__do_   = __state::__reject;
17790b57cec5SDimitry Andric    __s.__node_ = nullptr;
17800b57cec5SDimitry Andric  }
17810b57cec5SDimitry Andric}
17820b57cec5SDimitry Andric
17830b57cec5SDimitry Andric// __word_boundary
17840b57cec5SDimitry Andric
17850b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
1786cb14a3feSDimitry Andricclass __word_boundary : public __owns_one_state<_CharT> {
17870b57cec5SDimitry Andric  typedef __owns_one_state<_CharT> base;
17880b57cec5SDimitry Andric
17890b57cec5SDimitry Andric  _Traits __traits_;
17900b57cec5SDimitry Andric  bool __invert_;
1791cb14a3feSDimitry Andric
17920b57cec5SDimitry Andricpublic:
17935f757f3fSDimitry Andric  typedef std::__state<_CharT> __state;
17940b57cec5SDimitry Andric
1795cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI explicit __word_boundary(const _Traits& __traits, bool __invert, __node<_CharT>* __s)
17960b57cec5SDimitry Andric      : base(__s), __traits_(__traits), __invert_(__invert) {}
17970b57cec5SDimitry Andric
179806c3fb27SDimitry Andric  _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual void __exec(__state&) const;
17990b57cec5SDimitry Andric};
18000b57cec5SDimitry Andric
18010b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
1802cb14a3feSDimitry Andricvoid __word_boundary<_CharT, _Traits>::__exec(__state& __s) const {
18030b57cec5SDimitry Andric  bool __is_word_b = false;
1804cb14a3feSDimitry Andric  if (__s.__first_ != __s.__last_) {
1805cb14a3feSDimitry Andric    if (__s.__current_ == __s.__last_) {
1806cb14a3feSDimitry Andric      if (!(__s.__flags_ & regex_constants::match_not_eow)) {
18070b57cec5SDimitry Andric        _CharT __c  = __s.__current_[-1];
1808cb14a3feSDimitry Andric        __is_word_b = __c == '_' || __traits_.isctype(__c, ctype_base::alnum);
18090b57cec5SDimitry Andric      }
1810cb14a3feSDimitry Andric    } else if (__s.__current_ == __s.__first_ && !(__s.__flags_ & regex_constants::match_prev_avail)) {
1811cb14a3feSDimitry Andric      if (!(__s.__flags_ & regex_constants::match_not_bow)) {
18120b57cec5SDimitry Andric        _CharT __c  = *__s.__current_;
1813cb14a3feSDimitry Andric        __is_word_b = __c == '_' || __traits_.isctype(__c, ctype_base::alnum);
18140b57cec5SDimitry Andric      }
1815cb14a3feSDimitry Andric    } else {
18160b57cec5SDimitry Andric      _CharT __c1    = __s.__current_[-1];
18170b57cec5SDimitry Andric      _CharT __c2    = *__s.__current_;
1818cb14a3feSDimitry Andric      bool __is_c1_b = __c1 == '_' || __traits_.isctype(__c1, ctype_base::alnum);
1819cb14a3feSDimitry Andric      bool __is_c2_b = __c2 == '_' || __traits_.isctype(__c2, ctype_base::alnum);
18200b57cec5SDimitry Andric      __is_word_b    = __is_c1_b != __is_c2_b;
18210b57cec5SDimitry Andric    }
18220b57cec5SDimitry Andric  }
1823cb14a3feSDimitry Andric  if (__is_word_b != __invert_) {
18240b57cec5SDimitry Andric    __s.__do_   = __state::__accept_but_not_consume;
18250b57cec5SDimitry Andric    __s.__node_ = this->first();
1826cb14a3feSDimitry Andric  } else {
18270b57cec5SDimitry Andric    __s.__do_   = __state::__reject;
18280b57cec5SDimitry Andric    __s.__node_ = nullptr;
18290b57cec5SDimitry Andric  }
18300b57cec5SDimitry Andric}
18310b57cec5SDimitry Andric
18320b57cec5SDimitry Andric// __l_anchor
18330b57cec5SDimitry Andric
18340b57cec5SDimitry Andrictemplate <class _CharT>
1835cb14a3feSDimitry Andric_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR bool __is_eol(_CharT __c) {
1836753f127fSDimitry Andric  return __c == '\r' || __c == '\n';
1837e8d8bef9SDimitry Andric}
1838e8d8bef9SDimitry Andric
1839e8d8bef9SDimitry Andrictemplate <class _CharT>
1840cb14a3feSDimitry Andricclass __l_anchor_multiline : public __owns_one_state<_CharT> {
18410b57cec5SDimitry Andric  typedef __owns_one_state<_CharT> base;
18420b57cec5SDimitry Andric
1843fe6060f1SDimitry Andric  bool __multiline_;
1844e8d8bef9SDimitry Andric
18450b57cec5SDimitry Andricpublic:
18465f757f3fSDimitry Andric  typedef std::__state<_CharT> __state;
18470b57cec5SDimitry Andric
1848cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI __l_anchor_multiline(bool __multiline, __node<_CharT>* __s)
1849fe6060f1SDimitry Andric      : base(__s), __multiline_(__multiline) {}
18500b57cec5SDimitry Andric
185106c3fb27SDimitry Andric  _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual void __exec(__state&) const;
18520b57cec5SDimitry Andric};
18530b57cec5SDimitry Andric
18540b57cec5SDimitry Andrictemplate <class _CharT>
1855cb14a3feSDimitry Andricvoid __l_anchor_multiline<_CharT>::__exec(__state& __s) const {
1856cb14a3feSDimitry Andric  if (__s.__at_first_ && __s.__current_ == __s.__first_ && !(__s.__flags_ & regex_constants::match_not_bol)) {
18570b57cec5SDimitry Andric    __s.__do_   = __state::__accept_but_not_consume;
18580b57cec5SDimitry Andric    __s.__node_ = this->first();
1859cb14a3feSDimitry Andric  } else if (__multiline_ && !__s.__at_first_ && std::__is_eol(*std::prev(__s.__current_))) {
1860e8d8bef9SDimitry Andric    __s.__do_   = __state::__accept_but_not_consume;
1861e8d8bef9SDimitry Andric    __s.__node_ = this->first();
1862cb14a3feSDimitry Andric  } else {
18630b57cec5SDimitry Andric    __s.__do_   = __state::__reject;
18640b57cec5SDimitry Andric    __s.__node_ = nullptr;
18650b57cec5SDimitry Andric  }
18660b57cec5SDimitry Andric}
18670b57cec5SDimitry Andric
18680b57cec5SDimitry Andric// __r_anchor
18690b57cec5SDimitry Andric
18700b57cec5SDimitry Andrictemplate <class _CharT>
1871cb14a3feSDimitry Andricclass __r_anchor_multiline : public __owns_one_state<_CharT> {
18720b57cec5SDimitry Andric  typedef __owns_one_state<_CharT> base;
18730b57cec5SDimitry Andric
187481ad6265SDimitry Andric  bool __multiline_;
1875e8d8bef9SDimitry Andric
18760b57cec5SDimitry Andricpublic:
18775f757f3fSDimitry Andric  typedef std::__state<_CharT> __state;
18780b57cec5SDimitry Andric
1879cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI __r_anchor_multiline(bool __multiline, __node<_CharT>* __s)
188081ad6265SDimitry Andric      : base(__s), __multiline_(__multiline) {}
18810b57cec5SDimitry Andric
188206c3fb27SDimitry Andric  _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual void __exec(__state&) const;
18830b57cec5SDimitry Andric};
18840b57cec5SDimitry Andric
18850b57cec5SDimitry Andrictemplate <class _CharT>
1886cb14a3feSDimitry Andricvoid __r_anchor_multiline<_CharT>::__exec(__state& __s) const {
1887cb14a3feSDimitry Andric  if (__s.__current_ == __s.__last_ && !(__s.__flags_ & regex_constants::match_not_eol)) {
18880b57cec5SDimitry Andric    __s.__do_   = __state::__accept_but_not_consume;
18890b57cec5SDimitry Andric    __s.__node_ = this->first();
1890cb14a3feSDimitry Andric  } else if (__multiline_ && std::__is_eol(*__s.__current_)) {
1891e8d8bef9SDimitry Andric    __s.__do_   = __state::__accept_but_not_consume;
1892e8d8bef9SDimitry Andric    __s.__node_ = this->first();
1893cb14a3feSDimitry Andric  } else {
18940b57cec5SDimitry Andric    __s.__do_   = __state::__reject;
18950b57cec5SDimitry Andric    __s.__node_ = nullptr;
18960b57cec5SDimitry Andric  }
18970b57cec5SDimitry Andric}
18980b57cec5SDimitry Andric
18990b57cec5SDimitry Andric// __match_any
19000b57cec5SDimitry Andric
19010b57cec5SDimitry Andrictemplate <class _CharT>
1902cb14a3feSDimitry Andricclass __match_any : public __owns_one_state<_CharT> {
19030b57cec5SDimitry Andric  typedef __owns_one_state<_CharT> base;
19040b57cec5SDimitry Andric
19050b57cec5SDimitry Andricpublic:
19065f757f3fSDimitry Andric  typedef std::__state<_CharT> __state;
19070b57cec5SDimitry Andric
1908cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI __match_any(__node<_CharT>* __s) : base(__s) {}
19090b57cec5SDimitry Andric
191006c3fb27SDimitry Andric  _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual void __exec(__state&) const;
19110b57cec5SDimitry Andric};
19120b57cec5SDimitry Andric
19130b57cec5SDimitry Andrictemplate <class _CharT>
1914cb14a3feSDimitry Andricvoid __match_any<_CharT>::__exec(__state& __s) const {
1915cb14a3feSDimitry Andric  if (__s.__current_ != __s.__last_ && *__s.__current_ != 0) {
19160b57cec5SDimitry Andric    __s.__do_ = __state::__accept_and_consume;
19170b57cec5SDimitry Andric    ++__s.__current_;
19180b57cec5SDimitry Andric    __s.__node_ = this->first();
1919cb14a3feSDimitry Andric  } else {
19200b57cec5SDimitry Andric    __s.__do_   = __state::__reject;
19210b57cec5SDimitry Andric    __s.__node_ = nullptr;
19220b57cec5SDimitry Andric  }
19230b57cec5SDimitry Andric}
19240b57cec5SDimitry Andric
19250b57cec5SDimitry Andric// __match_any_but_newline
19260b57cec5SDimitry Andric
19270b57cec5SDimitry Andrictemplate <class _CharT>
1928cb14a3feSDimitry Andricclass __match_any_but_newline : public __owns_one_state<_CharT> {
19290b57cec5SDimitry Andric  typedef __owns_one_state<_CharT> base;
19300b57cec5SDimitry Andric
19310b57cec5SDimitry Andricpublic:
19325f757f3fSDimitry Andric  typedef std::__state<_CharT> __state;
19330b57cec5SDimitry Andric
1934cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI __match_any_but_newline(__node<_CharT>* __s) : base(__s) {}
19350b57cec5SDimitry Andric
1936bdd1243dSDimitry Andric  void __exec(__state&) const override;
19370b57cec5SDimitry Andric};
19380b57cec5SDimitry Andric
1939cb14a3feSDimitry Andrictemplate <>
1940cb14a3feSDimitry Andric_LIBCPP_EXPORTED_FROM_ABI void __match_any_but_newline<char>::__exec(__state&) const;
1941349cc55cSDimitry Andric#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
1942cb14a3feSDimitry Andrictemplate <>
1943cb14a3feSDimitry Andric_LIBCPP_EXPORTED_FROM_ABI void __match_any_but_newline<wchar_t>::__exec(__state&) const;
1944349cc55cSDimitry Andric#endif
19450b57cec5SDimitry Andric
19460b57cec5SDimitry Andric// __match_char
19470b57cec5SDimitry Andric
19480b57cec5SDimitry Andrictemplate <class _CharT>
1949cb14a3feSDimitry Andricclass __match_char : public __owns_one_state<_CharT> {
19500b57cec5SDimitry Andric  typedef __owns_one_state<_CharT> base;
19510b57cec5SDimitry Andric
19520b57cec5SDimitry Andric  _CharT __c_;
19530b57cec5SDimitry Andric
19540b57cec5SDimitry Andricpublic:
19555f757f3fSDimitry Andric  typedef std::__state<_CharT> __state;
19560b57cec5SDimitry Andric
1957cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI __match_char(_CharT __c, __node<_CharT>* __s) : base(__s), __c_(__c) {}
19580b57cec5SDimitry Andric
1959*0fca6ea1SDimitry Andric  __match_char(const __match_char&)            = delete;
1960*0fca6ea1SDimitry Andric  __match_char& operator=(const __match_char&) = delete;
1961*0fca6ea1SDimitry Andric
196206c3fb27SDimitry Andric  _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual void __exec(__state&) const;
19630b57cec5SDimitry Andric};
19640b57cec5SDimitry Andric
19650b57cec5SDimitry Andrictemplate <class _CharT>
1966cb14a3feSDimitry Andricvoid __match_char<_CharT>::__exec(__state& __s) const {
1967cb14a3feSDimitry Andric  if (__s.__current_ != __s.__last_ && *__s.__current_ == __c_) {
19680b57cec5SDimitry Andric    __s.__do_ = __state::__accept_and_consume;
19690b57cec5SDimitry Andric    ++__s.__current_;
19700b57cec5SDimitry Andric    __s.__node_ = this->first();
1971cb14a3feSDimitry Andric  } else {
19720b57cec5SDimitry Andric    __s.__do_   = __state::__reject;
19730b57cec5SDimitry Andric    __s.__node_ = nullptr;
19740b57cec5SDimitry Andric  }
19750b57cec5SDimitry Andric}
19760b57cec5SDimitry Andric
19770b57cec5SDimitry Andric// __match_char_icase
19780b57cec5SDimitry Andric
19790b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
1980cb14a3feSDimitry Andricclass __match_char_icase : public __owns_one_state<_CharT> {
19810b57cec5SDimitry Andric  typedef __owns_one_state<_CharT> base;
19820b57cec5SDimitry Andric
19830b57cec5SDimitry Andric  _Traits __traits_;
19840b57cec5SDimitry Andric  _CharT __c_;
19850b57cec5SDimitry Andric
19860b57cec5SDimitry Andricpublic:
19875f757f3fSDimitry Andric  typedef std::__state<_CharT> __state;
19880b57cec5SDimitry Andric
1989cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI __match_char_icase(const _Traits& __traits, _CharT __c, __node<_CharT>* __s)
19900b57cec5SDimitry Andric      : base(__s), __traits_(__traits), __c_(__traits.translate_nocase(__c)) {}
19910b57cec5SDimitry Andric
1992*0fca6ea1SDimitry Andric  __match_char_icase(const __match_char_icase&)            = delete;
1993*0fca6ea1SDimitry Andric  __match_char_icase& operator=(const __match_char_icase&) = delete;
1994*0fca6ea1SDimitry Andric
199506c3fb27SDimitry Andric  _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual void __exec(__state&) const;
19960b57cec5SDimitry Andric};
19970b57cec5SDimitry Andric
19980b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
1999cb14a3feSDimitry Andricvoid __match_char_icase<_CharT, _Traits>::__exec(__state& __s) const {
2000cb14a3feSDimitry Andric  if (__s.__current_ != __s.__last_ && __traits_.translate_nocase(*__s.__current_) == __c_) {
20010b57cec5SDimitry Andric    __s.__do_ = __state::__accept_and_consume;
20020b57cec5SDimitry Andric    ++__s.__current_;
20030b57cec5SDimitry Andric    __s.__node_ = this->first();
2004cb14a3feSDimitry Andric  } else {
20050b57cec5SDimitry Andric    __s.__do_   = __state::__reject;
20060b57cec5SDimitry Andric    __s.__node_ = nullptr;
20070b57cec5SDimitry Andric  }
20080b57cec5SDimitry Andric}
20090b57cec5SDimitry Andric
20100b57cec5SDimitry Andric// __match_char_collate
20110b57cec5SDimitry Andric
20120b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
2013cb14a3feSDimitry Andricclass __match_char_collate : public __owns_one_state<_CharT> {
20140b57cec5SDimitry Andric  typedef __owns_one_state<_CharT> base;
20150b57cec5SDimitry Andric
20160b57cec5SDimitry Andric  _Traits __traits_;
20170b57cec5SDimitry Andric  _CharT __c_;
20180b57cec5SDimitry Andric
20190b57cec5SDimitry Andricpublic:
20205f757f3fSDimitry Andric  typedef std::__state<_CharT> __state;
20210b57cec5SDimitry Andric
2022cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI __match_char_collate(const _Traits& __traits, _CharT __c, __node<_CharT>* __s)
20230b57cec5SDimitry Andric      : base(__s), __traits_(__traits), __c_(__traits.translate(__c)) {}
20240b57cec5SDimitry Andric
2025*0fca6ea1SDimitry Andric  __match_char_collate(const __match_char_collate&)            = delete;
2026*0fca6ea1SDimitry Andric  __match_char_collate& operator=(const __match_char_collate&) = delete;
2027*0fca6ea1SDimitry Andric
202806c3fb27SDimitry Andric  _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual void __exec(__state&) const;
20290b57cec5SDimitry Andric};
20300b57cec5SDimitry Andric
20310b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
2032cb14a3feSDimitry Andricvoid __match_char_collate<_CharT, _Traits>::__exec(__state& __s) const {
2033cb14a3feSDimitry Andric  if (__s.__current_ != __s.__last_ && __traits_.translate(*__s.__current_) == __c_) {
20340b57cec5SDimitry Andric    __s.__do_ = __state::__accept_and_consume;
20350b57cec5SDimitry Andric    ++__s.__current_;
20360b57cec5SDimitry Andric    __s.__node_ = this->first();
2037cb14a3feSDimitry Andric  } else {
20380b57cec5SDimitry Andric    __s.__do_   = __state::__reject;
20390b57cec5SDimitry Andric    __s.__node_ = nullptr;
20400b57cec5SDimitry Andric  }
20410b57cec5SDimitry Andric}
20420b57cec5SDimitry Andric
20430b57cec5SDimitry Andric// __bracket_expression
20440b57cec5SDimitry Andric
20450b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
2046cb14a3feSDimitry Andricclass __bracket_expression : public __owns_one_state<_CharT> {
20470b57cec5SDimitry Andric  typedef __owns_one_state<_CharT> base;
20480b57cec5SDimitry Andric  typedef typename _Traits::string_type string_type;
20490b57cec5SDimitry Andric
20500b57cec5SDimitry Andric  _Traits __traits_;
20510b57cec5SDimitry Andric  vector<_CharT> __chars_;
20520b57cec5SDimitry Andric  vector<_CharT> __neg_chars_;
20530b57cec5SDimitry Andric  vector<pair<string_type, string_type> > __ranges_;
20540b57cec5SDimitry Andric  vector<pair<_CharT, _CharT> > __digraphs_;
20550b57cec5SDimitry Andric  vector<string_type> __equivalences_;
20560b57cec5SDimitry Andric  typename regex_traits<_CharT>::char_class_type __mask_;
20570b57cec5SDimitry Andric  typename regex_traits<_CharT>::char_class_type __neg_mask_;
20580b57cec5SDimitry Andric  bool __negate_;
20590b57cec5SDimitry Andric  bool __icase_;
20600b57cec5SDimitry Andric  bool __collate_;
20610b57cec5SDimitry Andric  bool __might_have_digraph_;
20620b57cec5SDimitry Andric
20630b57cec5SDimitry Andricpublic:
20645f757f3fSDimitry Andric  typedef std::__state<_CharT> __state;
20650b57cec5SDimitry Andric
20665f757f3fSDimitry Andric  _LIBCPP_HIDE_FROM_ABI
2067cb14a3feSDimitry Andric  __bracket_expression(const _Traits& __traits, __node<_CharT>* __s, bool __negate, bool __icase, bool __collate)
2068cb14a3feSDimitry Andric      : base(__s),
2069cb14a3feSDimitry Andric        __traits_(__traits),
2070cb14a3feSDimitry Andric        __mask_(),
2071cb14a3feSDimitry Andric        __neg_mask_(),
2072cb14a3feSDimitry Andric        __negate_(__negate),
2073cb14a3feSDimitry Andric        __icase_(__icase),
2074cb14a3feSDimitry Andric        __collate_(__collate),
20750b57cec5SDimitry Andric        __might_have_digraph_(__traits_.getloc().name() != "C") {}
20760b57cec5SDimitry Andric
2077*0fca6ea1SDimitry Andric  __bracket_expression(const __bracket_expression&)            = delete;
2078*0fca6ea1SDimitry Andric  __bracket_expression& operator=(const __bracket_expression&) = delete;
2079*0fca6ea1SDimitry Andric
208006c3fb27SDimitry Andric  _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual void __exec(__state&) const;
20810b57cec5SDimitry Andric
2082cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI bool __negated() const { return __negate_; }
20830b57cec5SDimitry Andric
2084cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void __add_char(_CharT __c) {
20850b57cec5SDimitry Andric    if (__icase_)
20860b57cec5SDimitry Andric      __chars_.push_back(__traits_.translate_nocase(__c));
20870b57cec5SDimitry Andric    else if (__collate_)
20880b57cec5SDimitry Andric      __chars_.push_back(__traits_.translate(__c));
20890b57cec5SDimitry Andric    else
20900b57cec5SDimitry Andric      __chars_.push_back(__c);
20910b57cec5SDimitry Andric  }
2092cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void __add_neg_char(_CharT __c) {
20930b57cec5SDimitry Andric    if (__icase_)
20940b57cec5SDimitry Andric      __neg_chars_.push_back(__traits_.translate_nocase(__c));
20950b57cec5SDimitry Andric    else if (__collate_)
20960b57cec5SDimitry Andric      __neg_chars_.push_back(__traits_.translate(__c));
20970b57cec5SDimitry Andric    else
20980b57cec5SDimitry Andric      __neg_chars_.push_back(__c);
20990b57cec5SDimitry Andric  }
2100cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void __add_range(string_type __b, string_type __e) {
2101cb14a3feSDimitry Andric    if (__collate_) {
2102cb14a3feSDimitry Andric      if (__icase_) {
21030b57cec5SDimitry Andric        for (size_t __i = 0; __i < __b.size(); ++__i)
21040b57cec5SDimitry Andric          __b[__i] = __traits_.translate_nocase(__b[__i]);
21050b57cec5SDimitry Andric        for (size_t __i = 0; __i < __e.size(); ++__i)
21060b57cec5SDimitry Andric          __e[__i] = __traits_.translate_nocase(__e[__i]);
2107cb14a3feSDimitry Andric      } else {
21080b57cec5SDimitry Andric        for (size_t __i = 0; __i < __b.size(); ++__i)
21090b57cec5SDimitry Andric          __b[__i] = __traits_.translate(__b[__i]);
21100b57cec5SDimitry Andric        for (size_t __i = 0; __i < __e.size(); ++__i)
21110b57cec5SDimitry Andric          __e[__i] = __traits_.translate(__e[__i]);
21120b57cec5SDimitry Andric      }
2113cb14a3feSDimitry Andric      __ranges_.push_back(
2114cb14a3feSDimitry Andric          std::make_pair(__traits_.transform(__b.begin(), __b.end()), __traits_.transform(__e.begin(), __e.end())));
2115cb14a3feSDimitry Andric    } else {
21160b57cec5SDimitry Andric      if (__b.size() != 1 || __e.size() != 1)
21170b57cec5SDimitry Andric        __throw_regex_error<regex_constants::error_range>();
2118cb14a3feSDimitry Andric      if (__icase_) {
21190b57cec5SDimitry Andric        __b[0] = __traits_.translate_nocase(__b[0]);
21200b57cec5SDimitry Andric        __e[0] = __traits_.translate_nocase(__e[0]);
21210b57cec5SDimitry Andric      }
21225f757f3fSDimitry Andric      __ranges_.push_back(std::make_pair(std::move(__b), std::move(__e)));
21230b57cec5SDimitry Andric    }
21240b57cec5SDimitry Andric  }
2125cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void __add_digraph(_CharT __c1, _CharT __c2) {
21260b57cec5SDimitry Andric    if (__icase_)
2127cb14a3feSDimitry Andric      __digraphs_.push_back(std::make_pair(__traits_.translate_nocase(__c1), __traits_.translate_nocase(__c2)));
21280b57cec5SDimitry Andric    else if (__collate_)
2129cb14a3feSDimitry Andric      __digraphs_.push_back(std::make_pair(__traits_.translate(__c1), __traits_.translate(__c2)));
21300b57cec5SDimitry Andric    else
2131bdd1243dSDimitry Andric      __digraphs_.push_back(std::make_pair(__c1, __c2));
21320b57cec5SDimitry Andric  }
2133cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void __add_equivalence(const string_type& __s) { __equivalences_.push_back(__s); }
2134cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void __add_class(typename regex_traits<_CharT>::char_class_type __mask) { __mask_ |= __mask; }
2135cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void __add_neg_class(typename regex_traits<_CharT>::char_class_type __mask) {
2136cb14a3feSDimitry Andric    __neg_mask_ |= __mask;
2137cb14a3feSDimitry Andric  }
21380b57cec5SDimitry Andric};
21390b57cec5SDimitry Andric
21400b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
2141cb14a3feSDimitry Andricvoid __bracket_expression<_CharT, _Traits>::__exec(__state& __s) const {
21420b57cec5SDimitry Andric  bool __found        = false;
21430b57cec5SDimitry Andric  unsigned __consumed = 0;
2144cb14a3feSDimitry Andric  if (__s.__current_ != __s.__last_) {
21450b57cec5SDimitry Andric    ++__consumed;
2146cb14a3feSDimitry Andric    if (__might_have_digraph_) {
21475f757f3fSDimitry Andric      const _CharT* __next = std::next(__s.__current_);
2148cb14a3feSDimitry Andric      if (__next != __s.__last_) {
21490b57cec5SDimitry Andric        pair<_CharT, _CharT> __ch2(*__s.__current_, *__next);
2150cb14a3feSDimitry Andric        if (__icase_) {
21510b57cec5SDimitry Andric          __ch2.first  = __traits_.translate_nocase(__ch2.first);
21520b57cec5SDimitry Andric          __ch2.second = __traits_.translate_nocase(__ch2.second);
2153cb14a3feSDimitry Andric        } else if (__collate_) {
21540b57cec5SDimitry Andric          __ch2.first  = __traits_.translate(__ch2.first);
21550b57cec5SDimitry Andric          __ch2.second = __traits_.translate(__ch2.second);
21560b57cec5SDimitry Andric        }
2157cb14a3feSDimitry Andric        if (!__traits_.lookup_collatename(&__ch2.first, &__ch2.first + 2).empty()) {
21580b57cec5SDimitry Andric          // __ch2 is a digraph in this locale
21590b57cec5SDimitry Andric          ++__consumed;
2160cb14a3feSDimitry Andric          for (size_t __i = 0; __i < __digraphs_.size(); ++__i) {
2161cb14a3feSDimitry Andric            if (__ch2 == __digraphs_[__i]) {
21620b57cec5SDimitry Andric              __found = true;
21630b57cec5SDimitry Andric              goto __exit;
21640b57cec5SDimitry Andric            }
21650b57cec5SDimitry Andric          }
2166cb14a3feSDimitry Andric          if (__collate_ && !__ranges_.empty()) {
2167cb14a3feSDimitry Andric            string_type __s2 = __traits_.transform(&__ch2.first, &__ch2.first + 2);
2168cb14a3feSDimitry Andric            for (size_t __i = 0; __i < __ranges_.size(); ++__i) {
2169cb14a3feSDimitry Andric              if (__ranges_[__i].first <= __s2 && __s2 <= __ranges_[__i].second) {
21700b57cec5SDimitry Andric                __found = true;
21710b57cec5SDimitry Andric                goto __exit;
21720b57cec5SDimitry Andric              }
21730b57cec5SDimitry Andric            }
21740b57cec5SDimitry Andric          }
2175cb14a3feSDimitry Andric          if (!__equivalences_.empty()) {
2176cb14a3feSDimitry Andric            string_type __s2 = __traits_.transform_primary(&__ch2.first, &__ch2.first + 2);
2177cb14a3feSDimitry Andric            for (size_t __i = 0; __i < __equivalences_.size(); ++__i) {
2178cb14a3feSDimitry Andric              if (__s2 == __equivalences_[__i]) {
21790b57cec5SDimitry Andric                __found = true;
21800b57cec5SDimitry Andric                goto __exit;
21810b57cec5SDimitry Andric              }
21820b57cec5SDimitry Andric            }
21830b57cec5SDimitry Andric          }
2184cb14a3feSDimitry Andric          if (__traits_.isctype(__ch2.first, __mask_) && __traits_.isctype(__ch2.second, __mask_)) {
21850b57cec5SDimitry Andric            __found = true;
21860b57cec5SDimitry Andric            goto __exit;
21870b57cec5SDimitry Andric          }
2188cb14a3feSDimitry Andric          if (!__traits_.isctype(__ch2.first, __neg_mask_) && !__traits_.isctype(__ch2.second, __neg_mask_)) {
21890b57cec5SDimitry Andric            __found = true;
21900b57cec5SDimitry Andric            goto __exit;
21910b57cec5SDimitry Andric          }
21920b57cec5SDimitry Andric          goto __exit;
21930b57cec5SDimitry Andric        }
21940b57cec5SDimitry Andric      }
21950b57cec5SDimitry Andric    }
21960b57cec5SDimitry Andric    // test *__s.__current_ as not a digraph
21970b57cec5SDimitry Andric    _CharT __ch = *__s.__current_;
21980b57cec5SDimitry Andric    if (__icase_)
21990b57cec5SDimitry Andric      __ch = __traits_.translate_nocase(__ch);
22000b57cec5SDimitry Andric    else if (__collate_)
22010b57cec5SDimitry Andric      __ch = __traits_.translate(__ch);
2202cb14a3feSDimitry Andric    for (size_t __i = 0; __i < __chars_.size(); ++__i) {
2203cb14a3feSDimitry Andric      if (__ch == __chars_[__i]) {
22040b57cec5SDimitry Andric        __found = true;
22050b57cec5SDimitry Andric        goto __exit;
22060b57cec5SDimitry Andric      }
22070b57cec5SDimitry Andric    }
22080b57cec5SDimitry Andric    // When there's at least one of __neg_chars_ and __neg_mask_, the set
22090b57cec5SDimitry Andric    // of "__found" chars is
22100b57cec5SDimitry Andric    //   union(complement(union(__neg_chars_, __neg_mask_)),
22110b57cec5SDimitry Andric    //         other cases...)
22120b57cec5SDimitry Andric    //
22130b57cec5SDimitry Andric    // It doesn't make sense to check this when there are no __neg_chars_
22140b57cec5SDimitry Andric    // and no __neg_mask_.
2215cb14a3feSDimitry Andric    if (!(__neg_mask_ == 0 && __neg_chars_.empty())) {
22160b57cec5SDimitry Andric      const bool __in_neg_mask  = __traits_.isctype(__ch, __neg_mask_);
2217cb14a3feSDimitry Andric      const bool __in_neg_chars = std::find(__neg_chars_.begin(), __neg_chars_.end(), __ch) != __neg_chars_.end();
2218cb14a3feSDimitry Andric      if (!(__in_neg_mask || __in_neg_chars)) {
22190b57cec5SDimitry Andric        __found = true;
22200b57cec5SDimitry Andric        goto __exit;
22210b57cec5SDimitry Andric      }
22220b57cec5SDimitry Andric    }
2223cb14a3feSDimitry Andric    if (!__ranges_.empty()) {
2224cb14a3feSDimitry Andric      string_type __s2 = __collate_ ? __traits_.transform(&__ch, &__ch + 1) : string_type(1, __ch);
2225cb14a3feSDimitry Andric      for (size_t __i = 0; __i < __ranges_.size(); ++__i) {
2226cb14a3feSDimitry Andric        if (__ranges_[__i].first <= __s2 && __s2 <= __ranges_[__i].second) {
22270b57cec5SDimitry Andric          __found = true;
22280b57cec5SDimitry Andric          goto __exit;
22290b57cec5SDimitry Andric        }
22300b57cec5SDimitry Andric      }
22310b57cec5SDimitry Andric    }
2232cb14a3feSDimitry Andric    if (!__equivalences_.empty()) {
22330b57cec5SDimitry Andric      string_type __s2 = __traits_.transform_primary(&__ch, &__ch + 1);
2234cb14a3feSDimitry Andric      for (size_t __i = 0; __i < __equivalences_.size(); ++__i) {
2235cb14a3feSDimitry Andric        if (__s2 == __equivalences_[__i]) {
22360b57cec5SDimitry Andric          __found = true;
22370b57cec5SDimitry Andric          goto __exit;
22380b57cec5SDimitry Andric        }
22390b57cec5SDimitry Andric      }
22400b57cec5SDimitry Andric    }
2241cb14a3feSDimitry Andric    if (__traits_.isctype(__ch, __mask_)) {
22420b57cec5SDimitry Andric      __found = true;
22430b57cec5SDimitry Andric      goto __exit;
22440b57cec5SDimitry Andric    }
2245cb14a3feSDimitry Andric  } else
22460b57cec5SDimitry Andric    __found = __negate_; // force reject
22470b57cec5SDimitry Andric__exit:
2248cb14a3feSDimitry Andric  if (__found != __negate_) {
22490b57cec5SDimitry Andric    __s.__do_ = __state::__accept_and_consume;
22500b57cec5SDimitry Andric    __s.__current_ += __consumed;
22510b57cec5SDimitry Andric    __s.__node_ = this->first();
2252cb14a3feSDimitry Andric  } else {
22530b57cec5SDimitry Andric    __s.__do_   = __state::__reject;
22540b57cec5SDimitry Andric    __s.__node_ = nullptr;
22550b57cec5SDimitry Andric  }
22560b57cec5SDimitry Andric}
22570b57cec5SDimitry Andric
2258cb14a3feSDimitry Andrictemplate <class _CharT, class _Traits>
2259cb14a3feSDimitry Andricclass __lookahead;
22600b57cec5SDimitry Andric
22610b57cec5SDimitry Andrictemplate <class _CharT, class _Traits = regex_traits<_CharT> >
2262e8d8bef9SDimitry Andricclass _LIBCPP_TEMPLATE_VIS basic_regex;
2263e8d8bef9SDimitry Andric
2264e8d8bef9SDimitry Andrictypedef basic_regex<char> regex;
2265349cc55cSDimitry Andric#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
2266e8d8bef9SDimitry Andrictypedef basic_regex<wchar_t> wregex;
2267349cc55cSDimitry Andric#endif
2268e8d8bef9SDimitry Andric
2269e8d8bef9SDimitry Andrictemplate <class _CharT, class _Traits>
2270cb14a3feSDimitry Andricclass _LIBCPP_TEMPLATE_VIS _LIBCPP_PREFERRED_NAME(regex)
2271cb14a3feSDimitry Andric    _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wregex)) basic_regex {
22720b57cec5SDimitry Andricpublic:
22730b57cec5SDimitry Andric  // types:
22740b57cec5SDimitry Andric  typedef _CharT value_type;
22750b57cec5SDimitry Andric  typedef _Traits traits_type;
22760b57cec5SDimitry Andric  typedef typename _Traits::string_type string_type;
22770b57cec5SDimitry Andric  typedef regex_constants::syntax_option_type flag_type;
22780b57cec5SDimitry Andric  typedef typename _Traits::locale_type locale_type;
22790b57cec5SDimitry Andric
22800b57cec5SDimitry Andricprivate:
22810b57cec5SDimitry Andric  _Traits __traits_;
22820b57cec5SDimitry Andric  flag_type __flags_;
22830b57cec5SDimitry Andric  unsigned __marked_count_;
22840b57cec5SDimitry Andric  unsigned __loop_count_;
22850b57cec5SDimitry Andric  int __open_count_;
22860b57cec5SDimitry Andric  shared_ptr<__empty_state<_CharT> > __start_;
22870b57cec5SDimitry Andric  __owns_one_state<_CharT>* __end_;
22880b57cec5SDimitry Andric
22895f757f3fSDimitry Andric  typedef std::__state<_CharT> __state;
22905f757f3fSDimitry Andric  typedef std::__node<_CharT> __node;
22910b57cec5SDimitry Andric
22920b57cec5SDimitry Andricpublic:
22930b57cec5SDimitry Andric  // constants:
22940b57cec5SDimitry Andric  static const regex_constants::syntax_option_type icase      = regex_constants::icase;
22950b57cec5SDimitry Andric  static const regex_constants::syntax_option_type nosubs     = regex_constants::nosubs;
22960b57cec5SDimitry Andric  static const regex_constants::syntax_option_type optimize   = regex_constants::optimize;
22970b57cec5SDimitry Andric  static const regex_constants::syntax_option_type collate    = regex_constants::collate;
22980b57cec5SDimitry Andric  static const regex_constants::syntax_option_type ECMAScript = regex_constants::ECMAScript;
22990b57cec5SDimitry Andric  static const regex_constants::syntax_option_type basic      = regex_constants::basic;
23000b57cec5SDimitry Andric  static const regex_constants::syntax_option_type extended   = regex_constants::extended;
23010b57cec5SDimitry Andric  static const regex_constants::syntax_option_type awk        = regex_constants::awk;
23020b57cec5SDimitry Andric  static const regex_constants::syntax_option_type grep       = regex_constants::grep;
23030b57cec5SDimitry Andric  static const regex_constants::syntax_option_type egrep      = regex_constants::egrep;
2304e8d8bef9SDimitry Andric  static const regex_constants::syntax_option_type multiline  = regex_constants::multiline;
23050b57cec5SDimitry Andric
23060b57cec5SDimitry Andric  // construct/copy/destroy:
2307cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI basic_regex()
2308cb14a3feSDimitry Andric      : __flags_(regex_constants::ECMAScript),
2309cb14a3feSDimitry Andric        __marked_count_(0),
2310cb14a3feSDimitry Andric        __loop_count_(0),
2311cb14a3feSDimitry Andric        __open_count_(0),
2312cb14a3feSDimitry Andric        __end_(nullptr) {}
2313cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI explicit basic_regex(const value_type* __p, flag_type __f = regex_constants::ECMAScript)
2314cb14a3feSDimitry Andric      : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), __end_(nullptr) {
2315480093f4SDimitry Andric    __init(__p, __p + __traits_.length(__p));
23160b57cec5SDimitry Andric  }
23170b57cec5SDimitry Andric
2318cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI basic_regex(const value_type* __p, size_t __len, flag_type __f = regex_constants::ECMAScript)
2319cb14a3feSDimitry Andric      : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), __end_(nullptr) {
2320480093f4SDimitry Andric    __init(__p, __p + __len);
23210b57cec5SDimitry Andric  }
23220b57cec5SDimitry Andric
23230b57cec5SDimitry Andric  //     basic_regex(const basic_regex&) = default;
23240b57cec5SDimitry Andric  //     basic_regex(basic_regex&&) = default;
23250b57cec5SDimitry Andric  template <class _ST, class _SA>
2326cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI explicit basic_regex(const basic_string<value_type, _ST, _SA>& __p,
23270b57cec5SDimitry Andric                                             flag_type __f = regex_constants::ECMAScript)
2328cb14a3feSDimitry Andric      : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), __end_(nullptr) {
2329480093f4SDimitry Andric    __init(__p.begin(), __p.end());
23300b57cec5SDimitry Andric  }
23310b57cec5SDimitry Andric
23320b57cec5SDimitry Andric  template <class _ForwardIterator>
23335f757f3fSDimitry Andric  _LIBCPP_HIDE_FROM_ABI
2334cb14a3feSDimitry Andric  basic_regex(_ForwardIterator __first, _ForwardIterator __last, flag_type __f = regex_constants::ECMAScript)
2335cb14a3feSDimitry Andric      : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), __end_(nullptr) {
2336480093f4SDimitry Andric    __init(__first, __last);
23370b57cec5SDimitry Andric  }
23380b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
2339cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI basic_regex(initializer_list<value_type> __il, flag_type __f = regex_constants::ECMAScript)
2340cb14a3feSDimitry Andric      : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), __end_(nullptr) {
2341480093f4SDimitry Andric    __init(__il.begin(), __il.end());
23420b57cec5SDimitry Andric  }
23430b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG
23440b57cec5SDimitry Andric
23450b57cec5SDimitry Andric  //    ~basic_regex() = default;
23460b57cec5SDimitry Andric
23470b57cec5SDimitry Andric  //     basic_regex& operator=(const basic_regex&) = default;
23480b57cec5SDimitry Andric  //     basic_regex& operator=(basic_regex&&) = default;
2349cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI basic_regex& operator=(const value_type* __p) { return assign(__p); }
23500b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
2351cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI basic_regex& operator=(initializer_list<value_type> __il) { return assign(__il); }
23520b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG
23530b57cec5SDimitry Andric  template <class _ST, class _SA>
2354cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI basic_regex& operator=(const basic_string<value_type, _ST, _SA>& __p) {
2355cb14a3feSDimitry Andric    return assign(__p);
2356cb14a3feSDimitry Andric  }
23570b57cec5SDimitry Andric
23580b57cec5SDimitry Andric  // assign:
2359cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI basic_regex& assign(const basic_regex& __that) { return *this = __that; }
23600b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
2361cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI basic_regex& assign(basic_regex&& __that) _NOEXCEPT { return *this = std::move(__that); }
23620b57cec5SDimitry Andric#endif
2363cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI basic_regex& assign(const value_type* __p, flag_type __f = regex_constants::ECMAScript) {
2364cb14a3feSDimitry Andric    return assign(__p, __p + __traits_.length(__p), __f);
2365cb14a3feSDimitry Andric  }
2366cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI basic_regex&
2367cb14a3feSDimitry Andric  assign(const value_type* __p, size_t __len, flag_type __f = regex_constants::ECMAScript) {
2368cb14a3feSDimitry Andric    return assign(__p, __p + __len, __f);
2369cb14a3feSDimitry Andric  }
23700b57cec5SDimitry Andric  template <class _ST, class _SA>
2371cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI basic_regex&
2372cb14a3feSDimitry Andric  assign(const basic_string<value_type, _ST, _SA>& __s, flag_type __f = regex_constants::ECMAScript) {
2373cb14a3feSDimitry Andric    return assign(__s.begin(), __s.end(), __f);
2374cb14a3feSDimitry Andric  }
23750b57cec5SDimitry Andric
23765f757f3fSDimitry Andric  template <class _InputIterator, __enable_if_t<__has_exactly_input_iterator_category<_InputIterator>::value, int> = 0>
2377cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI basic_regex&
2378cb14a3feSDimitry Andric  assign(_InputIterator __first, _InputIterator __last, flag_type __f = regex_constants::ECMAScript) {
23790b57cec5SDimitry Andric    basic_string<_CharT> __t(__first, __last);
23800b57cec5SDimitry Andric    return assign(__t.begin(), __t.end(), __f);
23810b57cec5SDimitry Andric  }
23820b57cec5SDimitry Andric
23830b57cec5SDimitry Andricprivate:
2384cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void __member_init(flag_type __f) {
23850b57cec5SDimitry Andric    __flags_        = __f;
23860b57cec5SDimitry Andric    __marked_count_ = 0;
23870b57cec5SDimitry Andric    __loop_count_   = 0;
23880b57cec5SDimitry Andric    __open_count_   = 0;
23890b57cec5SDimitry Andric    __end_          = nullptr;
23900b57cec5SDimitry Andric  }
23910b57cec5SDimitry Andric
2392cb14a3feSDimitry Andricpublic:
23935f757f3fSDimitry Andric  template <class _ForwardIterator, __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value, int> = 0>
2394cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI basic_regex&
2395cb14a3feSDimitry Andric  assign(_ForwardIterator __first, _ForwardIterator __last, flag_type __f = regex_constants::ECMAScript) {
23960b57cec5SDimitry Andric    return assign(basic_regex(__first, __last, __f));
23970b57cec5SDimitry Andric  }
23980b57cec5SDimitry Andric
23990b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
24000b57cec5SDimitry Andric
2401cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI basic_regex&
2402cb14a3feSDimitry Andric  assign(initializer_list<value_type> __il, flag_type __f = regex_constants::ECMAScript) {
2403cb14a3feSDimitry Andric    return assign(__il.begin(), __il.end(), __f);
2404cb14a3feSDimitry Andric  }
24050b57cec5SDimitry Andric
24060b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG
24070b57cec5SDimitry Andric
24080b57cec5SDimitry Andric  // const operations:
2409cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI unsigned mark_count() const { return __marked_count_; }
2410cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI flag_type flags() const { return __flags_; }
24110b57cec5SDimitry Andric
24120b57cec5SDimitry Andric  // locale:
2413cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI locale_type imbue(locale_type __loc) {
24140b57cec5SDimitry Andric    __member_init(ECMAScript);
24150b57cec5SDimitry Andric    __start_.reset();
24160b57cec5SDimitry Andric    return __traits_.imbue(__loc);
24170b57cec5SDimitry Andric  }
2418cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI locale_type getloc() const { return __traits_.getloc(); }
24190b57cec5SDimitry Andric
24200b57cec5SDimitry Andric  // swap:
24210b57cec5SDimitry Andric  void swap(basic_regex& __r);
24220b57cec5SDimitry Andric
24230b57cec5SDimitry Andricprivate:
2424cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI unsigned __loop_count() const { return __loop_count_; }
24250b57cec5SDimitry Andric
2426cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI bool __use_multiline() const {
2427e8d8bef9SDimitry Andric    return __get_grammar(__flags_) == ECMAScript && (__flags_ & multiline);
2428e8d8bef9SDimitry Andric  }
2429e8d8bef9SDimitry Andric
24300b57cec5SDimitry Andric  template <class _ForwardIterator>
2431cb14a3feSDimitry Andric  void __init(_ForwardIterator __first, _ForwardIterator __last);
2432480093f4SDimitry Andric  template <class _ForwardIterator>
2433cb14a3feSDimitry Andric  _ForwardIterator __parse(_ForwardIterator __first, _ForwardIterator __last);
24340b57cec5SDimitry Andric  template <class _ForwardIterator>
2435cb14a3feSDimitry Andric  _ForwardIterator __parse_basic_reg_exp(_ForwardIterator __first, _ForwardIterator __last);
24360b57cec5SDimitry Andric  template <class _ForwardIterator>
2437cb14a3feSDimitry Andric  _ForwardIterator __parse_RE_expression(_ForwardIterator __first, _ForwardIterator __last);
24380b57cec5SDimitry Andric  template <class _ForwardIterator>
2439cb14a3feSDimitry Andric  _ForwardIterator __parse_simple_RE(_ForwardIterator __first, _ForwardIterator __last);
24400b57cec5SDimitry Andric  template <class _ForwardIterator>
2441cb14a3feSDimitry Andric  _ForwardIterator __parse_nondupl_RE(_ForwardIterator __first, _ForwardIterator __last);
24420b57cec5SDimitry Andric  template <class _ForwardIterator>
2443cb14a3feSDimitry Andric  _ForwardIterator __parse_one_char_or_coll_elem_RE(_ForwardIterator __first, _ForwardIterator __last);
24440b57cec5SDimitry Andric  template <class _ForwardIterator>
2445cb14a3feSDimitry Andric  _ForwardIterator __parse_Back_open_paren(_ForwardIterator __first, _ForwardIterator __last);
24460b57cec5SDimitry Andric  template <class _ForwardIterator>
2447cb14a3feSDimitry Andric  _ForwardIterator __parse_Back_close_paren(_ForwardIterator __first, _ForwardIterator __last);
24480b57cec5SDimitry Andric  template <class _ForwardIterator>
2449cb14a3feSDimitry Andric  _ForwardIterator __parse_Back_open_brace(_ForwardIterator __first, _ForwardIterator __last);
24500b57cec5SDimitry Andric  template <class _ForwardIterator>
2451cb14a3feSDimitry Andric  _ForwardIterator __parse_Back_close_brace(_ForwardIterator __first, _ForwardIterator __last);
24520b57cec5SDimitry Andric  template <class _ForwardIterator>
2453cb14a3feSDimitry Andric  _ForwardIterator __parse_BACKREF(_ForwardIterator __first, _ForwardIterator __last);
24540b57cec5SDimitry Andric  template <class _ForwardIterator>
2455cb14a3feSDimitry Andric  _ForwardIterator __parse_ORD_CHAR(_ForwardIterator __first, _ForwardIterator __last);
24560b57cec5SDimitry Andric  template <class _ForwardIterator>
2457cb14a3feSDimitry Andric  _ForwardIterator __parse_QUOTED_CHAR(_ForwardIterator __first, _ForwardIterator __last);
24580b57cec5SDimitry Andric  template <class _ForwardIterator>
2459cb14a3feSDimitry Andric  _ForwardIterator __parse_RE_dupl_symbol(
2460cb14a3feSDimitry Andric      _ForwardIterator __first,
2461cb14a3feSDimitry Andric      _ForwardIterator __last,
24620b57cec5SDimitry Andric      __owns_one_state<_CharT>* __s,
2463cb14a3feSDimitry Andric      unsigned __mexp_begin,
2464cb14a3feSDimitry Andric      unsigned __mexp_end);
24650b57cec5SDimitry Andric  template <class _ForwardIterator>
2466cb14a3feSDimitry Andric  _ForwardIterator __parse_ERE_dupl_symbol(
2467cb14a3feSDimitry Andric      _ForwardIterator __first,
2468cb14a3feSDimitry Andric      _ForwardIterator __last,
24690b57cec5SDimitry Andric      __owns_one_state<_CharT>* __s,
2470cb14a3feSDimitry Andric      unsigned __mexp_begin,
2471cb14a3feSDimitry Andric      unsigned __mexp_end);
2472cb14a3feSDimitry Andric  template <class _ForwardIterator>
2473cb14a3feSDimitry Andric  _ForwardIterator __parse_bracket_expression(_ForwardIterator __first, _ForwardIterator __last);
24740b57cec5SDimitry Andric  template <class _ForwardIterator>
24750b57cec5SDimitry Andric  _ForwardIterator
2476cb14a3feSDimitry Andric  __parse_follow_list(_ForwardIterator __first, _ForwardIterator __last, __bracket_expression<_CharT, _Traits>* __ml);
2477cb14a3feSDimitry Andric  template <class _ForwardIterator>
2478cb14a3feSDimitry Andric  _ForwardIterator __parse_expression_term(
2479cb14a3feSDimitry Andric      _ForwardIterator __first, _ForwardIterator __last, __bracket_expression<_CharT, _Traits>* __ml);
2480cb14a3feSDimitry Andric  template <class _ForwardIterator>
2481cb14a3feSDimitry Andric  _ForwardIterator __parse_equivalence_class(
2482cb14a3feSDimitry Andric      _ForwardIterator __first, _ForwardIterator __last, __bracket_expression<_CharT, _Traits>* __ml);
2483cb14a3feSDimitry Andric  template <class _ForwardIterator>
2484cb14a3feSDimitry Andric  _ForwardIterator __parse_character_class(
2485cb14a3feSDimitry Andric      _ForwardIterator __first, _ForwardIterator __last, __bracket_expression<_CharT, _Traits>* __ml);
24860b57cec5SDimitry Andric  template <class _ForwardIterator>
24870b57cec5SDimitry Andric  _ForwardIterator
2488cb14a3feSDimitry Andric  __parse_collating_symbol(_ForwardIterator __first, _ForwardIterator __last, basic_string<_CharT>& __col_sym);
2489cb14a3feSDimitry Andric  template <class _ForwardIterator>
2490cb14a3feSDimitry Andric  _ForwardIterator __parse_DUP_COUNT(_ForwardIterator __first, _ForwardIterator __last, int& __c);
2491cb14a3feSDimitry Andric  template <class _ForwardIterator>
2492cb14a3feSDimitry Andric  _ForwardIterator __parse_extended_reg_exp(_ForwardIterator __first, _ForwardIterator __last);
2493cb14a3feSDimitry Andric  template <class _ForwardIterator>
2494cb14a3feSDimitry Andric  _ForwardIterator __parse_ERE_branch(_ForwardIterator __first, _ForwardIterator __last);
2495cb14a3feSDimitry Andric  template <class _ForwardIterator>
2496cb14a3feSDimitry Andric  _ForwardIterator __parse_ERE_expression(_ForwardIterator __first, _ForwardIterator __last);
2497cb14a3feSDimitry Andric  template <class _ForwardIterator>
2498cb14a3feSDimitry Andric  _ForwardIterator __parse_one_char_or_coll_elem_ERE(_ForwardIterator __first, _ForwardIterator __last);
2499cb14a3feSDimitry Andric  template <class _ForwardIterator>
2500cb14a3feSDimitry Andric  _ForwardIterator __parse_ORD_CHAR_ERE(_ForwardIterator __first, _ForwardIterator __last);
2501cb14a3feSDimitry Andric  template <class _ForwardIterator>
2502cb14a3feSDimitry Andric  _ForwardIterator __parse_QUOTED_CHAR_ERE(_ForwardIterator __first, _ForwardIterator __last);
2503cb14a3feSDimitry Andric  template <class _ForwardIterator>
2504cb14a3feSDimitry Andric  _ForwardIterator __parse_ecma_exp(_ForwardIterator __first, _ForwardIterator __last);
2505cb14a3feSDimitry Andric  template <class _ForwardIterator>
2506cb14a3feSDimitry Andric  _ForwardIterator __parse_alternative(_ForwardIterator __first, _ForwardIterator __last);
2507cb14a3feSDimitry Andric  template <class _ForwardIterator>
2508cb14a3feSDimitry Andric  _ForwardIterator __parse_term(_ForwardIterator __first, _ForwardIterator __last);
2509cb14a3feSDimitry Andric  template <class _ForwardIterator>
2510cb14a3feSDimitry Andric  _ForwardIterator __parse_assertion(_ForwardIterator __first, _ForwardIterator __last);
2511cb14a3feSDimitry Andric  template <class _ForwardIterator>
2512cb14a3feSDimitry Andric  _ForwardIterator __parse_atom(_ForwardIterator __first, _ForwardIterator __last);
2513cb14a3feSDimitry Andric  template <class _ForwardIterator>
2514cb14a3feSDimitry Andric  _ForwardIterator __parse_atom_escape(_ForwardIterator __first, _ForwardIterator __last);
2515cb14a3feSDimitry Andric  template <class _ForwardIterator>
2516cb14a3feSDimitry Andric  _ForwardIterator __parse_decimal_escape(_ForwardIterator __first, _ForwardIterator __last);
2517cb14a3feSDimitry Andric  template <class _ForwardIterator>
2518cb14a3feSDimitry Andric  _ForwardIterator __parse_character_class_escape(_ForwardIterator __first, _ForwardIterator __last);
25190b57cec5SDimitry Andric  template <class _ForwardIterator>
25200b57cec5SDimitry Andric  _ForwardIterator
2521cb14a3feSDimitry Andric  __parse_character_escape(_ForwardIterator __first, _ForwardIterator __last, basic_string<_CharT>* __str = nullptr);
25220b57cec5SDimitry Andric  template <class _ForwardIterator>
2523cb14a3feSDimitry Andric  _ForwardIterator __parse_pattern_character(_ForwardIterator __first, _ForwardIterator __last);
25240b57cec5SDimitry Andric  template <class _ForwardIterator>
2525cb14a3feSDimitry Andric  _ForwardIterator __parse_grep(_ForwardIterator __first, _ForwardIterator __last);
25260b57cec5SDimitry Andric  template <class _ForwardIterator>
2527cb14a3feSDimitry Andric  _ForwardIterator __parse_egrep(_ForwardIterator __first, _ForwardIterator __last);
25280b57cec5SDimitry Andric  template <class _ForwardIterator>
2529cb14a3feSDimitry Andric  _ForwardIterator __parse_class_escape(
2530cb14a3feSDimitry Andric      _ForwardIterator __first,
2531cb14a3feSDimitry Andric      _ForwardIterator __last,
25320b57cec5SDimitry Andric      basic_string<_CharT>& __str,
25330b57cec5SDimitry Andric      __bracket_expression<_CharT, _Traits>* __ml);
25340b57cec5SDimitry Andric  template <class _ForwardIterator>
25350b57cec5SDimitry Andric  _ForwardIterator
2536cb14a3feSDimitry Andric  __parse_awk_escape(_ForwardIterator __first, _ForwardIterator __last, basic_string<_CharT>* __str = nullptr);
25370b57cec5SDimitry Andric
2538753f127fSDimitry Andric  bool __test_back_ref(_CharT);
25395ffd83dbSDimitry Andric
2540cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void __push_l_anchor();
25410b57cec5SDimitry Andric  void __push_r_anchor();
25420b57cec5SDimitry Andric  void __push_match_any();
25430b57cec5SDimitry Andric  void __push_match_any_but_newline();
2544cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void __push_greedy_inf_repeat(
2545cb14a3feSDimitry Andric      size_t __min, __owns_one_state<_CharT>* __s, unsigned __mexp_begin = 0, unsigned __mexp_end = 0) {
2546cb14a3feSDimitry Andric    __push_loop(__min, numeric_limits<size_t>::max(), __s, __mexp_begin, __mexp_end);
2547cb14a3feSDimitry Andric  }
2548cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void __push_nongreedy_inf_repeat(
2549cb14a3feSDimitry Andric      size_t __min, __owns_one_state<_CharT>* __s, unsigned __mexp_begin = 0, unsigned __mexp_end = 0) {
2550cb14a3feSDimitry Andric    __push_loop(__min, numeric_limits<size_t>::max(), __s, __mexp_begin, __mexp_end, false);
2551cb14a3feSDimitry Andric  }
2552cb14a3feSDimitry Andric  void __push_loop(size_t __min,
2553cb14a3feSDimitry Andric                   size_t __max,
2554cb14a3feSDimitry Andric                   __owns_one_state<_CharT>* __s,
2555cb14a3feSDimitry Andric                   size_t __mexp_begin = 0,
2556cb14a3feSDimitry Andric                   size_t __mexp_end   = 0,
25570b57cec5SDimitry Andric                   bool __greedy       = true);
25580b57cec5SDimitry Andric  __bracket_expression<_CharT, _Traits>* __start_matching_list(bool __negate);
25590b57cec5SDimitry Andric  void __push_char(value_type __c);
25600b57cec5SDimitry Andric  void __push_back_ref(int __i);
2561cb14a3feSDimitry Andric  void __push_alternation(__owns_one_state<_CharT>* __sa, __owns_one_state<_CharT>* __sb);
25620b57cec5SDimitry Andric  void __push_begin_marked_subexpression();
25630b57cec5SDimitry Andric  void __push_end_marked_subexpression(unsigned);
25640b57cec5SDimitry Andric  void __push_empty();
25650b57cec5SDimitry Andric  void __push_word_boundary(bool);
25660b57cec5SDimitry Andric  void __push_lookahead(const basic_regex&, bool, unsigned);
25670b57cec5SDimitry Andric
25680b57cec5SDimitry Andric  template <class _Allocator>
2569cb14a3feSDimitry Andric  bool __search(const _CharT* __first,
2570cb14a3feSDimitry Andric                const _CharT* __last,
25710b57cec5SDimitry Andric                match_results<const _CharT*, _Allocator>& __m,
25720b57cec5SDimitry Andric                regex_constants::match_flag_type __flags) const;
25730b57cec5SDimitry Andric
25740b57cec5SDimitry Andric  template <class _Allocator>
2575cb14a3feSDimitry Andric  bool __match_at_start(const _CharT* __first,
2576cb14a3feSDimitry Andric                        const _CharT* __last,
25770b57cec5SDimitry Andric                        match_results<const _CharT*, _Allocator>& __m,
2578cb14a3feSDimitry Andric                        regex_constants::match_flag_type __flags,
2579cb14a3feSDimitry Andric                        bool) const;
25800b57cec5SDimitry Andric  template <class _Allocator>
2581cb14a3feSDimitry Andric  bool __match_at_start_ecma(
2582cb14a3feSDimitry Andric      const _CharT* __first,
2583cb14a3feSDimitry Andric      const _CharT* __last,
25840b57cec5SDimitry Andric      match_results<const _CharT*, _Allocator>& __m,
2585cb14a3feSDimitry Andric      regex_constants::match_flag_type __flags,
2586cb14a3feSDimitry Andric      bool) const;
25870b57cec5SDimitry Andric  template <class _Allocator>
2588cb14a3feSDimitry Andric  bool __match_at_start_posix_nosubs(
2589cb14a3feSDimitry Andric      const _CharT* __first,
2590cb14a3feSDimitry Andric      const _CharT* __last,
25910b57cec5SDimitry Andric      match_results<const _CharT*, _Allocator>& __m,
2592cb14a3feSDimitry Andric      regex_constants::match_flag_type __flags,
2593cb14a3feSDimitry Andric      bool) const;
25940b57cec5SDimitry Andric  template <class _Allocator>
2595cb14a3feSDimitry Andric  bool __match_at_start_posix_subs(
2596cb14a3feSDimitry Andric      const _CharT* __first,
2597cb14a3feSDimitry Andric      const _CharT* __last,
25980b57cec5SDimitry Andric      match_results<const _CharT*, _Allocator>& __m,
2599cb14a3feSDimitry Andric      regex_constants::match_flag_type __flags,
2600cb14a3feSDimitry Andric      bool) const;
26010b57cec5SDimitry Andric
26020b57cec5SDimitry Andric  template <class _Bp, class _Ap, class _Cp, class _Tp>
2603cb14a3feSDimitry Andric  friend bool
2604cb14a3feSDimitry Andric  regex_search(_Bp, _Bp, match_results<_Bp, _Ap>&, const basic_regex<_Cp, _Tp>&, regex_constants::match_flag_type);
26050b57cec5SDimitry Andric
26060b57cec5SDimitry Andric  template <class _Ap, class _Cp, class _Tp>
2607cb14a3feSDimitry Andric  friend bool
2608cb14a3feSDimitry Andric  regex_search(const _Cp*,
2609cb14a3feSDimitry Andric               const _Cp*,
2610cb14a3feSDimitry Andric               match_results<const _Cp*, _Ap>&,
2611cb14a3feSDimitry Andric               const basic_regex<_Cp, _Tp>&,
2612cb14a3feSDimitry Andric               regex_constants::match_flag_type);
26130b57cec5SDimitry Andric
26140b57cec5SDimitry Andric  template <class _Bp, class _Cp, class _Tp>
2615cb14a3feSDimitry Andric  friend bool regex_search(_Bp, _Bp, const basic_regex<_Cp, _Tp>&, regex_constants::match_flag_type);
26160b57cec5SDimitry Andric
26170b57cec5SDimitry Andric  template <class _Cp, class _Tp>
2618cb14a3feSDimitry Andric  friend bool regex_search(const _Cp*, const _Cp*, const basic_regex<_Cp, _Tp>&, regex_constants::match_flag_type);
26190b57cec5SDimitry Andric
26200b57cec5SDimitry Andric  template <class _Cp, class _Ap, class _Tp>
2621cb14a3feSDimitry Andric  friend bool regex_search(
2622cb14a3feSDimitry Andric      const _Cp*, match_results<const _Cp*, _Ap>&, const basic_regex<_Cp, _Tp>&, regex_constants::match_flag_type);
26230b57cec5SDimitry Andric
26240b57cec5SDimitry Andric  template <class _ST, class _SA, class _Cp, class _Tp>
2625cb14a3feSDimitry Andric  friend bool regex_search(const basic_string<_Cp, _ST, _SA>& __s,
26260b57cec5SDimitry Andric                           const basic_regex<_Cp, _Tp>& __e,
26270b57cec5SDimitry Andric                           regex_constants::match_flag_type __flags);
26280b57cec5SDimitry Andric
26290b57cec5SDimitry Andric  template <class _ST, class _SA, class _Ap, class _Cp, class _Tp>
2630cb14a3feSDimitry Andric  friend bool regex_search(const basic_string<_Cp, _ST, _SA>& __s,
26310b57cec5SDimitry Andric                           match_results<typename basic_string<_Cp, _ST, _SA>::const_iterator, _Ap>&,
26320b57cec5SDimitry Andric                           const basic_regex<_Cp, _Tp>& __e,
26330b57cec5SDimitry Andric                           regex_constants::match_flag_type __flags);
26340b57cec5SDimitry Andric
26350b57cec5SDimitry Andric  template <class _Iter, class _Ap, class _Cp, class _Tp>
2636cb14a3feSDimitry Andric  friend bool
26370b57cec5SDimitry Andric  regex_search(__wrap_iter<_Iter> __first,
26380b57cec5SDimitry Andric               __wrap_iter<_Iter> __last,
26390b57cec5SDimitry Andric               match_results<__wrap_iter<_Iter>, _Ap>& __m,
26400b57cec5SDimitry Andric               const basic_regex<_Cp, _Tp>& __e,
26410b57cec5SDimitry Andric               regex_constants::match_flag_type __flags);
26420b57cec5SDimitry Andric
2643cb14a3feSDimitry Andric  template <class, class>
2644cb14a3feSDimitry Andric  friend class __lookahead;
26450b57cec5SDimitry Andric};
26460b57cec5SDimitry Andric
2647349cc55cSDimitry Andric#if _LIBCPP_STD_VER >= 17
2648cb14a3feSDimitry Andrictemplate <class _ForwardIterator, __enable_if_t<__has_forward_iterator_category<_ForwardIterator>::value, int> = 0>
2649cb14a3feSDimitry Andricbasic_regex(_ForwardIterator, _ForwardIterator, regex_constants::syntax_option_type = regex_constants::ECMAScript)
26500b57cec5SDimitry Andric    -> basic_regex<typename iterator_traits<_ForwardIterator>::value_type>;
26510b57cec5SDimitry Andric#endif
26520b57cec5SDimitry Andric
26530b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
26540b57cec5SDimitry Andricconst regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::icase;
26550b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
26560b57cec5SDimitry Andricconst regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::nosubs;
26570b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
26580b57cec5SDimitry Andricconst regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::optimize;
26590b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
26600b57cec5SDimitry Andricconst regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::collate;
26610b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
26620b57cec5SDimitry Andricconst regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::ECMAScript;
26630b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
26640b57cec5SDimitry Andricconst regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::basic;
26650b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
26660b57cec5SDimitry Andricconst regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::extended;
26670b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
26680b57cec5SDimitry Andricconst regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::awk;
26690b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
26700b57cec5SDimitry Andricconst regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::grep;
26710b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
26720b57cec5SDimitry Andricconst regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::egrep;
26730b57cec5SDimitry Andric
26740b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
2675cb14a3feSDimitry Andricvoid basic_regex<_CharT, _Traits>::swap(basic_regex& __r) {
26765f757f3fSDimitry Andric  using std::swap;
26770b57cec5SDimitry Andric  swap(__traits_, __r.__traits_);
26780b57cec5SDimitry Andric  swap(__flags_, __r.__flags_);
26790b57cec5SDimitry Andric  swap(__marked_count_, __r.__marked_count_);
26800b57cec5SDimitry Andric  swap(__loop_count_, __r.__loop_count_);
26810b57cec5SDimitry Andric  swap(__open_count_, __r.__open_count_);
26820b57cec5SDimitry Andric  swap(__start_, __r.__start_);
26830b57cec5SDimitry Andric  swap(__end_, __r.__end_);
26840b57cec5SDimitry Andric}
26850b57cec5SDimitry Andric
26860b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
2687cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI void swap(basic_regex<_CharT, _Traits>& __x, basic_regex<_CharT, _Traits>& __y) {
26880b57cec5SDimitry Andric  return __x.swap(__y);
26890b57cec5SDimitry Andric}
26900b57cec5SDimitry Andric
26910b57cec5SDimitry Andric// __lookahead
26920b57cec5SDimitry Andric
26930b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
2694cb14a3feSDimitry Andricclass __lookahead : public __owns_one_state<_CharT> {
26950b57cec5SDimitry Andric  typedef __owns_one_state<_CharT> base;
26960b57cec5SDimitry Andric
26970b57cec5SDimitry Andric  basic_regex<_CharT, _Traits> __exp_;
26980b57cec5SDimitry Andric  unsigned __mexp_;
26990b57cec5SDimitry Andric  bool __invert_;
27000b57cec5SDimitry Andric
27010b57cec5SDimitry Andricpublic:
27025f757f3fSDimitry Andric  typedef std::__state<_CharT> __state;
27030b57cec5SDimitry Andric
27045f757f3fSDimitry Andric  _LIBCPP_HIDE_FROM_ABI
27050b57cec5SDimitry Andric  __lookahead(const basic_regex<_CharT, _Traits>& __exp, bool __invert, __node<_CharT>* __s, unsigned __mexp)
27060b57cec5SDimitry Andric      : base(__s), __exp_(__exp), __mexp_(__mexp), __invert_(__invert) {}
27070b57cec5SDimitry Andric
2708*0fca6ea1SDimitry Andric  __lookahead(const __lookahead&)            = delete;
2709*0fca6ea1SDimitry Andric  __lookahead& operator=(const __lookahead&) = delete;
2710*0fca6ea1SDimitry Andric
271106c3fb27SDimitry Andric  _LIBCPP_HIDE_FROM_ABI_VIRTUAL virtual void __exec(__state&) const;
27120b57cec5SDimitry Andric};
27130b57cec5SDimitry Andric
27140b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
2715cb14a3feSDimitry Andricvoid __lookahead<_CharT, _Traits>::__exec(__state& __s) const {
27160b57cec5SDimitry Andric  match_results<const _CharT*> __m;
27170b57cec5SDimitry Andric  __m.__init(1 + __exp_.mark_count(), __s.__current_, __s.__last_);
27180b57cec5SDimitry Andric  bool __matched = __exp_.__match_at_start_ecma(
2719cb14a3feSDimitry Andric      __s.__current_,
2720cb14a3feSDimitry Andric      __s.__last_,
27210b57cec5SDimitry Andric      __m,
2722cb14a3feSDimitry Andric      (__s.__flags_ | regex_constants::match_continuous) & ~regex_constants::__full_match,
27230b57cec5SDimitry Andric      __s.__at_first_ && __s.__current_ == __s.__first_);
2724cb14a3feSDimitry Andric  if (__matched != __invert_) {
27250b57cec5SDimitry Andric    __s.__do_   = __state::__accept_but_not_consume;
27260b57cec5SDimitry Andric    __s.__node_ = this->first();
27270b57cec5SDimitry Andric    for (unsigned __i = 1; __i < __m.size(); ++__i) {
27280b57cec5SDimitry Andric      __s.__sub_matches_[__mexp_ + __i - 1] = __m.__matches_[__i];
27290b57cec5SDimitry Andric    }
2730cb14a3feSDimitry Andric  } else {
27310b57cec5SDimitry Andric    __s.__do_   = __state::__reject;
27320b57cec5SDimitry Andric    __s.__node_ = nullptr;
27330b57cec5SDimitry Andric  }
27340b57cec5SDimitry Andric}
27350b57cec5SDimitry Andric
27360b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
27370b57cec5SDimitry Andrictemplate <class _ForwardIterator>
2738cb14a3feSDimitry Andricvoid basic_regex<_CharT, _Traits>::__init(_ForwardIterator __first, _ForwardIterator __last) {
2739cb14a3feSDimitry Andric  if (__get_grammar(__flags_) == 0)
2740cb14a3feSDimitry Andric    __flags_ |= regex_constants::ECMAScript;
2741480093f4SDimitry Andric  _ForwardIterator __temp = __parse(__first, __last);
2742480093f4SDimitry Andric  if (__temp != __last)
2743480093f4SDimitry Andric    __throw_regex_error<regex_constants::__re_err_parse>();
2744480093f4SDimitry Andric}
2745480093f4SDimitry Andric
2746480093f4SDimitry Andrictemplate <class _CharT, class _Traits>
2747480093f4SDimitry Andrictemplate <class _ForwardIterator>
2748cb14a3feSDimitry Andric_ForwardIterator basic_regex<_CharT, _Traits>::__parse(_ForwardIterator __first, _ForwardIterator __last) {
27490b57cec5SDimitry Andric  {
27500b57cec5SDimitry Andric    unique_ptr<__node> __h(new __end_state<_CharT>);
27510b57cec5SDimitry Andric    __start_.reset(new __empty_state<_CharT>(__h.get()));
27520b57cec5SDimitry Andric    __h.release();
27530b57cec5SDimitry Andric    __end_ = __start_.get();
27540b57cec5SDimitry Andric  }
2755cb14a3feSDimitry Andric  switch (__get_grammar(__flags_)) {
27560b57cec5SDimitry Andric  case ECMAScript:
27570b57cec5SDimitry Andric    __first = __parse_ecma_exp(__first, __last);
27580b57cec5SDimitry Andric    break;
27590b57cec5SDimitry Andric  case basic:
27600b57cec5SDimitry Andric    __first = __parse_basic_reg_exp(__first, __last);
27610b57cec5SDimitry Andric    break;
27620b57cec5SDimitry Andric  case extended:
27630b57cec5SDimitry Andric  case awk:
27640b57cec5SDimitry Andric    __first = __parse_extended_reg_exp(__first, __last);
27650b57cec5SDimitry Andric    break;
27660b57cec5SDimitry Andric  case grep:
27670b57cec5SDimitry Andric    __first = __parse_grep(__first, __last);
27680b57cec5SDimitry Andric    break;
27690b57cec5SDimitry Andric  case egrep:
27700b57cec5SDimitry Andric    __first = __parse_egrep(__first, __last);
27710b57cec5SDimitry Andric    break;
27720b57cec5SDimitry Andric  default:
27730b57cec5SDimitry Andric    __throw_regex_error<regex_constants::__re_err_grammar>();
27740b57cec5SDimitry Andric  }
27750b57cec5SDimitry Andric  return __first;
27760b57cec5SDimitry Andric}
27770b57cec5SDimitry Andric
27780b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
27790b57cec5SDimitry Andrictemplate <class _ForwardIterator>
27800b57cec5SDimitry Andric_ForwardIterator
2781cb14a3feSDimitry Andricbasic_regex<_CharT, _Traits>::__parse_basic_reg_exp(_ForwardIterator __first, _ForwardIterator __last) {
2782cb14a3feSDimitry Andric  if (__first != __last) {
2783cb14a3feSDimitry Andric    if (*__first == '^') {
27840b57cec5SDimitry Andric      __push_l_anchor();
27850b57cec5SDimitry Andric      ++__first;
27860b57cec5SDimitry Andric    }
2787cb14a3feSDimitry Andric    if (__first != __last) {
27880b57cec5SDimitry Andric      __first = __parse_RE_expression(__first, __last);
2789cb14a3feSDimitry Andric      if (__first != __last) {
27905f757f3fSDimitry Andric        _ForwardIterator __temp = std::next(__first);
2791cb14a3feSDimitry Andric        if (__temp == __last && *__first == '$') {
27920b57cec5SDimitry Andric          __push_r_anchor();
27930b57cec5SDimitry Andric          ++__first;
27940b57cec5SDimitry Andric        }
27950b57cec5SDimitry Andric      }
27960b57cec5SDimitry Andric    }
27970b57cec5SDimitry Andric    if (__first != __last)
27980b57cec5SDimitry Andric      __throw_regex_error<regex_constants::__re_err_empty>();
27990b57cec5SDimitry Andric  }
28000b57cec5SDimitry Andric  return __first;
28010b57cec5SDimitry Andric}
28020b57cec5SDimitry Andric
28030b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
28040b57cec5SDimitry Andrictemplate <class _ForwardIterator>
28050b57cec5SDimitry Andric_ForwardIterator
2806cb14a3feSDimitry Andricbasic_regex<_CharT, _Traits>::__parse_extended_reg_exp(_ForwardIterator __first, _ForwardIterator __last) {
28070b57cec5SDimitry Andric  __owns_one_state<_CharT>* __sa = __end_;
28080b57cec5SDimitry Andric  _ForwardIterator __temp        = __parse_ERE_branch(__first, __last);
28090b57cec5SDimitry Andric  if (__temp == __first)
28100b57cec5SDimitry Andric    __throw_regex_error<regex_constants::__re_err_empty>();
28110b57cec5SDimitry Andric  __first = __temp;
2812cb14a3feSDimitry Andric  while (__first != __last && *__first == '|') {
28130b57cec5SDimitry Andric    __owns_one_state<_CharT>* __sb = __end_;
28140b57cec5SDimitry Andric    __temp                         = __parse_ERE_branch(++__first, __last);
28150b57cec5SDimitry Andric    if (__temp == __first)
28160b57cec5SDimitry Andric      __throw_regex_error<regex_constants::__re_err_empty>();
28170b57cec5SDimitry Andric    __push_alternation(__sa, __sb);
28180b57cec5SDimitry Andric    __first = __temp;
28190b57cec5SDimitry Andric  }
28200b57cec5SDimitry Andric  return __first;
28210b57cec5SDimitry Andric}
28220b57cec5SDimitry Andric
28230b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
28240b57cec5SDimitry Andrictemplate <class _ForwardIterator>
2825cb14a3feSDimitry Andric_ForwardIterator basic_regex<_CharT, _Traits>::__parse_ERE_branch(_ForwardIterator __first, _ForwardIterator __last) {
28260b57cec5SDimitry Andric  _ForwardIterator __temp = __parse_ERE_expression(__first, __last);
28270b57cec5SDimitry Andric  if (__temp == __first)
28280b57cec5SDimitry Andric    __throw_regex_error<regex_constants::__re_err_empty>();
2829cb14a3feSDimitry Andric  do {
28300b57cec5SDimitry Andric    __first = __temp;
28310b57cec5SDimitry Andric    __temp  = __parse_ERE_expression(__first, __last);
28320b57cec5SDimitry Andric  } while (__temp != __first);
28330b57cec5SDimitry Andric  return __first;
28340b57cec5SDimitry Andric}
28350b57cec5SDimitry Andric
28360b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
28370b57cec5SDimitry Andrictemplate <class _ForwardIterator>
28380b57cec5SDimitry Andric_ForwardIterator
2839cb14a3feSDimitry Andricbasic_regex<_CharT, _Traits>::__parse_ERE_expression(_ForwardIterator __first, _ForwardIterator __last) {
28400b57cec5SDimitry Andric  __owns_one_state<_CharT>* __e = __end_;
28410b57cec5SDimitry Andric  unsigned __mexp_begin         = __marked_count_;
28420b57cec5SDimitry Andric  _ForwardIterator __temp       = __parse_one_char_or_coll_elem_ERE(__first, __last);
2843cb14a3feSDimitry Andric  if (__temp == __first && __temp != __last) {
2844cb14a3feSDimitry Andric    switch (*__temp) {
28450b57cec5SDimitry Andric    case '^':
28460b57cec5SDimitry Andric      __push_l_anchor();
28470b57cec5SDimitry Andric      ++__temp;
28480b57cec5SDimitry Andric      break;
28490b57cec5SDimitry Andric    case '$':
28500b57cec5SDimitry Andric      __push_r_anchor();
28510b57cec5SDimitry Andric      ++__temp;
28520b57cec5SDimitry Andric      break;
28530b57cec5SDimitry Andric    case '(':
28540b57cec5SDimitry Andric      __push_begin_marked_subexpression();
28550b57cec5SDimitry Andric      unsigned __temp_count = __marked_count_;
28560b57cec5SDimitry Andric      ++__open_count_;
28570b57cec5SDimitry Andric      __temp = __parse_extended_reg_exp(++__temp, __last);
28580b57cec5SDimitry Andric      if (__temp == __last || *__temp != ')')
28590b57cec5SDimitry Andric        __throw_regex_error<regex_constants::error_paren>();
28600b57cec5SDimitry Andric      __push_end_marked_subexpression(__temp_count);
28610b57cec5SDimitry Andric      --__open_count_;
28620b57cec5SDimitry Andric      ++__temp;
28630b57cec5SDimitry Andric      break;
28640b57cec5SDimitry Andric    }
28650b57cec5SDimitry Andric  }
28660b57cec5SDimitry Andric  if (__temp != __first)
2867cb14a3feSDimitry Andric    __temp = __parse_ERE_dupl_symbol(__temp, __last, __e, __mexp_begin + 1, __marked_count_ + 1);
28680b57cec5SDimitry Andric  __first = __temp;
28690b57cec5SDimitry Andric  return __first;
28700b57cec5SDimitry Andric}
28710b57cec5SDimitry Andric
28720b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
28730b57cec5SDimitry Andrictemplate <class _ForwardIterator>
28740b57cec5SDimitry Andric_ForwardIterator
2875cb14a3feSDimitry Andricbasic_regex<_CharT, _Traits>::__parse_RE_expression(_ForwardIterator __first, _ForwardIterator __last) {
2876cb14a3feSDimitry Andric  while (true) {
28770b57cec5SDimitry Andric    _ForwardIterator __temp = __parse_simple_RE(__first, __last);
28780b57cec5SDimitry Andric    if (__temp == __first)
28790b57cec5SDimitry Andric      break;
28800b57cec5SDimitry Andric    __first = __temp;
28810b57cec5SDimitry Andric  }
28820b57cec5SDimitry Andric  return __first;
28830b57cec5SDimitry Andric}
28840b57cec5SDimitry Andric
28850b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
28860b57cec5SDimitry Andrictemplate <class _ForwardIterator>
2887cb14a3feSDimitry Andric_ForwardIterator basic_regex<_CharT, _Traits>::__parse_simple_RE(_ForwardIterator __first, _ForwardIterator __last) {
2888cb14a3feSDimitry Andric  if (__first != __last) {
28890b57cec5SDimitry Andric    __owns_one_state<_CharT>* __e = __end_;
28900b57cec5SDimitry Andric    unsigned __mexp_begin         = __marked_count_;
28910b57cec5SDimitry Andric    _ForwardIterator __temp       = __parse_nondupl_RE(__first, __last);
28920b57cec5SDimitry Andric    if (__temp != __first)
2893cb14a3feSDimitry Andric      __first = __parse_RE_dupl_symbol(__temp, __last, __e, __mexp_begin + 1, __marked_count_ + 1);
28940b57cec5SDimitry Andric  }
28950b57cec5SDimitry Andric  return __first;
28960b57cec5SDimitry Andric}
28970b57cec5SDimitry Andric
28980b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
28990b57cec5SDimitry Andrictemplate <class _ForwardIterator>
2900cb14a3feSDimitry Andric_ForwardIterator basic_regex<_CharT, _Traits>::__parse_nondupl_RE(_ForwardIterator __first, _ForwardIterator __last) {
29010b57cec5SDimitry Andric  _ForwardIterator __temp = __first;
29020b57cec5SDimitry Andric  __first                 = __parse_one_char_or_coll_elem_RE(__first, __last);
2903cb14a3feSDimitry Andric  if (__temp == __first) {
29040b57cec5SDimitry Andric    __temp = __parse_Back_open_paren(__first, __last);
2905cb14a3feSDimitry Andric    if (__temp != __first) {
29060b57cec5SDimitry Andric      __push_begin_marked_subexpression();
29070b57cec5SDimitry Andric      unsigned __temp_count = __marked_count_;
29080b57cec5SDimitry Andric      __first               = __parse_RE_expression(__temp, __last);
29090b57cec5SDimitry Andric      __temp                = __parse_Back_close_paren(__first, __last);
29100b57cec5SDimitry Andric      if (__temp == __first)
29110b57cec5SDimitry Andric        __throw_regex_error<regex_constants::error_paren>();
29120b57cec5SDimitry Andric      __push_end_marked_subexpression(__temp_count);
29130b57cec5SDimitry Andric      __first = __temp;
2914cb14a3feSDimitry Andric    } else
29150b57cec5SDimitry Andric      __first = __parse_BACKREF(__first, __last);
29160b57cec5SDimitry Andric  }
29170b57cec5SDimitry Andric  return __first;
29180b57cec5SDimitry Andric}
29190b57cec5SDimitry Andric
29200b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
29210b57cec5SDimitry Andrictemplate <class _ForwardIterator>
29220b57cec5SDimitry Andric_ForwardIterator
2923cb14a3feSDimitry Andricbasic_regex<_CharT, _Traits>::__parse_one_char_or_coll_elem_RE(_ForwardIterator __first, _ForwardIterator __last) {
29240b57cec5SDimitry Andric  _ForwardIterator __temp = __parse_ORD_CHAR(__first, __last);
2925cb14a3feSDimitry Andric  if (__temp == __first) {
29260b57cec5SDimitry Andric    __temp = __parse_QUOTED_CHAR(__first, __last);
2927cb14a3feSDimitry Andric    if (__temp == __first) {
2928cb14a3feSDimitry Andric      if (__temp != __last && *__temp == '.') {
29290b57cec5SDimitry Andric        __push_match_any();
29300b57cec5SDimitry Andric        ++__temp;
2931cb14a3feSDimitry Andric      } else
29320b57cec5SDimitry Andric        __temp = __parse_bracket_expression(__first, __last);
29330b57cec5SDimitry Andric    }
29340b57cec5SDimitry Andric  }
29350b57cec5SDimitry Andric  __first = __temp;
29360b57cec5SDimitry Andric  return __first;
29370b57cec5SDimitry Andric}
29380b57cec5SDimitry Andric
29390b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
29400b57cec5SDimitry Andrictemplate <class _ForwardIterator>
29410b57cec5SDimitry Andric_ForwardIterator
2942cb14a3feSDimitry Andricbasic_regex<_CharT, _Traits>::__parse_one_char_or_coll_elem_ERE(_ForwardIterator __first, _ForwardIterator __last) {
29430b57cec5SDimitry Andric  _ForwardIterator __temp = __parse_ORD_CHAR_ERE(__first, __last);
2944cb14a3feSDimitry Andric  if (__temp == __first) {
29450b57cec5SDimitry Andric    __temp = __parse_QUOTED_CHAR_ERE(__first, __last);
2946cb14a3feSDimitry Andric    if (__temp == __first) {
2947cb14a3feSDimitry Andric      if (__temp != __last && *__temp == '.') {
29480b57cec5SDimitry Andric        __push_match_any();
29490b57cec5SDimitry Andric        ++__temp;
2950cb14a3feSDimitry Andric      } else
29510b57cec5SDimitry Andric        __temp = __parse_bracket_expression(__first, __last);
29520b57cec5SDimitry Andric    }
29530b57cec5SDimitry Andric  }
29540b57cec5SDimitry Andric  __first = __temp;
29550b57cec5SDimitry Andric  return __first;
29560b57cec5SDimitry Andric}
29570b57cec5SDimitry Andric
29580b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
29590b57cec5SDimitry Andrictemplate <class _ForwardIterator>
29600b57cec5SDimitry Andric_ForwardIterator
2961cb14a3feSDimitry Andricbasic_regex<_CharT, _Traits>::__parse_Back_open_paren(_ForwardIterator __first, _ForwardIterator __last) {
2962cb14a3feSDimitry Andric  if (__first != __last) {
29635f757f3fSDimitry Andric    _ForwardIterator __temp = std::next(__first);
2964cb14a3feSDimitry Andric    if (__temp != __last) {
29650b57cec5SDimitry Andric      if (*__first == '\\' && *__temp == '(')
29660b57cec5SDimitry Andric        __first = ++__temp;
29670b57cec5SDimitry Andric    }
29680b57cec5SDimitry Andric  }
29690b57cec5SDimitry Andric  return __first;
29700b57cec5SDimitry Andric}
29710b57cec5SDimitry Andric
29720b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
29730b57cec5SDimitry Andrictemplate <class _ForwardIterator>
29740b57cec5SDimitry Andric_ForwardIterator
2975cb14a3feSDimitry Andricbasic_regex<_CharT, _Traits>::__parse_Back_close_paren(_ForwardIterator __first, _ForwardIterator __last) {
2976cb14a3feSDimitry Andric  if (__first != __last) {
29775f757f3fSDimitry Andric    _ForwardIterator __temp = std::next(__first);
2978cb14a3feSDimitry Andric    if (__temp != __last) {
29790b57cec5SDimitry Andric      if (*__first == '\\' && *__temp == ')')
29800b57cec5SDimitry Andric        __first = ++__temp;
29810b57cec5SDimitry Andric    }
29820b57cec5SDimitry Andric  }
29830b57cec5SDimitry Andric  return __first;
29840b57cec5SDimitry Andric}
29850b57cec5SDimitry Andric
29860b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
29870b57cec5SDimitry Andrictemplate <class _ForwardIterator>
29880b57cec5SDimitry Andric_ForwardIterator
2989cb14a3feSDimitry Andricbasic_regex<_CharT, _Traits>::__parse_Back_open_brace(_ForwardIterator __first, _ForwardIterator __last) {
2990cb14a3feSDimitry Andric  if (__first != __last) {
29915f757f3fSDimitry Andric    _ForwardIterator __temp = std::next(__first);
2992cb14a3feSDimitry Andric    if (__temp != __last) {
29930b57cec5SDimitry Andric      if (*__first == '\\' && *__temp == '{')
29940b57cec5SDimitry Andric        __first = ++__temp;
29950b57cec5SDimitry Andric    }
29960b57cec5SDimitry Andric  }
29970b57cec5SDimitry Andric  return __first;
29980b57cec5SDimitry Andric}
29990b57cec5SDimitry Andric
30000b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
30010b57cec5SDimitry Andrictemplate <class _ForwardIterator>
30020b57cec5SDimitry Andric_ForwardIterator
3003cb14a3feSDimitry Andricbasic_regex<_CharT, _Traits>::__parse_Back_close_brace(_ForwardIterator __first, _ForwardIterator __last) {
3004cb14a3feSDimitry Andric  if (__first != __last) {
30055f757f3fSDimitry Andric    _ForwardIterator __temp = std::next(__first);
3006cb14a3feSDimitry Andric    if (__temp != __last) {
30070b57cec5SDimitry Andric      if (*__first == '\\' && *__temp == '}')
30080b57cec5SDimitry Andric        __first = ++__temp;
30090b57cec5SDimitry Andric    }
30100b57cec5SDimitry Andric  }
30110b57cec5SDimitry Andric  return __first;
30120b57cec5SDimitry Andric}
30130b57cec5SDimitry Andric
30140b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
30150b57cec5SDimitry Andrictemplate <class _ForwardIterator>
3016cb14a3feSDimitry Andric_ForwardIterator basic_regex<_CharT, _Traits>::__parse_BACKREF(_ForwardIterator __first, _ForwardIterator __last) {
3017cb14a3feSDimitry Andric  if (__first != __last) {
30185f757f3fSDimitry Andric    _ForwardIterator __temp = std::next(__first);
30195ffd83dbSDimitry Andric    if (__temp != __last && *__first == '\\' && __test_back_ref(*__temp))
30200b57cec5SDimitry Andric      __first = ++__temp;
30210b57cec5SDimitry Andric  }
30220b57cec5SDimitry Andric  return __first;
30230b57cec5SDimitry Andric}
30240b57cec5SDimitry Andric
30250b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
30260b57cec5SDimitry Andrictemplate <class _ForwardIterator>
3027cb14a3feSDimitry Andric_ForwardIterator basic_regex<_CharT, _Traits>::__parse_ORD_CHAR(_ForwardIterator __first, _ForwardIterator __last) {
3028cb14a3feSDimitry Andric  if (__first != __last) {
30295f757f3fSDimitry Andric    _ForwardIterator __temp = std::next(__first);
30300b57cec5SDimitry Andric    if (__temp == __last && *__first == '$')
30310b57cec5SDimitry Andric      return __first;
30320b57cec5SDimitry Andric    // Not called inside a bracket
30330b57cec5SDimitry Andric    if (*__first == '.' || *__first == '\\' || *__first == '[')
30340b57cec5SDimitry Andric      return __first;
30350b57cec5SDimitry Andric    __push_char(*__first);
30360b57cec5SDimitry Andric    ++__first;
30370b57cec5SDimitry Andric  }
30380b57cec5SDimitry Andric  return __first;
30390b57cec5SDimitry Andric}
30400b57cec5SDimitry Andric
30410b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
30420b57cec5SDimitry Andrictemplate <class _ForwardIterator>
3043cb14a3feSDimitry Andric_ForwardIterator basic_regex<_CharT, _Traits>::__parse_ORD_CHAR_ERE(_ForwardIterator __first, _ForwardIterator __last) {
3044cb14a3feSDimitry Andric  if (__first != __last) {
3045cb14a3feSDimitry Andric    switch (*__first) {
30460b57cec5SDimitry Andric    case '^':
30470b57cec5SDimitry Andric    case '.':
30480b57cec5SDimitry Andric    case '[':
30490b57cec5SDimitry Andric    case '$':
30500b57cec5SDimitry Andric    case '(':
30510b57cec5SDimitry Andric    case '|':
30520b57cec5SDimitry Andric    case '*':
30530b57cec5SDimitry Andric    case '+':
30540b57cec5SDimitry Andric    case '?':
30550b57cec5SDimitry Andric    case '{':
30560b57cec5SDimitry Andric    case '\\':
30570b57cec5SDimitry Andric      break;
30580b57cec5SDimitry Andric    case ')':
3059cb14a3feSDimitry Andric      if (__open_count_ == 0) {
30600b57cec5SDimitry Andric        __push_char(*__first);
30610b57cec5SDimitry Andric        ++__first;
30620b57cec5SDimitry Andric      }
30630b57cec5SDimitry Andric      break;
30640b57cec5SDimitry Andric    default:
30650b57cec5SDimitry Andric      __push_char(*__first);
30660b57cec5SDimitry Andric      ++__first;
30670b57cec5SDimitry Andric      break;
30680b57cec5SDimitry Andric    }
30690b57cec5SDimitry Andric  }
30700b57cec5SDimitry Andric  return __first;
30710b57cec5SDimitry Andric}
30720b57cec5SDimitry Andric
30730b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
30740b57cec5SDimitry Andrictemplate <class _ForwardIterator>
3075cb14a3feSDimitry Andric_ForwardIterator basic_regex<_CharT, _Traits>::__parse_QUOTED_CHAR(_ForwardIterator __first, _ForwardIterator __last) {
3076cb14a3feSDimitry Andric  if (__first != __last) {
30775f757f3fSDimitry Andric    _ForwardIterator __temp = std::next(__first);
3078cb14a3feSDimitry Andric    if (__temp != __last) {
3079cb14a3feSDimitry Andric      if (*__first == '\\') {
3080cb14a3feSDimitry Andric        switch (*__temp) {
30810b57cec5SDimitry Andric        case '^':
30820b57cec5SDimitry Andric        case '.':
30830b57cec5SDimitry Andric        case '*':
30840b57cec5SDimitry Andric        case '[':
30850b57cec5SDimitry Andric        case '$':
30860b57cec5SDimitry Andric        case '\\':
30870b57cec5SDimitry Andric          __push_char(*__temp);
30880b57cec5SDimitry Andric          __first = ++__temp;
30890b57cec5SDimitry Andric          break;
30900b57cec5SDimitry Andric        }
30910b57cec5SDimitry Andric      }
30920b57cec5SDimitry Andric    }
30930b57cec5SDimitry Andric  }
30940b57cec5SDimitry Andric  return __first;
30950b57cec5SDimitry Andric}
30960b57cec5SDimitry Andric
30970b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
30980b57cec5SDimitry Andrictemplate <class _ForwardIterator>
30990b57cec5SDimitry Andric_ForwardIterator
3100cb14a3feSDimitry Andricbasic_regex<_CharT, _Traits>::__parse_QUOTED_CHAR_ERE(_ForwardIterator __first, _ForwardIterator __last) {
3101cb14a3feSDimitry Andric  if (__first != __last) {
31025f757f3fSDimitry Andric    _ForwardIterator __temp = std::next(__first);
3103cb14a3feSDimitry Andric    if (__temp != __last) {
3104cb14a3feSDimitry Andric      if (*__first == '\\') {
3105cb14a3feSDimitry Andric        switch (*__temp) {
31060b57cec5SDimitry Andric        case '^':
31070b57cec5SDimitry Andric        case '.':
31080b57cec5SDimitry Andric        case '*':
31090b57cec5SDimitry Andric        case '[':
31100b57cec5SDimitry Andric        case '$':
31110b57cec5SDimitry Andric        case '\\':
31120b57cec5SDimitry Andric        case '(':
31130b57cec5SDimitry Andric        case ')':
31140b57cec5SDimitry Andric        case '|':
31150b57cec5SDimitry Andric        case '+':
31160b57cec5SDimitry Andric        case '?':
31170b57cec5SDimitry Andric        case '{':
31180b57cec5SDimitry Andric        case '}':
31190b57cec5SDimitry Andric          __push_char(*__temp);
31200b57cec5SDimitry Andric          __first = ++__temp;
31210b57cec5SDimitry Andric          break;
31220b57cec5SDimitry Andric        default:
31230b57cec5SDimitry Andric          if (__get_grammar(__flags_) == awk)
31240b57cec5SDimitry Andric            __first = __parse_awk_escape(++__first, __last);
31255ffd83dbSDimitry Andric          else if (__test_back_ref(*__temp))
31265ffd83dbSDimitry Andric            __first = ++__temp;
31270b57cec5SDimitry Andric          break;
31280b57cec5SDimitry Andric        }
31290b57cec5SDimitry Andric      }
31300b57cec5SDimitry Andric    }
31310b57cec5SDimitry Andric  }
31320b57cec5SDimitry Andric  return __first;
31330b57cec5SDimitry Andric}
31340b57cec5SDimitry Andric
31350b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
31360b57cec5SDimitry Andrictemplate <class _ForwardIterator>
3137cb14a3feSDimitry Andric_ForwardIterator basic_regex<_CharT, _Traits>::__parse_RE_dupl_symbol(
3138cb14a3feSDimitry Andric    _ForwardIterator __first,
31390b57cec5SDimitry Andric    _ForwardIterator __last,
31400b57cec5SDimitry Andric    __owns_one_state<_CharT>* __s,
31410b57cec5SDimitry Andric    unsigned __mexp_begin,
3142cb14a3feSDimitry Andric    unsigned __mexp_end) {
3143cb14a3feSDimitry Andric  if (__first != __last) {
3144cb14a3feSDimitry Andric    if (*__first == '*') {
31450b57cec5SDimitry Andric      __push_greedy_inf_repeat(0, __s, __mexp_begin, __mexp_end);
31460b57cec5SDimitry Andric      ++__first;
3147cb14a3feSDimitry Andric    } else {
31480b57cec5SDimitry Andric      _ForwardIterator __temp = __parse_Back_open_brace(__first, __last);
3149cb14a3feSDimitry Andric      if (__temp != __first) {
31500b57cec5SDimitry Andric        int __min = 0;
31510b57cec5SDimitry Andric        __first   = __temp;
31520b57cec5SDimitry Andric        __temp    = __parse_DUP_COUNT(__first, __last, __min);
31530b57cec5SDimitry Andric        if (__temp == __first)
31540b57cec5SDimitry Andric          __throw_regex_error<regex_constants::error_badbrace>();
31550b57cec5SDimitry Andric        __first = __temp;
31560b57cec5SDimitry Andric        if (__first == __last)
31570b57cec5SDimitry Andric          __throw_regex_error<regex_constants::error_brace>();
3158cb14a3feSDimitry Andric        if (*__first != ',') {
31590b57cec5SDimitry Andric          __temp = __parse_Back_close_brace(__first, __last);
31600b57cec5SDimitry Andric          if (__temp == __first)
31610b57cec5SDimitry Andric            __throw_regex_error<regex_constants::error_brace>();
3162cb14a3feSDimitry Andric          __push_loop(__min, __min, __s, __mexp_begin, __mexp_end, true);
31630b57cec5SDimitry Andric          __first = __temp;
3164cb14a3feSDimitry Andric        } else {
31650b57cec5SDimitry Andric          ++__first; // consume ','
31660b57cec5SDimitry Andric          int __max = -1;
31670b57cec5SDimitry Andric          __first   = __parse_DUP_COUNT(__first, __last, __max);
31680b57cec5SDimitry Andric          __temp    = __parse_Back_close_brace(__first, __last);
31690b57cec5SDimitry Andric          if (__temp == __first)
31700b57cec5SDimitry Andric            __throw_regex_error<regex_constants::error_brace>();
31710b57cec5SDimitry Andric          if (__max == -1)
31720b57cec5SDimitry Andric            __push_greedy_inf_repeat(__min, __s, __mexp_begin, __mexp_end);
3173cb14a3feSDimitry Andric          else {
31740b57cec5SDimitry Andric            if (__max < __min)
31750b57cec5SDimitry Andric              __throw_regex_error<regex_constants::error_badbrace>();
3176cb14a3feSDimitry Andric            __push_loop(__min, __max, __s, __mexp_begin, __mexp_end, true);
31770b57cec5SDimitry Andric          }
31780b57cec5SDimitry Andric          __first = __temp;
31790b57cec5SDimitry Andric        }
31800b57cec5SDimitry Andric      }
31810b57cec5SDimitry Andric    }
31820b57cec5SDimitry Andric  }
31830b57cec5SDimitry Andric  return __first;
31840b57cec5SDimitry Andric}
31850b57cec5SDimitry Andric
31860b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
31870b57cec5SDimitry Andrictemplate <class _ForwardIterator>
3188cb14a3feSDimitry Andric_ForwardIterator basic_regex<_CharT, _Traits>::__parse_ERE_dupl_symbol(
3189cb14a3feSDimitry Andric    _ForwardIterator __first,
31900b57cec5SDimitry Andric    _ForwardIterator __last,
31910b57cec5SDimitry Andric    __owns_one_state<_CharT>* __s,
31920b57cec5SDimitry Andric    unsigned __mexp_begin,
3193cb14a3feSDimitry Andric    unsigned __mexp_end) {
3194cb14a3feSDimitry Andric  if (__first != __last) {
31950b57cec5SDimitry Andric    unsigned __grammar = __get_grammar(__flags_);
3196cb14a3feSDimitry Andric    switch (*__first) {
31970b57cec5SDimitry Andric    case '*':
31980b57cec5SDimitry Andric      ++__first;
3199cb14a3feSDimitry Andric      if (__grammar == ECMAScript && __first != __last && *__first == '?') {
32000b57cec5SDimitry Andric        ++__first;
32010b57cec5SDimitry Andric        __push_nongreedy_inf_repeat(0, __s, __mexp_begin, __mexp_end);
3202cb14a3feSDimitry Andric      } else
32030b57cec5SDimitry Andric        __push_greedy_inf_repeat(0, __s, __mexp_begin, __mexp_end);
32040b57cec5SDimitry Andric      break;
32050b57cec5SDimitry Andric    case '+':
32060b57cec5SDimitry Andric      ++__first;
3207cb14a3feSDimitry Andric      if (__grammar == ECMAScript && __first != __last && *__first == '?') {
32080b57cec5SDimitry Andric        ++__first;
32090b57cec5SDimitry Andric        __push_nongreedy_inf_repeat(1, __s, __mexp_begin, __mexp_end);
3210cb14a3feSDimitry Andric      } else
32110b57cec5SDimitry Andric        __push_greedy_inf_repeat(1, __s, __mexp_begin, __mexp_end);
32120b57cec5SDimitry Andric      break;
32130b57cec5SDimitry Andric    case '?':
32140b57cec5SDimitry Andric      ++__first;
3215cb14a3feSDimitry Andric      if (__grammar == ECMAScript && __first != __last && *__first == '?') {
32160b57cec5SDimitry Andric        ++__first;
32170b57cec5SDimitry Andric        __push_loop(0, 1, __s, __mexp_begin, __mexp_end, false);
3218cb14a3feSDimitry Andric      } else
32190b57cec5SDimitry Andric        __push_loop(0, 1, __s, __mexp_begin, __mexp_end);
32200b57cec5SDimitry Andric      break;
3221cb14a3feSDimitry Andric    case '{': {
32220b57cec5SDimitry Andric      int __min;
32230b57cec5SDimitry Andric      _ForwardIterator __temp = __parse_DUP_COUNT(++__first, __last, __min);
32240b57cec5SDimitry Andric      if (__temp == __first)
32250b57cec5SDimitry Andric        __throw_regex_error<regex_constants::error_badbrace>();
32260b57cec5SDimitry Andric      __first = __temp;
32270b57cec5SDimitry Andric      if (__first == __last)
32280b57cec5SDimitry Andric        __throw_regex_error<regex_constants::error_brace>();
3229cb14a3feSDimitry Andric      switch (*__first) {
32300b57cec5SDimitry Andric      case '}':
32310b57cec5SDimitry Andric        ++__first;
3232cb14a3feSDimitry Andric        if (__grammar == ECMAScript && __first != __last && *__first == '?') {
32330b57cec5SDimitry Andric          ++__first;
32340b57cec5SDimitry Andric          __push_loop(__min, __min, __s, __mexp_begin, __mexp_end, false);
3235cb14a3feSDimitry Andric        } else
32360b57cec5SDimitry Andric          __push_loop(__min, __min, __s, __mexp_begin, __mexp_end);
32370b57cec5SDimitry Andric        break;
32380b57cec5SDimitry Andric      case ',':
32390b57cec5SDimitry Andric        ++__first;
32400b57cec5SDimitry Andric        if (__first == __last)
32410b57cec5SDimitry Andric          __throw_regex_error<regex_constants::error_badbrace>();
3242cb14a3feSDimitry Andric        if (*__first == '}') {
32430b57cec5SDimitry Andric          ++__first;
3244cb14a3feSDimitry Andric          if (__grammar == ECMAScript && __first != __last && *__first == '?') {
32450b57cec5SDimitry Andric            ++__first;
32460b57cec5SDimitry Andric            __push_nongreedy_inf_repeat(__min, __s, __mexp_begin, __mexp_end);
3247cb14a3feSDimitry Andric          } else
32480b57cec5SDimitry Andric            __push_greedy_inf_repeat(__min, __s, __mexp_begin, __mexp_end);
3249cb14a3feSDimitry Andric        } else {
32500b57cec5SDimitry Andric          int __max = -1;
32510b57cec5SDimitry Andric          __temp    = __parse_DUP_COUNT(__first, __last, __max);
32520b57cec5SDimitry Andric          if (__temp == __first)
32530b57cec5SDimitry Andric            __throw_regex_error<regex_constants::error_brace>();
32540b57cec5SDimitry Andric          __first = __temp;
32550b57cec5SDimitry Andric          if (__first == __last || *__first != '}')
32560b57cec5SDimitry Andric            __throw_regex_error<regex_constants::error_brace>();
32570b57cec5SDimitry Andric          ++__first;
32580b57cec5SDimitry Andric          if (__max < __min)
32590b57cec5SDimitry Andric            __throw_regex_error<regex_constants::error_badbrace>();
3260cb14a3feSDimitry Andric          if (__grammar == ECMAScript && __first != __last && *__first == '?') {
32610b57cec5SDimitry Andric            ++__first;
32620b57cec5SDimitry Andric            __push_loop(__min, __max, __s, __mexp_begin, __mexp_end, false);
3263cb14a3feSDimitry Andric          } else
32640b57cec5SDimitry Andric            __push_loop(__min, __max, __s, __mexp_begin, __mexp_end);
32650b57cec5SDimitry Andric        }
32660b57cec5SDimitry Andric        break;
32670b57cec5SDimitry Andric      default:
32680b57cec5SDimitry Andric        __throw_regex_error<regex_constants::error_badbrace>();
32690b57cec5SDimitry Andric      }
3270cb14a3feSDimitry Andric    } break;
32710b57cec5SDimitry Andric    }
32720b57cec5SDimitry Andric  }
32730b57cec5SDimitry Andric  return __first;
32740b57cec5SDimitry Andric}
32750b57cec5SDimitry Andric
32760b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
32770b57cec5SDimitry Andrictemplate <class _ForwardIterator>
32780b57cec5SDimitry Andric_ForwardIterator
3279cb14a3feSDimitry Andricbasic_regex<_CharT, _Traits>::__parse_bracket_expression(_ForwardIterator __first, _ForwardIterator __last) {
3280cb14a3feSDimitry Andric  if (__first != __last && *__first == '[') {
32810b57cec5SDimitry Andric    ++__first;
32820b57cec5SDimitry Andric    if (__first == __last)
32830b57cec5SDimitry Andric      __throw_regex_error<regex_constants::error_brack>();
32840b57cec5SDimitry Andric    bool __negate = false;
3285cb14a3feSDimitry Andric    if (*__first == '^') {
32860b57cec5SDimitry Andric      ++__first;
32870b57cec5SDimitry Andric      __negate = true;
32880b57cec5SDimitry Andric    }
32890b57cec5SDimitry Andric    __bracket_expression<_CharT, _Traits>* __ml = __start_matching_list(__negate);
32900b57cec5SDimitry Andric    // __ml owned by *this
32910b57cec5SDimitry Andric    if (__first == __last)
32920b57cec5SDimitry Andric      __throw_regex_error<regex_constants::error_brack>();
3293cb14a3feSDimitry Andric    if (__get_grammar(__flags_) != ECMAScript && *__first == ']') {
32940b57cec5SDimitry Andric      __ml->__add_char(']');
32950b57cec5SDimitry Andric      ++__first;
32960b57cec5SDimitry Andric    }
32970b57cec5SDimitry Andric    __first = __parse_follow_list(__first, __last, __ml);
32980b57cec5SDimitry Andric    if (__first == __last)
32990b57cec5SDimitry Andric      __throw_regex_error<regex_constants::error_brack>();
3300cb14a3feSDimitry Andric    if (*__first == '-') {
33010b57cec5SDimitry Andric      __ml->__add_char('-');
33020b57cec5SDimitry Andric      ++__first;
33030b57cec5SDimitry Andric    }
33040b57cec5SDimitry Andric    if (__first == __last || *__first != ']')
33050b57cec5SDimitry Andric      __throw_regex_error<regex_constants::error_brack>();
33060b57cec5SDimitry Andric    ++__first;
33070b57cec5SDimitry Andric  }
33080b57cec5SDimitry Andric  return __first;
33090b57cec5SDimitry Andric}
33100b57cec5SDimitry Andric
33110b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
33120b57cec5SDimitry Andrictemplate <class _ForwardIterator>
3313cb14a3feSDimitry Andric_ForwardIterator basic_regex<_CharT, _Traits>::__parse_follow_list(
3314cb14a3feSDimitry Andric    _ForwardIterator __first, _ForwardIterator __last, __bracket_expression<_CharT, _Traits>* __ml) {
3315cb14a3feSDimitry Andric  if (__first != __last) {
3316cb14a3feSDimitry Andric    while (true) {
3317cb14a3feSDimitry Andric      _ForwardIterator __temp = __parse_expression_term(__first, __last, __ml);
33180b57cec5SDimitry Andric      if (__temp == __first)
33190b57cec5SDimitry Andric        break;
33200b57cec5SDimitry Andric      __first = __temp;
33210b57cec5SDimitry Andric    }
33220b57cec5SDimitry Andric  }
33230b57cec5SDimitry Andric  return __first;
33240b57cec5SDimitry Andric}
33250b57cec5SDimitry Andric
33260b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
33270b57cec5SDimitry Andrictemplate <class _ForwardIterator>
3328cb14a3feSDimitry Andric_ForwardIterator basic_regex<_CharT, _Traits>::__parse_expression_term(
3329cb14a3feSDimitry Andric    _ForwardIterator __first, _ForwardIterator __last, __bracket_expression<_CharT, _Traits>* __ml) {
3330cb14a3feSDimitry Andric  if (__first != __last && *__first != ']') {
33315f757f3fSDimitry Andric    _ForwardIterator __temp = std::next(__first);
33320b57cec5SDimitry Andric    basic_string<_CharT> __start_range;
3333cb14a3feSDimitry Andric    if (__temp != __last && *__first == '[') {
33340b57cec5SDimitry Andric      if (*__temp == '=')
33350b57cec5SDimitry Andric        return __parse_equivalence_class(++__temp, __last, __ml);
33360b57cec5SDimitry Andric      else if (*__temp == ':')
33370b57cec5SDimitry Andric        return __parse_character_class(++__temp, __last, __ml);
33380b57cec5SDimitry Andric      else if (*__temp == '.')
33390b57cec5SDimitry Andric        __first = __parse_collating_symbol(++__temp, __last, __start_range);
33400b57cec5SDimitry Andric    }
33410b57cec5SDimitry Andric    unsigned __grammar = __get_grammar(__flags_);
3342cb14a3feSDimitry Andric    if (__start_range.empty()) {
3343cb14a3feSDimitry Andric      if ((__grammar == ECMAScript || __grammar == awk) && *__first == '\\') {
33440b57cec5SDimitry Andric        if (__grammar == ECMAScript)
33450b57cec5SDimitry Andric          __first = __parse_class_escape(++__first, __last, __start_range, __ml);
33460b57cec5SDimitry Andric        else
33470b57cec5SDimitry Andric          __first = __parse_awk_escape(++__first, __last, &__start_range);
3348cb14a3feSDimitry Andric      } else {
33490b57cec5SDimitry Andric        __start_range = *__first;
33500b57cec5SDimitry Andric        ++__first;
33510b57cec5SDimitry Andric      }
33520b57cec5SDimitry Andric    }
3353cb14a3feSDimitry Andric    if (__first != __last && *__first != ']') {
33545f757f3fSDimitry Andric      __temp = std::next(__first);
3355cb14a3feSDimitry Andric      if (__temp != __last && *__first == '-' && *__temp != ']') {
33560b57cec5SDimitry Andric        // parse a range
33570b57cec5SDimitry Andric        basic_string<_CharT> __end_range;
33580b57cec5SDimitry Andric        __first = __temp;
33590b57cec5SDimitry Andric        ++__temp;
33600b57cec5SDimitry Andric        if (__temp != __last && *__first == '[' && *__temp == '.')
33610b57cec5SDimitry Andric          __first = __parse_collating_symbol(++__temp, __last, __end_range);
3362cb14a3feSDimitry Andric        else {
3363cb14a3feSDimitry Andric          if ((__grammar == ECMAScript || __grammar == awk) && *__first == '\\') {
33640b57cec5SDimitry Andric            if (__grammar == ECMAScript)
3365cb14a3feSDimitry Andric              __first = __parse_class_escape(++__first, __last, __end_range, __ml);
33660b57cec5SDimitry Andric            else
3367cb14a3feSDimitry Andric              __first = __parse_awk_escape(++__first, __last, &__end_range);
3368cb14a3feSDimitry Andric          } else {
33690b57cec5SDimitry Andric            __end_range = *__first;
33700b57cec5SDimitry Andric            ++__first;
33710b57cec5SDimitry Andric          }
33720b57cec5SDimitry Andric        }
33735f757f3fSDimitry Andric        __ml->__add_range(std::move(__start_range), std::move(__end_range));
3374cb14a3feSDimitry Andric      } else if (!__start_range.empty()) {
33750b57cec5SDimitry Andric        if (__start_range.size() == 1)
33760b57cec5SDimitry Andric          __ml->__add_char(__start_range[0]);
33770b57cec5SDimitry Andric        else
33780b57cec5SDimitry Andric          __ml->__add_digraph(__start_range[0], __start_range[1]);
33790b57cec5SDimitry Andric      }
3380cb14a3feSDimitry Andric    } else if (!__start_range.empty()) {
33810b57cec5SDimitry Andric      if (__start_range.size() == 1)
33820b57cec5SDimitry Andric        __ml->__add_char(__start_range[0]);
33830b57cec5SDimitry Andric      else
33840b57cec5SDimitry Andric        __ml->__add_digraph(__start_range[0], __start_range[1]);
33850b57cec5SDimitry Andric    }
33860b57cec5SDimitry Andric  }
33870b57cec5SDimitry Andric  return __first;
33880b57cec5SDimitry Andric}
33890b57cec5SDimitry Andric
33900b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
33910b57cec5SDimitry Andrictemplate <class _ForwardIterator>
3392cb14a3feSDimitry Andric_ForwardIterator basic_regex<_CharT, _Traits>::__parse_class_escape(
3393cb14a3feSDimitry Andric    _ForwardIterator __first,
33940b57cec5SDimitry Andric    _ForwardIterator __last,
33950b57cec5SDimitry Andric    basic_string<_CharT>& __str,
3396cb14a3feSDimitry Andric    __bracket_expression<_CharT, _Traits>* __ml) {
33970b57cec5SDimitry Andric  if (__first == __last)
33980b57cec5SDimitry Andric    __throw_regex_error<regex_constants::error_escape>();
3399cb14a3feSDimitry Andric  switch (*__first) {
34000b57cec5SDimitry Andric  case 0:
34010b57cec5SDimitry Andric    __str = *__first;
34020b57cec5SDimitry Andric    return ++__first;
34030b57cec5SDimitry Andric  case 'b':
34040b57cec5SDimitry Andric    __str = _CharT(8);
34050b57cec5SDimitry Andric    return ++__first;
34060b57cec5SDimitry Andric  case 'd':
34070b57cec5SDimitry Andric    __ml->__add_class(ctype_base::digit);
34080b57cec5SDimitry Andric    return ++__first;
34090b57cec5SDimitry Andric  case 'D':
34100b57cec5SDimitry Andric    __ml->__add_neg_class(ctype_base::digit);
34110b57cec5SDimitry Andric    return ++__first;
34120b57cec5SDimitry Andric  case 's':
34130b57cec5SDimitry Andric    __ml->__add_class(ctype_base::space);
34140b57cec5SDimitry Andric    return ++__first;
34150b57cec5SDimitry Andric  case 'S':
34160b57cec5SDimitry Andric    __ml->__add_neg_class(ctype_base::space);
34170b57cec5SDimitry Andric    return ++__first;
34180b57cec5SDimitry Andric  case 'w':
34190b57cec5SDimitry Andric    __ml->__add_class(ctype_base::alnum);
34200b57cec5SDimitry Andric    __ml->__add_char('_');
34210b57cec5SDimitry Andric    return ++__first;
34220b57cec5SDimitry Andric  case 'W':
34230b57cec5SDimitry Andric    __ml->__add_neg_class(ctype_base::alnum);
34240b57cec5SDimitry Andric    __ml->__add_neg_char('_');
34250b57cec5SDimitry Andric    return ++__first;
34260b57cec5SDimitry Andric  }
34270b57cec5SDimitry Andric  __first = __parse_character_escape(__first, __last, &__str);
34280b57cec5SDimitry Andric  return __first;
34290b57cec5SDimitry Andric}
34300b57cec5SDimitry Andric
34310b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
34320b57cec5SDimitry Andrictemplate <class _ForwardIterator>
3433cb14a3feSDimitry Andric_ForwardIterator basic_regex<_CharT, _Traits>::__parse_awk_escape(
3434cb14a3feSDimitry Andric    _ForwardIterator __first, _ForwardIterator __last, basic_string<_CharT>* __str) {
34350b57cec5SDimitry Andric  if (__first == __last)
34360b57cec5SDimitry Andric    __throw_regex_error<regex_constants::error_escape>();
3437cb14a3feSDimitry Andric  switch (*__first) {
34380b57cec5SDimitry Andric  case '\\':
34390b57cec5SDimitry Andric  case '"':
34400b57cec5SDimitry Andric  case '/':
34410b57cec5SDimitry Andric    if (__str)
34420b57cec5SDimitry Andric      *__str = *__first;
34430b57cec5SDimitry Andric    else
34440b57cec5SDimitry Andric      __push_char(*__first);
34450b57cec5SDimitry Andric    return ++__first;
34460b57cec5SDimitry Andric  case 'a':
34470b57cec5SDimitry Andric    if (__str)
34480b57cec5SDimitry Andric      *__str = _CharT(7);
34490b57cec5SDimitry Andric    else
34500b57cec5SDimitry Andric      __push_char(_CharT(7));
34510b57cec5SDimitry Andric    return ++__first;
34520b57cec5SDimitry Andric  case 'b':
34530b57cec5SDimitry Andric    if (__str)
34540b57cec5SDimitry Andric      *__str = _CharT(8);
34550b57cec5SDimitry Andric    else
34560b57cec5SDimitry Andric      __push_char(_CharT(8));
34570b57cec5SDimitry Andric    return ++__first;
34580b57cec5SDimitry Andric  case 'f':
34590b57cec5SDimitry Andric    if (__str)
34600b57cec5SDimitry Andric      *__str = _CharT(0xC);
34610b57cec5SDimitry Andric    else
34620b57cec5SDimitry Andric      __push_char(_CharT(0xC));
34630b57cec5SDimitry Andric    return ++__first;
34640b57cec5SDimitry Andric  case 'n':
34650b57cec5SDimitry Andric    if (__str)
34660b57cec5SDimitry Andric      *__str = _CharT(0xA);
34670b57cec5SDimitry Andric    else
34680b57cec5SDimitry Andric      __push_char(_CharT(0xA));
34690b57cec5SDimitry Andric    return ++__first;
34700b57cec5SDimitry Andric  case 'r':
34710b57cec5SDimitry Andric    if (__str)
34720b57cec5SDimitry Andric      *__str = _CharT(0xD);
34730b57cec5SDimitry Andric    else
34740b57cec5SDimitry Andric      __push_char(_CharT(0xD));
34750b57cec5SDimitry Andric    return ++__first;
34760b57cec5SDimitry Andric  case 't':
34770b57cec5SDimitry Andric    if (__str)
34780b57cec5SDimitry Andric      *__str = _CharT(0x9);
34790b57cec5SDimitry Andric    else
34800b57cec5SDimitry Andric      __push_char(_CharT(0x9));
34810b57cec5SDimitry Andric    return ++__first;
34820b57cec5SDimitry Andric  case 'v':
34830b57cec5SDimitry Andric    if (__str)
34840b57cec5SDimitry Andric      *__str = _CharT(0xB);
34850b57cec5SDimitry Andric    else
34860b57cec5SDimitry Andric      __push_char(_CharT(0xB));
34870b57cec5SDimitry Andric    return ++__first;
34880b57cec5SDimitry Andric  }
3489cb14a3feSDimitry Andric  if ('0' <= *__first && *__first <= '7') {
34900b57cec5SDimitry Andric    unsigned __val = *__first - '0';
3491cb14a3feSDimitry Andric    if (++__first != __last && ('0' <= *__first && *__first <= '7')) {
34920b57cec5SDimitry Andric      __val = 8 * __val + *__first - '0';
34930b57cec5SDimitry Andric      if (++__first != __last && ('0' <= *__first && *__first <= '7'))
34940b57cec5SDimitry Andric        __val = 8 * __val + *__first++ - '0';
34950b57cec5SDimitry Andric    }
34960b57cec5SDimitry Andric    if (__str)
34970b57cec5SDimitry Andric      *__str = _CharT(__val);
34980b57cec5SDimitry Andric    else
34990b57cec5SDimitry Andric      __push_char(_CharT(__val));
3500cb14a3feSDimitry Andric  } else
35010b57cec5SDimitry Andric    __throw_regex_error<regex_constants::error_escape>();
35020b57cec5SDimitry Andric  return __first;
35030b57cec5SDimitry Andric}
35040b57cec5SDimitry Andric
35050b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
35060b57cec5SDimitry Andrictemplate <class _ForwardIterator>
3507cb14a3feSDimitry Andric_ForwardIterator basic_regex<_CharT, _Traits>::__parse_equivalence_class(
3508cb14a3feSDimitry Andric    _ForwardIterator __first, _ForwardIterator __last, __bracket_expression<_CharT, _Traits>* __ml) {
35090b57cec5SDimitry Andric  // Found [=
35100b57cec5SDimitry Andric  //   This means =] must exist
351106c3fb27SDimitry Andric  value_type __equal_close[2] = {'=', ']'};
3512cb14a3feSDimitry Andric  _ForwardIterator __temp     = std::search(__first, __last, __equal_close, __equal_close + 2);
35130b57cec5SDimitry Andric  if (__temp == __last)
35140b57cec5SDimitry Andric    __throw_regex_error<regex_constants::error_brack>();
35150b57cec5SDimitry Andric  // [__first, __temp) contains all text in [= ... =]
3516cb14a3feSDimitry Andric  string_type __collate_name = __traits_.lookup_collatename(__first, __temp);
35170b57cec5SDimitry Andric  if (__collate_name.empty())
35180b57cec5SDimitry Andric    __throw_regex_error<regex_constants::error_collate>();
3519cb14a3feSDimitry Andric  string_type __equiv_name = __traits_.transform_primary(__collate_name.begin(), __collate_name.end());
35200b57cec5SDimitry Andric  if (!__equiv_name.empty())
35210b57cec5SDimitry Andric    __ml->__add_equivalence(__equiv_name);
3522cb14a3feSDimitry Andric  else {
3523cb14a3feSDimitry Andric    switch (__collate_name.size()) {
35240b57cec5SDimitry Andric    case 1:
35250b57cec5SDimitry Andric      __ml->__add_char(__collate_name[0]);
35260b57cec5SDimitry Andric      break;
35270b57cec5SDimitry Andric    case 2:
35280b57cec5SDimitry Andric      __ml->__add_digraph(__collate_name[0], __collate_name[1]);
35290b57cec5SDimitry Andric      break;
35300b57cec5SDimitry Andric    default:
35310b57cec5SDimitry Andric      __throw_regex_error<regex_constants::error_collate>();
35320b57cec5SDimitry Andric    }
35330b57cec5SDimitry Andric  }
35345f757f3fSDimitry Andric  __first = std::next(__temp, 2);
35350b57cec5SDimitry Andric  return __first;
35360b57cec5SDimitry Andric}
35370b57cec5SDimitry Andric
35380b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
35390b57cec5SDimitry Andrictemplate <class _ForwardIterator>
3540cb14a3feSDimitry Andric_ForwardIterator basic_regex<_CharT, _Traits>::__parse_character_class(
3541cb14a3feSDimitry Andric    _ForwardIterator __first, _ForwardIterator __last, __bracket_expression<_CharT, _Traits>* __ml) {
35420b57cec5SDimitry Andric  // Found [:
35430b57cec5SDimitry Andric  //   This means :] must exist
354406c3fb27SDimitry Andric  value_type __colon_close[2] = {':', ']'};
3545cb14a3feSDimitry Andric  _ForwardIterator __temp     = std::search(__first, __last, __colon_close, __colon_close + 2);
35460b57cec5SDimitry Andric  if (__temp == __last)
35470b57cec5SDimitry Andric    __throw_regex_error<regex_constants::error_brack>();
35480b57cec5SDimitry Andric  // [__first, __temp) contains all text in [: ... :]
35490b57cec5SDimitry Andric  typedef typename _Traits::char_class_type char_class_type;
3550cb14a3feSDimitry Andric  char_class_type __class_type = __traits_.lookup_classname(__first, __temp, __flags_ & icase);
35510b57cec5SDimitry Andric  if (__class_type == 0)
35520b57cec5SDimitry Andric    __throw_regex_error<regex_constants::error_ctype>();
35530b57cec5SDimitry Andric  __ml->__add_class(__class_type);
35545f757f3fSDimitry Andric  __first = std::next(__temp, 2);
35550b57cec5SDimitry Andric  return __first;
35560b57cec5SDimitry Andric}
35570b57cec5SDimitry Andric
35580b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
35590b57cec5SDimitry Andrictemplate <class _ForwardIterator>
3560cb14a3feSDimitry Andric_ForwardIterator basic_regex<_CharT, _Traits>::__parse_collating_symbol(
3561cb14a3feSDimitry Andric    _ForwardIterator __first, _ForwardIterator __last, basic_string<_CharT>& __col_sym) {
35620b57cec5SDimitry Andric  // Found [.
35630b57cec5SDimitry Andric  //   This means .] must exist
356406c3fb27SDimitry Andric  value_type __dot_close[2] = {'.', ']'};
3565cb14a3feSDimitry Andric  _ForwardIterator __temp   = std::search(__first, __last, __dot_close, __dot_close + 2);
35660b57cec5SDimitry Andric  if (__temp == __last)
35670b57cec5SDimitry Andric    __throw_regex_error<regex_constants::error_brack>();
35680b57cec5SDimitry Andric  // [__first, __temp) contains all text in [. ... .]
35690b57cec5SDimitry Andric  __col_sym = __traits_.lookup_collatename(__first, __temp);
3570cb14a3feSDimitry Andric  switch (__col_sym.size()) {
35710b57cec5SDimitry Andric  case 1:
35720b57cec5SDimitry Andric  case 2:
35730b57cec5SDimitry Andric    break;
35740b57cec5SDimitry Andric  default:
35750b57cec5SDimitry Andric    __throw_regex_error<regex_constants::error_collate>();
35760b57cec5SDimitry Andric  }
35775f757f3fSDimitry Andric  __first = std::next(__temp, 2);
35780b57cec5SDimitry Andric  return __first;
35790b57cec5SDimitry Andric}
35800b57cec5SDimitry Andric
35810b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
35820b57cec5SDimitry Andrictemplate <class _ForwardIterator>
35830b57cec5SDimitry Andric_ForwardIterator
3584cb14a3feSDimitry Andricbasic_regex<_CharT, _Traits>::__parse_DUP_COUNT(_ForwardIterator __first, _ForwardIterator __last, int& __c) {
3585cb14a3feSDimitry Andric  if (__first != __last) {
35860b57cec5SDimitry Andric    int __val = __traits_.value(*__first, 10);
3587cb14a3feSDimitry Andric    if (__val != -1) {
35880b57cec5SDimitry Andric      __c = __val;
3589cb14a3feSDimitry Andric      for (++__first; __first != __last && (__val = __traits_.value(*__first, 10)) != -1; ++__first) {
3590e8d8bef9SDimitry Andric        if (__c >= numeric_limits<int>::max() / 10)
35910b57cec5SDimitry Andric          __throw_regex_error<regex_constants::error_badbrace>();
35920b57cec5SDimitry Andric        __c *= 10;
35930b57cec5SDimitry Andric        __c += __val;
35940b57cec5SDimitry Andric      }
35950b57cec5SDimitry Andric    }
35960b57cec5SDimitry Andric  }
35970b57cec5SDimitry Andric  return __first;
35980b57cec5SDimitry Andric}
35990b57cec5SDimitry Andric
36000b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
36010b57cec5SDimitry Andrictemplate <class _ForwardIterator>
3602cb14a3feSDimitry Andric_ForwardIterator basic_regex<_CharT, _Traits>::__parse_ecma_exp(_ForwardIterator __first, _ForwardIterator __last) {
36030b57cec5SDimitry Andric  __owns_one_state<_CharT>* __sa = __end_;
36040b57cec5SDimitry Andric  _ForwardIterator __temp        = __parse_alternative(__first, __last);
36050b57cec5SDimitry Andric  if (__temp == __first)
36060b57cec5SDimitry Andric    __push_empty();
36070b57cec5SDimitry Andric  __first = __temp;
3608cb14a3feSDimitry Andric  while (__first != __last && *__first == '|') {
36090b57cec5SDimitry Andric    __owns_one_state<_CharT>* __sb = __end_;
36100b57cec5SDimitry Andric    __temp                         = __parse_alternative(++__first, __last);
36110b57cec5SDimitry Andric    if (__temp == __first)
36120b57cec5SDimitry Andric      __push_empty();
36130b57cec5SDimitry Andric    __push_alternation(__sa, __sb);
36140b57cec5SDimitry Andric    __first = __temp;
36150b57cec5SDimitry Andric  }
36160b57cec5SDimitry Andric  return __first;
36170b57cec5SDimitry Andric}
36180b57cec5SDimitry Andric
36190b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
36200b57cec5SDimitry Andrictemplate <class _ForwardIterator>
3621cb14a3feSDimitry Andric_ForwardIterator basic_regex<_CharT, _Traits>::__parse_alternative(_ForwardIterator __first, _ForwardIterator __last) {
3622cb14a3feSDimitry Andric  while (true) {
36230b57cec5SDimitry Andric    _ForwardIterator __temp = __parse_term(__first, __last);
36240b57cec5SDimitry Andric    if (__temp == __first)
36250b57cec5SDimitry Andric      break;
36260b57cec5SDimitry Andric    __first = __temp;
36270b57cec5SDimitry Andric  }
36280b57cec5SDimitry Andric  return __first;
36290b57cec5SDimitry Andric}
36300b57cec5SDimitry Andric
36310b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
36320b57cec5SDimitry Andrictemplate <class _ForwardIterator>
3633cb14a3feSDimitry Andric_ForwardIterator basic_regex<_CharT, _Traits>::__parse_term(_ForwardIterator __first, _ForwardIterator __last) {
36340b57cec5SDimitry Andric  _ForwardIterator __temp = __parse_assertion(__first, __last);
3635cb14a3feSDimitry Andric  if (__temp == __first) {
36360b57cec5SDimitry Andric    __owns_one_state<_CharT>* __e = __end_;
36370b57cec5SDimitry Andric    unsigned __mexp_begin         = __marked_count_;
36380b57cec5SDimitry Andric    __temp                        = __parse_atom(__first, __last);
36390b57cec5SDimitry Andric    if (__temp != __first)
3640cb14a3feSDimitry Andric      __first = __parse_ERE_dupl_symbol(__temp, __last, __e, __mexp_begin + 1, __marked_count_ + 1);
3641cb14a3feSDimitry Andric  } else
36420b57cec5SDimitry Andric    __first = __temp;
36430b57cec5SDimitry Andric  return __first;
36440b57cec5SDimitry Andric}
36450b57cec5SDimitry Andric
36460b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
36470b57cec5SDimitry Andrictemplate <class _ForwardIterator>
3648cb14a3feSDimitry Andric_ForwardIterator basic_regex<_CharT, _Traits>::__parse_assertion(_ForwardIterator __first, _ForwardIterator __last) {
3649cb14a3feSDimitry Andric  if (__first != __last) {
3650cb14a3feSDimitry Andric    switch (*__first) {
36510b57cec5SDimitry Andric    case '^':
36520b57cec5SDimitry Andric      __push_l_anchor();
36530b57cec5SDimitry Andric      ++__first;
36540b57cec5SDimitry Andric      break;
36550b57cec5SDimitry Andric    case '$':
36560b57cec5SDimitry Andric      __push_r_anchor();
36570b57cec5SDimitry Andric      ++__first;
36580b57cec5SDimitry Andric      break;
3659cb14a3feSDimitry Andric    case '\\': {
36605f757f3fSDimitry Andric      _ForwardIterator __temp = std::next(__first);
3661cb14a3feSDimitry Andric      if (__temp != __last) {
3662cb14a3feSDimitry Andric        if (*__temp == 'b') {
36630b57cec5SDimitry Andric          __push_word_boundary(false);
36640b57cec5SDimitry Andric          __first = ++__temp;
3665cb14a3feSDimitry Andric        } else if (*__temp == 'B') {
36660b57cec5SDimitry Andric          __push_word_boundary(true);
36670b57cec5SDimitry Andric          __first = ++__temp;
36680b57cec5SDimitry Andric        }
36690b57cec5SDimitry Andric      }
3670cb14a3feSDimitry Andric    } break;
3671cb14a3feSDimitry Andric    case '(': {
36725f757f3fSDimitry Andric      _ForwardIterator __temp = std::next(__first);
3673cb14a3feSDimitry Andric      if (__temp != __last && *__temp == '?') {
3674cb14a3feSDimitry Andric        if (++__temp != __last) {
3675cb14a3feSDimitry Andric          switch (*__temp) {
3676cb14a3feSDimitry Andric          case '=': {
36770b57cec5SDimitry Andric            basic_regex __exp;
36780b57cec5SDimitry Andric            __exp.__flags_  = __flags_;
36790b57cec5SDimitry Andric            __temp          = __exp.__parse(++__temp, __last);
36800b57cec5SDimitry Andric            unsigned __mexp = __exp.__marked_count_;
36815f757f3fSDimitry Andric            __push_lookahead(std::move(__exp), false, __marked_count_);
36820b57cec5SDimitry Andric            __marked_count_ += __mexp;
36830b57cec5SDimitry Andric            if (__temp == __last || *__temp != ')')
36840b57cec5SDimitry Andric              __throw_regex_error<regex_constants::error_paren>();
36850b57cec5SDimitry Andric            __first = ++__temp;
3686cb14a3feSDimitry Andric          } break;
3687cb14a3feSDimitry Andric          case '!': {
36880b57cec5SDimitry Andric            basic_regex __exp;
36890b57cec5SDimitry Andric            __exp.__flags_  = __flags_;
36900b57cec5SDimitry Andric            __temp          = __exp.__parse(++__temp, __last);
36910b57cec5SDimitry Andric            unsigned __mexp = __exp.__marked_count_;
36925f757f3fSDimitry Andric            __push_lookahead(std::move(__exp), true, __marked_count_);
36930b57cec5SDimitry Andric            __marked_count_ += __mexp;
36940b57cec5SDimitry Andric            if (__temp == __last || *__temp != ')')
36950b57cec5SDimitry Andric              __throw_regex_error<regex_constants::error_paren>();
36960b57cec5SDimitry Andric            __first = ++__temp;
3697cb14a3feSDimitry Andric          } break;
36980b57cec5SDimitry Andric          }
36990b57cec5SDimitry Andric        }
37000b57cec5SDimitry Andric      }
3701cb14a3feSDimitry Andric    } break;
37020b57cec5SDimitry Andric    }
37030b57cec5SDimitry Andric  }
37040b57cec5SDimitry Andric  return __first;
37050b57cec5SDimitry Andric}
37060b57cec5SDimitry Andric
37070b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
37080b57cec5SDimitry Andrictemplate <class _ForwardIterator>
3709cb14a3feSDimitry Andric_ForwardIterator basic_regex<_CharT, _Traits>::__parse_atom(_ForwardIterator __first, _ForwardIterator __last) {
3710cb14a3feSDimitry Andric  if (__first != __last) {
3711cb14a3feSDimitry Andric    switch (*__first) {
37120b57cec5SDimitry Andric    case '.':
37130b57cec5SDimitry Andric      __push_match_any_but_newline();
37140b57cec5SDimitry Andric      ++__first;
37150b57cec5SDimitry Andric      break;
37160b57cec5SDimitry Andric    case '\\':
37170b57cec5SDimitry Andric      __first = __parse_atom_escape(__first, __last);
37180b57cec5SDimitry Andric      break;
37190b57cec5SDimitry Andric    case '[':
37200b57cec5SDimitry Andric      __first = __parse_bracket_expression(__first, __last);
37210b57cec5SDimitry Andric      break;
3722cb14a3feSDimitry Andric    case '(': {
37230b57cec5SDimitry Andric      ++__first;
37240b57cec5SDimitry Andric      if (__first == __last)
37250b57cec5SDimitry Andric        __throw_regex_error<regex_constants::error_paren>();
37265f757f3fSDimitry Andric      _ForwardIterator __temp = std::next(__first);
3727cb14a3feSDimitry Andric      if (__temp != __last && *__first == '?' && *__temp == ':') {
37280b57cec5SDimitry Andric        ++__open_count_;
37290b57cec5SDimitry Andric        __first = __parse_ecma_exp(++__temp, __last);
37300b57cec5SDimitry Andric        if (__first == __last || *__first != ')')
37310b57cec5SDimitry Andric          __throw_regex_error<regex_constants::error_paren>();
37320b57cec5SDimitry Andric        --__open_count_;
37330b57cec5SDimitry Andric        ++__first;
3734cb14a3feSDimitry Andric      } else {
37350b57cec5SDimitry Andric        __push_begin_marked_subexpression();
37360b57cec5SDimitry Andric        unsigned __temp_count = __marked_count_;
37370b57cec5SDimitry Andric        ++__open_count_;
37380b57cec5SDimitry Andric        __first = __parse_ecma_exp(__first, __last);
37390b57cec5SDimitry Andric        if (__first == __last || *__first != ')')
37400b57cec5SDimitry Andric          __throw_regex_error<regex_constants::error_paren>();
37410b57cec5SDimitry Andric        __push_end_marked_subexpression(__temp_count);
37420b57cec5SDimitry Andric        --__open_count_;
37430b57cec5SDimitry Andric        ++__first;
37440b57cec5SDimitry Andric      }
3745cb14a3feSDimitry Andric    } break;
37460b57cec5SDimitry Andric    case '*':
37470b57cec5SDimitry Andric    case '+':
37480b57cec5SDimitry Andric    case '?':
37490b57cec5SDimitry Andric    case '{':
37500b57cec5SDimitry Andric      __throw_regex_error<regex_constants::error_badrepeat>();
37510b57cec5SDimitry Andric      break;
37520b57cec5SDimitry Andric    default:
37530b57cec5SDimitry Andric      __first = __parse_pattern_character(__first, __last);
37540b57cec5SDimitry Andric      break;
37550b57cec5SDimitry Andric    }
37560b57cec5SDimitry Andric  }
37570b57cec5SDimitry Andric  return __first;
37580b57cec5SDimitry Andric}
37590b57cec5SDimitry Andric
37600b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
37610b57cec5SDimitry Andrictemplate <class _ForwardIterator>
3762cb14a3feSDimitry Andric_ForwardIterator basic_regex<_CharT, _Traits>::__parse_atom_escape(_ForwardIterator __first, _ForwardIterator __last) {
3763cb14a3feSDimitry Andric  if (__first != __last && *__first == '\\') {
37645f757f3fSDimitry Andric    _ForwardIterator __t1 = std::next(__first);
37650b57cec5SDimitry Andric    if (__t1 == __last)
37660b57cec5SDimitry Andric      __throw_regex_error<regex_constants::error_escape>();
37670b57cec5SDimitry Andric
37680b57cec5SDimitry Andric    _ForwardIterator __t2 = __parse_decimal_escape(__t1, __last);
37690b57cec5SDimitry Andric    if (__t2 != __t1)
37700b57cec5SDimitry Andric      __first = __t2;
3771cb14a3feSDimitry Andric    else {
37720b57cec5SDimitry Andric      __t2 = __parse_character_class_escape(__t1, __last);
37730b57cec5SDimitry Andric      if (__t2 != __t1)
37740b57cec5SDimitry Andric        __first = __t2;
3775cb14a3feSDimitry Andric      else {
37760b57cec5SDimitry Andric        __t2 = __parse_character_escape(__t1, __last);
37770b57cec5SDimitry Andric        if (__t2 != __t1)
37780b57cec5SDimitry Andric          __first = __t2;
37790b57cec5SDimitry Andric      }
37800b57cec5SDimitry Andric    }
37810b57cec5SDimitry Andric  }
37820b57cec5SDimitry Andric  return __first;
37830b57cec5SDimitry Andric}
37840b57cec5SDimitry Andric
37850b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
37860b57cec5SDimitry Andrictemplate <class _ForwardIterator>
37870b57cec5SDimitry Andric_ForwardIterator
3788cb14a3feSDimitry Andricbasic_regex<_CharT, _Traits>::__parse_decimal_escape(_ForwardIterator __first, _ForwardIterator __last) {
3789cb14a3feSDimitry Andric  if (__first != __last) {
3790cb14a3feSDimitry Andric    if (*__first == '0') {
37910b57cec5SDimitry Andric      __push_char(_CharT());
37920b57cec5SDimitry Andric      ++__first;
3793cb14a3feSDimitry Andric    } else if ('1' <= *__first && *__first <= '9') {
37940b57cec5SDimitry Andric      unsigned __v = *__first - '0';
3795cb14a3feSDimitry Andric      for (++__first; __first != __last && '0' <= *__first && *__first <= '9'; ++__first) {
3796e8d8bef9SDimitry Andric        if (__v >= numeric_limits<unsigned>::max() / 10)
37970b57cec5SDimitry Andric          __throw_regex_error<regex_constants::error_backref>();
37980b57cec5SDimitry Andric        __v = 10 * __v + *__first - '0';
37990b57cec5SDimitry Andric      }
38000b57cec5SDimitry Andric      if (__v == 0 || __v > mark_count())
38010b57cec5SDimitry Andric        __throw_regex_error<regex_constants::error_backref>();
38020b57cec5SDimitry Andric      __push_back_ref(__v);
38030b57cec5SDimitry Andric    }
38040b57cec5SDimitry Andric  }
38050b57cec5SDimitry Andric  return __first;
38060b57cec5SDimitry Andric}
38070b57cec5SDimitry Andric
38080b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
38090b57cec5SDimitry Andrictemplate <class _ForwardIterator>
38100b57cec5SDimitry Andric_ForwardIterator
3811cb14a3feSDimitry Andricbasic_regex<_CharT, _Traits>::__parse_character_class_escape(_ForwardIterator __first, _ForwardIterator __last) {
3812cb14a3feSDimitry Andric  if (__first != __last) {
38130b57cec5SDimitry Andric    __bracket_expression<_CharT, _Traits>* __ml;
3814cb14a3feSDimitry Andric    switch (*__first) {
38150b57cec5SDimitry Andric    case 'd':
38160b57cec5SDimitry Andric      __ml = __start_matching_list(false);
38170b57cec5SDimitry Andric      __ml->__add_class(ctype_base::digit);
38180b57cec5SDimitry Andric      ++__first;
38190b57cec5SDimitry Andric      break;
38200b57cec5SDimitry Andric    case 'D':
38210b57cec5SDimitry Andric      __ml = __start_matching_list(true);
38220b57cec5SDimitry Andric      __ml->__add_class(ctype_base::digit);
38230b57cec5SDimitry Andric      ++__first;
38240b57cec5SDimitry Andric      break;
38250b57cec5SDimitry Andric    case 's':
38260b57cec5SDimitry Andric      __ml = __start_matching_list(false);
38270b57cec5SDimitry Andric      __ml->__add_class(ctype_base::space);
38280b57cec5SDimitry Andric      ++__first;
38290b57cec5SDimitry Andric      break;
38300b57cec5SDimitry Andric    case 'S':
38310b57cec5SDimitry Andric      __ml = __start_matching_list(true);
38320b57cec5SDimitry Andric      __ml->__add_class(ctype_base::space);
38330b57cec5SDimitry Andric      ++__first;
38340b57cec5SDimitry Andric      break;
38350b57cec5SDimitry Andric    case 'w':
38360b57cec5SDimitry Andric      __ml = __start_matching_list(false);
38370b57cec5SDimitry Andric      __ml->__add_class(ctype_base::alnum);
38380b57cec5SDimitry Andric      __ml->__add_char('_');
38390b57cec5SDimitry Andric      ++__first;
38400b57cec5SDimitry Andric      break;
38410b57cec5SDimitry Andric    case 'W':
38420b57cec5SDimitry Andric      __ml = __start_matching_list(true);
38430b57cec5SDimitry Andric      __ml->__add_class(ctype_base::alnum);
38440b57cec5SDimitry Andric      __ml->__add_char('_');
38450b57cec5SDimitry Andric      ++__first;
38460b57cec5SDimitry Andric      break;
38470b57cec5SDimitry Andric    }
38480b57cec5SDimitry Andric  }
38490b57cec5SDimitry Andric  return __first;
38500b57cec5SDimitry Andric}
38510b57cec5SDimitry Andric
38520b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
38530b57cec5SDimitry Andrictemplate <class _ForwardIterator>
3854cb14a3feSDimitry Andric_ForwardIterator basic_regex<_CharT, _Traits>::__parse_character_escape(
3855cb14a3feSDimitry Andric    _ForwardIterator __first, _ForwardIterator __last, basic_string<_CharT>* __str) {
3856cb14a3feSDimitry Andric  if (__first != __last) {
38570b57cec5SDimitry Andric    _ForwardIterator __t;
38580b57cec5SDimitry Andric    unsigned __sum = 0;
38590b57cec5SDimitry Andric    int __hd;
3860cb14a3feSDimitry Andric    switch (*__first) {
38610b57cec5SDimitry Andric    case 'f':
38620b57cec5SDimitry Andric      if (__str)
38630b57cec5SDimitry Andric        *__str = _CharT(0xC);
38640b57cec5SDimitry Andric      else
38650b57cec5SDimitry Andric        __push_char(_CharT(0xC));
38660b57cec5SDimitry Andric      ++__first;
38670b57cec5SDimitry Andric      break;
38680b57cec5SDimitry Andric    case 'n':
38690b57cec5SDimitry Andric      if (__str)
38700b57cec5SDimitry Andric        *__str = _CharT(0xA);
38710b57cec5SDimitry Andric      else
38720b57cec5SDimitry Andric        __push_char(_CharT(0xA));
38730b57cec5SDimitry Andric      ++__first;
38740b57cec5SDimitry Andric      break;
38750b57cec5SDimitry Andric    case 'r':
38760b57cec5SDimitry Andric      if (__str)
38770b57cec5SDimitry Andric        *__str = _CharT(0xD);
38780b57cec5SDimitry Andric      else
38790b57cec5SDimitry Andric        __push_char(_CharT(0xD));
38800b57cec5SDimitry Andric      ++__first;
38810b57cec5SDimitry Andric      break;
38820b57cec5SDimitry Andric    case 't':
38830b57cec5SDimitry Andric      if (__str)
38840b57cec5SDimitry Andric        *__str = _CharT(0x9);
38850b57cec5SDimitry Andric      else
38860b57cec5SDimitry Andric        __push_char(_CharT(0x9));
38870b57cec5SDimitry Andric      ++__first;
38880b57cec5SDimitry Andric      break;
38890b57cec5SDimitry Andric    case 'v':
38900b57cec5SDimitry Andric      if (__str)
38910b57cec5SDimitry Andric        *__str = _CharT(0xB);
38920b57cec5SDimitry Andric      else
38930b57cec5SDimitry Andric        __push_char(_CharT(0xB));
38940b57cec5SDimitry Andric      ++__first;
38950b57cec5SDimitry Andric      break;
38960b57cec5SDimitry Andric    case 'c':
3897cb14a3feSDimitry Andric      if ((__t = std::next(__first)) != __last) {
3898cb14a3feSDimitry Andric        if (('A' <= *__t && *__t <= 'Z') || ('a' <= *__t && *__t <= 'z')) {
38990b57cec5SDimitry Andric          if (__str)
39000b57cec5SDimitry Andric            *__str = _CharT(*__t % 32);
39010b57cec5SDimitry Andric          else
39020b57cec5SDimitry Andric            __push_char(_CharT(*__t % 32));
39030b57cec5SDimitry Andric          __first = ++__t;
3904cb14a3feSDimitry Andric        } else
39050b57cec5SDimitry Andric          __throw_regex_error<regex_constants::error_escape>();
3906cb14a3feSDimitry Andric      } else
39070b57cec5SDimitry Andric        __throw_regex_error<regex_constants::error_escape>();
39080b57cec5SDimitry Andric      break;
39090b57cec5SDimitry Andric    case 'u':
39100b57cec5SDimitry Andric      ++__first;
39110b57cec5SDimitry Andric      if (__first == __last)
39120b57cec5SDimitry Andric        __throw_regex_error<regex_constants::error_escape>();
39130b57cec5SDimitry Andric      __hd = __traits_.value(*__first, 16);
39140b57cec5SDimitry Andric      if (__hd == -1)
39150b57cec5SDimitry Andric        __throw_regex_error<regex_constants::error_escape>();
39160b57cec5SDimitry Andric      __sum = 16 * __sum + static_cast<unsigned>(__hd);
39170b57cec5SDimitry Andric      ++__first;
39180b57cec5SDimitry Andric      if (__first == __last)
39190b57cec5SDimitry Andric        __throw_regex_error<regex_constants::error_escape>();
39200b57cec5SDimitry Andric      __hd = __traits_.value(*__first, 16);
39210b57cec5SDimitry Andric      if (__hd == -1)
39220b57cec5SDimitry Andric        __throw_regex_error<regex_constants::error_escape>();
39230b57cec5SDimitry Andric      __sum = 16 * __sum + static_cast<unsigned>(__hd);
3924fe6060f1SDimitry Andric      // fallthrough
39250b57cec5SDimitry Andric    case 'x':
39260b57cec5SDimitry Andric      ++__first;
39270b57cec5SDimitry Andric      if (__first == __last)
39280b57cec5SDimitry Andric        __throw_regex_error<regex_constants::error_escape>();
39290b57cec5SDimitry Andric      __hd = __traits_.value(*__first, 16);
39300b57cec5SDimitry Andric      if (__hd == -1)
39310b57cec5SDimitry Andric        __throw_regex_error<regex_constants::error_escape>();
39320b57cec5SDimitry Andric      __sum = 16 * __sum + static_cast<unsigned>(__hd);
39330b57cec5SDimitry Andric      ++__first;
39340b57cec5SDimitry Andric      if (__first == __last)
39350b57cec5SDimitry Andric        __throw_regex_error<regex_constants::error_escape>();
39360b57cec5SDimitry Andric      __hd = __traits_.value(*__first, 16);
39370b57cec5SDimitry Andric      if (__hd == -1)
39380b57cec5SDimitry Andric        __throw_regex_error<regex_constants::error_escape>();
39390b57cec5SDimitry Andric      __sum = 16 * __sum + static_cast<unsigned>(__hd);
39400b57cec5SDimitry Andric      if (__str)
39410b57cec5SDimitry Andric        *__str = _CharT(__sum);
39420b57cec5SDimitry Andric      else
39430b57cec5SDimitry Andric        __push_char(_CharT(__sum));
39440b57cec5SDimitry Andric      ++__first;
39450b57cec5SDimitry Andric      break;
39460b57cec5SDimitry Andric    case '0':
39470b57cec5SDimitry Andric      if (__str)
39480b57cec5SDimitry Andric        *__str = _CharT(0);
39490b57cec5SDimitry Andric      else
39500b57cec5SDimitry Andric        __push_char(_CharT(0));
39510b57cec5SDimitry Andric      ++__first;
39520b57cec5SDimitry Andric      break;
39530b57cec5SDimitry Andric    default:
3954cb14a3feSDimitry Andric      if (*__first != '_' && !__traits_.isctype(*__first, ctype_base::alnum)) {
39550b57cec5SDimitry Andric        if (__str)
39560b57cec5SDimitry Andric          *__str = *__first;
39570b57cec5SDimitry Andric        else
39580b57cec5SDimitry Andric          __push_char(*__first);
39590b57cec5SDimitry Andric        ++__first;
3960cb14a3feSDimitry Andric      } else
39610b57cec5SDimitry Andric        __throw_regex_error<regex_constants::error_escape>();
39620b57cec5SDimitry Andric      break;
39630b57cec5SDimitry Andric    }
39640b57cec5SDimitry Andric  }
39650b57cec5SDimitry Andric  return __first;
39660b57cec5SDimitry Andric}
39670b57cec5SDimitry Andric
39680b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
39690b57cec5SDimitry Andrictemplate <class _ForwardIterator>
39700b57cec5SDimitry Andric_ForwardIterator
3971cb14a3feSDimitry Andricbasic_regex<_CharT, _Traits>::__parse_pattern_character(_ForwardIterator __first, _ForwardIterator __last) {
3972cb14a3feSDimitry Andric  if (__first != __last) {
3973cb14a3feSDimitry Andric    switch (*__first) {
39740b57cec5SDimitry Andric    case '^':
39750b57cec5SDimitry Andric    case '$':
39760b57cec5SDimitry Andric    case '\\':
39770b57cec5SDimitry Andric    case '.':
39780b57cec5SDimitry Andric    case '*':
39790b57cec5SDimitry Andric    case '+':
39800b57cec5SDimitry Andric    case '?':
39810b57cec5SDimitry Andric    case '(':
39820b57cec5SDimitry Andric    case ')':
39830b57cec5SDimitry Andric    case '[':
39840b57cec5SDimitry Andric    case ']':
39850b57cec5SDimitry Andric    case '{':
39860b57cec5SDimitry Andric    case '}':
39870b57cec5SDimitry Andric    case '|':
39880b57cec5SDimitry Andric      break;
39890b57cec5SDimitry Andric    default:
39900b57cec5SDimitry Andric      __push_char(*__first);
39910b57cec5SDimitry Andric      ++__first;
39920b57cec5SDimitry Andric      break;
39930b57cec5SDimitry Andric    }
39940b57cec5SDimitry Andric  }
39950b57cec5SDimitry Andric  return __first;
39960b57cec5SDimitry Andric}
39970b57cec5SDimitry Andric
39980b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
39990b57cec5SDimitry Andrictemplate <class _ForwardIterator>
4000cb14a3feSDimitry Andric_ForwardIterator basic_regex<_CharT, _Traits>::__parse_grep(_ForwardIterator __first, _ForwardIterator __last) {
40010b57cec5SDimitry Andric  __owns_one_state<_CharT>* __sa = __end_;
40025f757f3fSDimitry Andric  _ForwardIterator __t1          = std::find(__first, __last, _CharT('\n'));
40030b57cec5SDimitry Andric  if (__t1 != __first)
40040b57cec5SDimitry Andric    __parse_basic_reg_exp(__first, __t1);
40050b57cec5SDimitry Andric  else
40060b57cec5SDimitry Andric    __push_empty();
40070b57cec5SDimitry Andric  __first = __t1;
40080b57cec5SDimitry Andric  if (__first != __last)
40090b57cec5SDimitry Andric    ++__first;
4010cb14a3feSDimitry Andric  while (__first != __last) {
40115f757f3fSDimitry Andric    __t1                           = std::find(__first, __last, _CharT('\n'));
40120b57cec5SDimitry Andric    __owns_one_state<_CharT>* __sb = __end_;
40130b57cec5SDimitry Andric    if (__t1 != __first)
40140b57cec5SDimitry Andric      __parse_basic_reg_exp(__first, __t1);
40150b57cec5SDimitry Andric    else
40160b57cec5SDimitry Andric      __push_empty();
40170b57cec5SDimitry Andric    __push_alternation(__sa, __sb);
40180b57cec5SDimitry Andric    __first = __t1;
40190b57cec5SDimitry Andric    if (__first != __last)
40200b57cec5SDimitry Andric      ++__first;
40210b57cec5SDimitry Andric  }
40220b57cec5SDimitry Andric  return __first;
40230b57cec5SDimitry Andric}
40240b57cec5SDimitry Andric
40250b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
40260b57cec5SDimitry Andrictemplate <class _ForwardIterator>
4027cb14a3feSDimitry Andric_ForwardIterator basic_regex<_CharT, _Traits>::__parse_egrep(_ForwardIterator __first, _ForwardIterator __last) {
40280b57cec5SDimitry Andric  __owns_one_state<_CharT>* __sa = __end_;
40295f757f3fSDimitry Andric  _ForwardIterator __t1          = std::find(__first, __last, _CharT('\n'));
40300b57cec5SDimitry Andric  if (__t1 != __first)
40310b57cec5SDimitry Andric    __parse_extended_reg_exp(__first, __t1);
40320b57cec5SDimitry Andric  else
40330b57cec5SDimitry Andric    __push_empty();
40340b57cec5SDimitry Andric  __first = __t1;
40350b57cec5SDimitry Andric  if (__first != __last)
40360b57cec5SDimitry Andric    ++__first;
4037cb14a3feSDimitry Andric  while (__first != __last) {
40385f757f3fSDimitry Andric    __t1                           = std::find(__first, __last, _CharT('\n'));
40390b57cec5SDimitry Andric    __owns_one_state<_CharT>* __sb = __end_;
40400b57cec5SDimitry Andric    if (__t1 != __first)
40410b57cec5SDimitry Andric      __parse_extended_reg_exp(__first, __t1);
40420b57cec5SDimitry Andric    else
40430b57cec5SDimitry Andric      __push_empty();
40440b57cec5SDimitry Andric    __push_alternation(__sa, __sb);
40450b57cec5SDimitry Andric    __first = __t1;
40460b57cec5SDimitry Andric    if (__first != __last)
40470b57cec5SDimitry Andric      ++__first;
40480b57cec5SDimitry Andric  }
40490b57cec5SDimitry Andric  return __first;
40500b57cec5SDimitry Andric}
40510b57cec5SDimitry Andric
40520b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
4053cb14a3feSDimitry Andricbool basic_regex<_CharT, _Traits>::__test_back_ref(_CharT __c) {
4054753f127fSDimitry Andric  unsigned __val = __traits_.value(__c, 10);
4055cb14a3feSDimitry Andric  if (__val >= 1 && __val <= 9) {
40565ffd83dbSDimitry Andric    if (__val > mark_count())
40575ffd83dbSDimitry Andric      __throw_regex_error<regex_constants::error_backref>();
40585ffd83dbSDimitry Andric    __push_back_ref(__val);
40595ffd83dbSDimitry Andric    return true;
40605ffd83dbSDimitry Andric  }
40615ffd83dbSDimitry Andric
40625ffd83dbSDimitry Andric  return false;
40635ffd83dbSDimitry Andric}
40645ffd83dbSDimitry Andric
40655ffd83dbSDimitry Andrictemplate <class _CharT, class _Traits>
4066cb14a3feSDimitry Andricvoid basic_regex<_CharT, _Traits>::__push_loop(
4067cb14a3feSDimitry Andric    size_t __min, size_t __max, __owns_one_state<_CharT>* __s, size_t __mexp_begin, size_t __mexp_end, bool __greedy) {
40680b57cec5SDimitry Andric  unique_ptr<__empty_state<_CharT> > __e1(new __empty_state<_CharT>(__end_->first()));
40690b57cec5SDimitry Andric  __end_->first() = nullptr;
4070cb14a3feSDimitry Andric  unique_ptr<__loop<_CharT> > __e2(
4071cb14a3feSDimitry Andric      new __loop<_CharT>(__loop_count_, __s->first(), __e1.get(), __mexp_begin, __mexp_end, __greedy, __min, __max));
40720b57cec5SDimitry Andric  __s->first() = nullptr;
40730b57cec5SDimitry Andric  __e1.release();
40740b57cec5SDimitry Andric  __end_->first() = new __repeat_one_loop<_CharT>(__e2.get());
40750b57cec5SDimitry Andric  __end_          = __e2->second();
40760b57cec5SDimitry Andric  __s->first()    = __e2.release();
40770b57cec5SDimitry Andric  ++__loop_count_;
40780b57cec5SDimitry Andric}
40790b57cec5SDimitry Andric
40800b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
4081cb14a3feSDimitry Andricvoid basic_regex<_CharT, _Traits>::__push_char(value_type __c) {
40820b57cec5SDimitry Andric  if (flags() & icase)
4083cb14a3feSDimitry Andric    __end_->first() = new __match_char_icase<_CharT, _Traits>(__traits_, __c, __end_->first());
40840b57cec5SDimitry Andric  else if (flags() & collate)
4085cb14a3feSDimitry Andric    __end_->first() = new __match_char_collate<_CharT, _Traits>(__traits_, __c, __end_->first());
40860b57cec5SDimitry Andric  else
40870b57cec5SDimitry Andric    __end_->first() = new __match_char<_CharT>(__c, __end_->first());
40880b57cec5SDimitry Andric  __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
40890b57cec5SDimitry Andric}
40900b57cec5SDimitry Andric
40910b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
4092cb14a3feSDimitry Andricvoid basic_regex<_CharT, _Traits>::__push_begin_marked_subexpression() {
4093cb14a3feSDimitry Andric  if (!(__flags_ & nosubs)) {
4094cb14a3feSDimitry Andric    __end_->first() = new __begin_marked_subexpression<_CharT>(++__marked_count_, __end_->first());
40950b57cec5SDimitry Andric    __end_          = static_cast<__owns_one_state<_CharT>*>(__end_->first());
40960b57cec5SDimitry Andric  }
40970b57cec5SDimitry Andric}
40980b57cec5SDimitry Andric
40990b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
4100cb14a3feSDimitry Andricvoid basic_regex<_CharT, _Traits>::__push_end_marked_subexpression(unsigned __sub) {
4101cb14a3feSDimitry Andric  if (!(__flags_ & nosubs)) {
4102cb14a3feSDimitry Andric    __end_->first() = new __end_marked_subexpression<_CharT>(__sub, __end_->first());
41030b57cec5SDimitry Andric    __end_          = static_cast<__owns_one_state<_CharT>*>(__end_->first());
41040b57cec5SDimitry Andric  }
41050b57cec5SDimitry Andric}
41060b57cec5SDimitry Andric
41070b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
4108cb14a3feSDimitry Andricvoid basic_regex<_CharT, _Traits>::__push_l_anchor() {
4109e8d8bef9SDimitry Andric  __end_->first() = new __l_anchor_multiline<_CharT>(__use_multiline(), __end_->first());
41100b57cec5SDimitry Andric  __end_          = static_cast<__owns_one_state<_CharT>*>(__end_->first());
41110b57cec5SDimitry Andric}
41120b57cec5SDimitry Andric
41130b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
4114cb14a3feSDimitry Andricvoid basic_regex<_CharT, _Traits>::__push_r_anchor() {
4115e8d8bef9SDimitry Andric  __end_->first() = new __r_anchor_multiline<_CharT>(__use_multiline(), __end_->first());
41160b57cec5SDimitry Andric  __end_          = static_cast<__owns_one_state<_CharT>*>(__end_->first());
41170b57cec5SDimitry Andric}
41180b57cec5SDimitry Andric
41190b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
4120cb14a3feSDimitry Andricvoid basic_regex<_CharT, _Traits>::__push_match_any() {
41210b57cec5SDimitry Andric  __end_->first() = new __match_any<_CharT>(__end_->first());
41220b57cec5SDimitry Andric  __end_          = static_cast<__owns_one_state<_CharT>*>(__end_->first());
41230b57cec5SDimitry Andric}
41240b57cec5SDimitry Andric
41250b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
4126cb14a3feSDimitry Andricvoid basic_regex<_CharT, _Traits>::__push_match_any_but_newline() {
41270b57cec5SDimitry Andric  __end_->first() = new __match_any_but_newline<_CharT>(__end_->first());
41280b57cec5SDimitry Andric  __end_          = static_cast<__owns_one_state<_CharT>*>(__end_->first());
41290b57cec5SDimitry Andric}
41300b57cec5SDimitry Andric
41310b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
4132cb14a3feSDimitry Andricvoid basic_regex<_CharT, _Traits>::__push_empty() {
41330b57cec5SDimitry Andric  __end_->first() = new __empty_state<_CharT>(__end_->first());
41340b57cec5SDimitry Andric  __end_          = static_cast<__owns_one_state<_CharT>*>(__end_->first());
41350b57cec5SDimitry Andric}
41360b57cec5SDimitry Andric
41370b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
4138cb14a3feSDimitry Andricvoid basic_regex<_CharT, _Traits>::__push_word_boundary(bool __invert) {
4139cb14a3feSDimitry Andric  __end_->first() = new __word_boundary<_CharT, _Traits>(__traits_, __invert, __end_->first());
41400b57cec5SDimitry Andric  __end_          = static_cast<__owns_one_state<_CharT>*>(__end_->first());
41410b57cec5SDimitry Andric}
41420b57cec5SDimitry Andric
41430b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
4144cb14a3feSDimitry Andricvoid basic_regex<_CharT, _Traits>::__push_back_ref(int __i) {
41450b57cec5SDimitry Andric  if (flags() & icase)
4146cb14a3feSDimitry Andric    __end_->first() = new __back_ref_icase<_CharT, _Traits>(__traits_, __i, __end_->first());
41470b57cec5SDimitry Andric  else if (flags() & collate)
4148cb14a3feSDimitry Andric    __end_->first() = new __back_ref_collate<_CharT, _Traits>(__traits_, __i, __end_->first());
41490b57cec5SDimitry Andric  else
41500b57cec5SDimitry Andric    __end_->first() = new __back_ref<_CharT>(__i, __end_->first());
41510b57cec5SDimitry Andric  __end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
41520b57cec5SDimitry Andric}
41530b57cec5SDimitry Andric
41540b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
4155cb14a3feSDimitry Andricvoid basic_regex<_CharT, _Traits>::__push_alternation(__owns_one_state<_CharT>* __sa, __owns_one_state<_CharT>* __ea) {
41560b57cec5SDimitry Andric  __sa->first() = new __alternate<_CharT>(
4157cb14a3feSDimitry Andric      static_cast<__owns_one_state<_CharT>*>(__sa->first()), static_cast<__owns_one_state<_CharT>*>(__ea->first()));
41580b57cec5SDimitry Andric  __ea->first()   = nullptr;
41590b57cec5SDimitry Andric  __ea->first()   = new __empty_state<_CharT>(__end_->first());
41600b57cec5SDimitry Andric  __end_->first() = nullptr;
41610b57cec5SDimitry Andric  __end_->first() = new __empty_non_own_state<_CharT>(__ea->first());
41620b57cec5SDimitry Andric  __end_          = static_cast<__owns_one_state<_CharT>*>(__ea->first());
41630b57cec5SDimitry Andric}
41640b57cec5SDimitry Andric
41650b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
4166cb14a3feSDimitry Andric__bracket_expression<_CharT, _Traits>* basic_regex<_CharT, _Traits>::__start_matching_list(bool __negate) {
4167cb14a3feSDimitry Andric  __bracket_expression<_CharT, _Traits>* __r = new __bracket_expression<_CharT, _Traits>(
4168cb14a3feSDimitry Andric      __traits_, __end_->first(), __negate, __flags_ & icase, __flags_ & collate);
41690b57cec5SDimitry Andric  __end_->first() = __r;
41700b57cec5SDimitry Andric  __end_          = __r;
41710b57cec5SDimitry Andric  return __r;
41720b57cec5SDimitry Andric}
41730b57cec5SDimitry Andric
41740b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
4175cb14a3feSDimitry Andricvoid basic_regex<_CharT, _Traits>::__push_lookahead(const basic_regex& __exp, bool __invert, unsigned __mexp) {
4176cb14a3feSDimitry Andric  __end_->first() = new __lookahead<_CharT, _Traits>(__exp, __invert, __end_->first(), __mexp);
41770b57cec5SDimitry Andric  __end_          = static_cast<__owns_one_state<_CharT>*>(__end_->first());
41780b57cec5SDimitry Andric}
41790b57cec5SDimitry Andric
41800b57cec5SDimitry Andric// sub_match
41810b57cec5SDimitry Andric
4182e8d8bef9SDimitry Andrictypedef sub_match<const char*> csub_match;
4183e8d8bef9SDimitry Andrictypedef sub_match<string::const_iterator> ssub_match;
4184349cc55cSDimitry Andric#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
4185349cc55cSDimitry Andrictypedef sub_match<const wchar_t*> wcsub_match;
4186e8d8bef9SDimitry Andrictypedef sub_match<wstring::const_iterator> wssub_match;
4187349cc55cSDimitry Andric#endif
4188e8d8bef9SDimitry Andric
41890b57cec5SDimitry Andrictemplate <class _BidirectionalIterator>
4190cb14a3feSDimitry Andricclass _LIBCPP_TEMPLATE_VIS _LIBCPP_PREFERRED_NAME(csub_match)
4191cb14a3feSDimitry Andric    _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wcsub_match)) _LIBCPP_PREFERRED_NAME(ssub_match)
4192cb14a3feSDimitry Andric        _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wssub_match)) sub_match
4193cb14a3feSDimitry Andric    : public pair<_BidirectionalIterator, _BidirectionalIterator> {
41940b57cec5SDimitry Andricpublic:
41950b57cec5SDimitry Andric  typedef _BidirectionalIterator iterator;
41960b57cec5SDimitry Andric  typedef typename iterator_traits<iterator>::value_type value_type;
41970b57cec5SDimitry Andric  typedef typename iterator_traits<iterator>::difference_type difference_type;
41980b57cec5SDimitry Andric  typedef basic_string<value_type> string_type;
41990b57cec5SDimitry Andric
42000b57cec5SDimitry Andric  bool matched;
42010b57cec5SDimitry Andric
4202cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR sub_match() : matched() {}
42030b57cec5SDimitry Andric
4204cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI difference_type length() const {
4205cb14a3feSDimitry Andric    return matched ? std::distance(this->first, this->second) : 0;
4206cb14a3feSDimitry Andric  }
4207cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI string_type str() const {
4208cb14a3feSDimitry Andric    return matched ? string_type(this->first, this->second) : string_type();
4209cb14a3feSDimitry Andric  }
4210cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI operator string_type() const { return str(); }
42110b57cec5SDimitry Andric
4212cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI int compare(const sub_match& __s) const { return str().compare(__s.str()); }
4213cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI int compare(const string_type& __s) const { return str().compare(__s); }
4214cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI int compare(const value_type* __s) const { return str().compare(__s); }
421506c3fb27SDimitry Andric
4216*0fca6ea1SDimitry Andric  _LIBCPP_HIDE_FROM_ABI void swap(sub_match& __s) _NOEXCEPT_(__is_nothrow_swappable_v<_BidirectionalIterator>) {
421706c3fb27SDimitry Andric    this->pair<_BidirectionalIterator, _BidirectionalIterator>::swap(__s);
421806c3fb27SDimitry Andric    std::swap(matched, __s.matched);
421906c3fb27SDimitry Andric  }
42200b57cec5SDimitry Andric};
42210b57cec5SDimitry Andric
42220b57cec5SDimitry Andrictemplate <class _BiIter>
4223cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool operator==(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) {
42240b57cec5SDimitry Andric  return __x.compare(__y) == 0;
42250b57cec5SDimitry Andric}
42260b57cec5SDimitry Andric
422706c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 20
422806c3fb27SDimitry Andrictemplate <class _BiIter>
422906c3fb27SDimitry Andricusing __sub_match_cat = compare_three_way_result_t<basic_string<typename iterator_traits<_BiIter>::value_type>>;
423006c3fb27SDimitry Andric
423106c3fb27SDimitry Andrictemplate <class _BiIter>
423206c3fb27SDimitry Andric_LIBCPP_HIDE_FROM_ABI auto operator<=>(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) {
423306c3fb27SDimitry Andric  return static_cast<__sub_match_cat<_BiIter>>(__x.compare(__y) <=> 0);
423406c3fb27SDimitry Andric}
423506c3fb27SDimitry Andric#else  // _LIBCPP_STD_VER >= 20
42360b57cec5SDimitry Andrictemplate <class _BiIter>
4237cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool operator!=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) {
42380b57cec5SDimitry Andric  return !(__x == __y);
42390b57cec5SDimitry Andric}
42400b57cec5SDimitry Andric
42410b57cec5SDimitry Andrictemplate <class _BiIter>
4242cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool operator<(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) {
42430b57cec5SDimitry Andric  return __x.compare(__y) < 0;
42440b57cec5SDimitry Andric}
42450b57cec5SDimitry Andric
42460b57cec5SDimitry Andrictemplate <class _BiIter>
4247cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool operator<=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) {
42480b57cec5SDimitry Andric  return !(__y < __x);
42490b57cec5SDimitry Andric}
42500b57cec5SDimitry Andric
42510b57cec5SDimitry Andrictemplate <class _BiIter>
4252cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool operator>=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) {
42530b57cec5SDimitry Andric  return !(__x < __y);
42540b57cec5SDimitry Andric}
42550b57cec5SDimitry Andric
42560b57cec5SDimitry Andrictemplate <class _BiIter>
4257cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool operator>(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y) {
42580b57cec5SDimitry Andric  return __y < __x;
42590b57cec5SDimitry Andric}
42600b57cec5SDimitry Andric
42610b57cec5SDimitry Andrictemplate <class _BiIter, class _ST, class _SA>
4262cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool
42630b57cec5SDimitry Andricoperator==(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
4264cb14a3feSDimitry Andric           const sub_match<_BiIter>& __y) {
42650b57cec5SDimitry Andric  return __y.compare(typename sub_match<_BiIter>::string_type(__x.data(), __x.size())) == 0;
42660b57cec5SDimitry Andric}
42670b57cec5SDimitry Andric
42680b57cec5SDimitry Andrictemplate <class _BiIter, class _ST, class _SA>
4269cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool
42700b57cec5SDimitry Andricoperator!=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
4271cb14a3feSDimitry Andric           const sub_match<_BiIter>& __y) {
42720b57cec5SDimitry Andric  return !(__x == __y);
42730b57cec5SDimitry Andric}
42740b57cec5SDimitry Andric
42750b57cec5SDimitry Andrictemplate <class _BiIter, class _ST, class _SA>
4276cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool
42770b57cec5SDimitry Andricoperator<(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
4278cb14a3feSDimitry Andric          const sub_match<_BiIter>& __y) {
42790b57cec5SDimitry Andric  return __y.compare(typename sub_match<_BiIter>::string_type(__x.data(), __x.size())) > 0;
42800b57cec5SDimitry Andric}
42810b57cec5SDimitry Andric
42820b57cec5SDimitry Andrictemplate <class _BiIter, class _ST, class _SA>
4283cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool
42840b57cec5SDimitry Andricoperator>(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
4285cb14a3feSDimitry Andric          const sub_match<_BiIter>& __y) {
42860b57cec5SDimitry Andric  return __y < __x;
42870b57cec5SDimitry Andric}
42880b57cec5SDimitry Andric
42890b57cec5SDimitry Andrictemplate <class _BiIter, class _ST, class _SA>
4290cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool
4291cb14a3feSDimitry Andricoperator>=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
4292cb14a3feSDimitry Andric           const sub_match<_BiIter>& __y) {
42930b57cec5SDimitry Andric  return !(__x < __y);
42940b57cec5SDimitry Andric}
42950b57cec5SDimitry Andric
42960b57cec5SDimitry Andrictemplate <class _BiIter, class _ST, class _SA>
4297cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool
42980b57cec5SDimitry Andricoperator<=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
4299cb14a3feSDimitry Andric           const sub_match<_BiIter>& __y) {
43000b57cec5SDimitry Andric  return !(__y < __x);
43010b57cec5SDimitry Andric}
430206c3fb27SDimitry Andric#endif // _LIBCPP_STD_VER >= 20
43030b57cec5SDimitry Andric
43040b57cec5SDimitry Andrictemplate <class _BiIter, class _ST, class _SA>
4305cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool
43060b57cec5SDimitry Andricoperator==(const sub_match<_BiIter>& __x,
4307cb14a3feSDimitry Andric           const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) {
43080b57cec5SDimitry Andric  return __x.compare(typename sub_match<_BiIter>::string_type(__y.data(), __y.size())) == 0;
43090b57cec5SDimitry Andric}
43100b57cec5SDimitry Andric
431106c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 20
431206c3fb27SDimitry Andrictemplate <class _BiIter, class _ST, class _SA>
4313cb14a3feSDimitry Andric_LIBCPP_HIDE_FROM_ABI auto
4314cb14a3feSDimitry Andricoperator<=>(const sub_match<_BiIter>& __x,
4315cb14a3feSDimitry Andric            const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) {
431606c3fb27SDimitry Andric  return static_cast<__sub_match_cat<_BiIter>>(
431706c3fb27SDimitry Andric      __x.compare(typename sub_match<_BiIter>::string_type(__y.data(), __y.size())) <=> 0);
431806c3fb27SDimitry Andric}
431906c3fb27SDimitry Andric#else  // _LIBCPP_STD_VER >= 20
43200b57cec5SDimitry Andrictemplate <class _BiIter, class _ST, class _SA>
4321cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool
43220b57cec5SDimitry Andricoperator!=(const sub_match<_BiIter>& __x,
4323cb14a3feSDimitry Andric           const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) {
43240b57cec5SDimitry Andric  return !(__x == __y);
43250b57cec5SDimitry Andric}
43260b57cec5SDimitry Andric
43270b57cec5SDimitry Andrictemplate <class _BiIter, class _ST, class _SA>
4328cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool
43290b57cec5SDimitry Andricoperator<(const sub_match<_BiIter>& __x,
4330cb14a3feSDimitry Andric          const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) {
43310b57cec5SDimitry Andric  return __x.compare(typename sub_match<_BiIter>::string_type(__y.data(), __y.size())) < 0;
43320b57cec5SDimitry Andric}
43330b57cec5SDimitry Andric
43340b57cec5SDimitry Andrictemplate <class _BiIter, class _ST, class _SA>
4335cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool
4336cb14a3feSDimitry Andricoperator>(const sub_match<_BiIter>& __x,
4337cb14a3feSDimitry Andric          const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) {
43380b57cec5SDimitry Andric  return __y < __x;
43390b57cec5SDimitry Andric}
43400b57cec5SDimitry Andric
43410b57cec5SDimitry Andrictemplate <class _BiIter, class _ST, class _SA>
4342cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool
43430b57cec5SDimitry Andricoperator>=(const sub_match<_BiIter>& __x,
4344cb14a3feSDimitry Andric           const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) {
43450b57cec5SDimitry Andric  return !(__x < __y);
43460b57cec5SDimitry Andric}
43470b57cec5SDimitry Andric
43480b57cec5SDimitry Andrictemplate <class _BiIter, class _ST, class _SA>
4349cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool
43500b57cec5SDimitry Andricoperator<=(const sub_match<_BiIter>& __x,
4351cb14a3feSDimitry Andric           const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y) {
43520b57cec5SDimitry Andric  return !(__y < __x);
43530b57cec5SDimitry Andric}
43540b57cec5SDimitry Andric
43550b57cec5SDimitry Andrictemplate <class _BiIter>
4356cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool
4357cb14a3feSDimitry Andricoperator==(typename iterator_traits<_BiIter>::value_type const* __x, const sub_match<_BiIter>& __y) {
43580b57cec5SDimitry Andric  return __y.compare(__x) == 0;
43590b57cec5SDimitry Andric}
43600b57cec5SDimitry Andric
43610b57cec5SDimitry Andrictemplate <class _BiIter>
4362cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool
4363cb14a3feSDimitry Andricoperator!=(typename iterator_traits<_BiIter>::value_type const* __x, const sub_match<_BiIter>& __y) {
43640b57cec5SDimitry Andric  return !(__x == __y);
43650b57cec5SDimitry Andric}
43660b57cec5SDimitry Andric
43670b57cec5SDimitry Andrictemplate <class _BiIter>
4368cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool
4369cb14a3feSDimitry Andricoperator<(typename iterator_traits<_BiIter>::value_type const* __x, const sub_match<_BiIter>& __y) {
43700b57cec5SDimitry Andric  return __y.compare(__x) > 0;
43710b57cec5SDimitry Andric}
43720b57cec5SDimitry Andric
43730b57cec5SDimitry Andrictemplate <class _BiIter>
4374cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool
4375cb14a3feSDimitry Andricoperator>(typename iterator_traits<_BiIter>::value_type const* __x, const sub_match<_BiIter>& __y) {
43760b57cec5SDimitry Andric  return __y < __x;
43770b57cec5SDimitry Andric}
43780b57cec5SDimitry Andric
43790b57cec5SDimitry Andrictemplate <class _BiIter>
4380cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool
4381cb14a3feSDimitry Andricoperator>=(typename iterator_traits<_BiIter>::value_type const* __x, const sub_match<_BiIter>& __y) {
43820b57cec5SDimitry Andric  return !(__x < __y);
43830b57cec5SDimitry Andric}
43840b57cec5SDimitry Andric
43850b57cec5SDimitry Andrictemplate <class _BiIter>
4386cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool
4387cb14a3feSDimitry Andricoperator<=(typename iterator_traits<_BiIter>::value_type const* __x, const sub_match<_BiIter>& __y) {
43880b57cec5SDimitry Andric  return !(__y < __x);
43890b57cec5SDimitry Andric}
439006c3fb27SDimitry Andric#endif // _LIBCPP_STD_VER >= 20
43910b57cec5SDimitry Andric
43920b57cec5SDimitry Andrictemplate <class _BiIter>
4393cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool
4394cb14a3feSDimitry Andricoperator==(const sub_match<_BiIter>& __x, typename iterator_traits<_BiIter>::value_type const* __y) {
43950b57cec5SDimitry Andric  return __x.compare(__y) == 0;
43960b57cec5SDimitry Andric}
43970b57cec5SDimitry Andric
439806c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 20
439906c3fb27SDimitry Andrictemplate <class _BiIter>
440006c3fb27SDimitry Andric_LIBCPP_HIDE_FROM_ABI auto
440106c3fb27SDimitry Andricoperator<=>(const sub_match<_BiIter>& __x, typename iterator_traits<_BiIter>::value_type const* __y) {
440206c3fb27SDimitry Andric  return static_cast<__sub_match_cat<_BiIter>>(__x.compare(__y) <=> 0);
440306c3fb27SDimitry Andric}
440406c3fb27SDimitry Andric#else  // _LIBCPP_STD_VER >= 20
44050b57cec5SDimitry Andrictemplate <class _BiIter>
4406cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool
4407cb14a3feSDimitry Andricoperator!=(const sub_match<_BiIter>& __x, typename iterator_traits<_BiIter>::value_type const* __y) {
44080b57cec5SDimitry Andric  return !(__x == __y);
44090b57cec5SDimitry Andric}
44100b57cec5SDimitry Andric
44110b57cec5SDimitry Andrictemplate <class _BiIter>
4412cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool
4413cb14a3feSDimitry Andricoperator<(const sub_match<_BiIter>& __x, typename iterator_traits<_BiIter>::value_type const* __y) {
44140b57cec5SDimitry Andric  return __x.compare(__y) < 0;
44150b57cec5SDimitry Andric}
44160b57cec5SDimitry Andric
44170b57cec5SDimitry Andrictemplate <class _BiIter>
4418cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool
4419cb14a3feSDimitry Andricoperator>(const sub_match<_BiIter>& __x, typename iterator_traits<_BiIter>::value_type const* __y) {
44200b57cec5SDimitry Andric  return __y < __x;
44210b57cec5SDimitry Andric}
44220b57cec5SDimitry Andric
44230b57cec5SDimitry Andrictemplate <class _BiIter>
4424cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool
4425cb14a3feSDimitry Andricoperator>=(const sub_match<_BiIter>& __x, typename iterator_traits<_BiIter>::value_type const* __y) {
44260b57cec5SDimitry Andric  return !(__x < __y);
44270b57cec5SDimitry Andric}
44280b57cec5SDimitry Andric
44290b57cec5SDimitry Andrictemplate <class _BiIter>
4430cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool
4431cb14a3feSDimitry Andricoperator<=(const sub_match<_BiIter>& __x, typename iterator_traits<_BiIter>::value_type const* __y) {
44320b57cec5SDimitry Andric  return !(__y < __x);
44330b57cec5SDimitry Andric}
44340b57cec5SDimitry Andric
44350b57cec5SDimitry Andrictemplate <class _BiIter>
4436cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool
4437cb14a3feSDimitry Andricoperator==(typename iterator_traits<_BiIter>::value_type const& __x, const sub_match<_BiIter>& __y) {
44380b57cec5SDimitry Andric  typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type;
44390b57cec5SDimitry Andric  return __y.compare(string_type(1, __x)) == 0;
44400b57cec5SDimitry Andric}
44410b57cec5SDimitry Andric
44420b57cec5SDimitry Andrictemplate <class _BiIter>
4443cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool
4444cb14a3feSDimitry Andricoperator!=(typename iterator_traits<_BiIter>::value_type const& __x, const sub_match<_BiIter>& __y) {
44450b57cec5SDimitry Andric  return !(__x == __y);
44460b57cec5SDimitry Andric}
44470b57cec5SDimitry Andric
44480b57cec5SDimitry Andrictemplate <class _BiIter>
4449cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool
4450cb14a3feSDimitry Andricoperator<(typename iterator_traits<_BiIter>::value_type const& __x, const sub_match<_BiIter>& __y) {
44510b57cec5SDimitry Andric  typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type;
44520b57cec5SDimitry Andric  return __y.compare(string_type(1, __x)) > 0;
44530b57cec5SDimitry Andric}
44540b57cec5SDimitry Andric
44550b57cec5SDimitry Andrictemplate <class _BiIter>
4456cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool
4457cb14a3feSDimitry Andricoperator>(typename iterator_traits<_BiIter>::value_type const& __x, const sub_match<_BiIter>& __y) {
44580b57cec5SDimitry Andric  return __y < __x;
44590b57cec5SDimitry Andric}
44600b57cec5SDimitry Andric
44610b57cec5SDimitry Andrictemplate <class _BiIter>
4462cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool
4463cb14a3feSDimitry Andricoperator>=(typename iterator_traits<_BiIter>::value_type const& __x, const sub_match<_BiIter>& __y) {
44640b57cec5SDimitry Andric  return !(__x < __y);
44650b57cec5SDimitry Andric}
44660b57cec5SDimitry Andric
44670b57cec5SDimitry Andrictemplate <class _BiIter>
4468cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool
4469cb14a3feSDimitry Andricoperator<=(typename iterator_traits<_BiIter>::value_type const& __x, const sub_match<_BiIter>& __y) {
44700b57cec5SDimitry Andric  return !(__y < __x);
44710b57cec5SDimitry Andric}
447206c3fb27SDimitry Andric#endif // _LIBCPP_STD_VER >= 20
44730b57cec5SDimitry Andric
44740b57cec5SDimitry Andrictemplate <class _BiIter>
4475cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool
4476cb14a3feSDimitry Andricoperator==(const sub_match<_BiIter>& __x, typename iterator_traits<_BiIter>::value_type const& __y) {
44770b57cec5SDimitry Andric  typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type;
44780b57cec5SDimitry Andric  return __x.compare(string_type(1, __y)) == 0;
44790b57cec5SDimitry Andric}
44800b57cec5SDimitry Andric
448106c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 20
448206c3fb27SDimitry Andrictemplate <class _BiIter>
448306c3fb27SDimitry Andric_LIBCPP_HIDE_FROM_ABI auto
448406c3fb27SDimitry Andricoperator<=>(const sub_match<_BiIter>& __x, typename iterator_traits<_BiIter>::value_type const& __y) {
448506c3fb27SDimitry Andric  using string_type = basic_string<typename iterator_traits<_BiIter>::value_type>;
448606c3fb27SDimitry Andric  return static_cast<__sub_match_cat<_BiIter>>(__x.compare(string_type(1, __y)) <=> 0);
448706c3fb27SDimitry Andric}
448806c3fb27SDimitry Andric#else  // _LIBCPP_STD_VER >= 20
44890b57cec5SDimitry Andrictemplate <class _BiIter>
4490cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool
4491cb14a3feSDimitry Andricoperator!=(const sub_match<_BiIter>& __x, typename iterator_traits<_BiIter>::value_type const& __y) {
44920b57cec5SDimitry Andric  return !(__x == __y);
44930b57cec5SDimitry Andric}
44940b57cec5SDimitry Andric
44950b57cec5SDimitry Andrictemplate <class _BiIter>
4496cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool
4497cb14a3feSDimitry Andricoperator<(const sub_match<_BiIter>& __x, typename iterator_traits<_BiIter>::value_type const& __y) {
44980b57cec5SDimitry Andric  typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type;
44990b57cec5SDimitry Andric  return __x.compare(string_type(1, __y)) < 0;
45000b57cec5SDimitry Andric}
45010b57cec5SDimitry Andric
45020b57cec5SDimitry Andrictemplate <class _BiIter>
4503cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool
4504cb14a3feSDimitry Andricoperator>(const sub_match<_BiIter>& __x, typename iterator_traits<_BiIter>::value_type const& __y) {
45050b57cec5SDimitry Andric  return __y < __x;
45060b57cec5SDimitry Andric}
45070b57cec5SDimitry Andric
45080b57cec5SDimitry Andrictemplate <class _BiIter>
4509cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool
4510cb14a3feSDimitry Andricoperator>=(const sub_match<_BiIter>& __x, typename iterator_traits<_BiIter>::value_type const& __y) {
45110b57cec5SDimitry Andric  return !(__x < __y);
45120b57cec5SDimitry Andric}
45130b57cec5SDimitry Andric
45140b57cec5SDimitry Andrictemplate <class _BiIter>
4515cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool
4516cb14a3feSDimitry Andricoperator<=(const sub_match<_BiIter>& __x, typename iterator_traits<_BiIter>::value_type const& __y) {
45170b57cec5SDimitry Andric  return !(__y < __x);
45180b57cec5SDimitry Andric}
451906c3fb27SDimitry Andric#endif // _LIBCPP_STD_VER >= 20
45200b57cec5SDimitry Andric
45210b57cec5SDimitry Andrictemplate <class _CharT, class _ST, class _BiIter>
4522cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI basic_ostream<_CharT, _ST>&
4523cb14a3feSDimitry Andricoperator<<(basic_ostream<_CharT, _ST>& __os, const sub_match<_BiIter>& __m) {
45240b57cec5SDimitry Andric  return __os << __m.str();
45250b57cec5SDimitry Andric}
45260b57cec5SDimitry Andric
4527e8d8bef9SDimitry Andrictypedef match_results<const char*> cmatch;
4528e8d8bef9SDimitry Andrictypedef match_results<string::const_iterator> smatch;
4529349cc55cSDimitry Andric#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
4530349cc55cSDimitry Andrictypedef match_results<const wchar_t*> wcmatch;
4531e8d8bef9SDimitry Andrictypedef match_results<wstring::const_iterator> wsmatch;
4532349cc55cSDimitry Andric#endif
4533e8d8bef9SDimitry Andric
45340b57cec5SDimitry Andrictemplate <class _BidirectionalIterator, class _Allocator>
4535cb14a3feSDimitry Andricclass _LIBCPP_TEMPLATE_VIS _LIBCPP_PREFERRED_NAME(cmatch) _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wcmatch))
4536cb14a3feSDimitry Andric    _LIBCPP_PREFERRED_NAME(smatch) _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wsmatch)) match_results {
45370b57cec5SDimitry Andricpublic:
45380b57cec5SDimitry Andric  typedef _Allocator allocator_type;
45390b57cec5SDimitry Andric  typedef sub_match<_BidirectionalIterator> value_type;
4540cb14a3feSDimitry Andric
45410b57cec5SDimitry Andricprivate:
45420b57cec5SDimitry Andric  typedef vector<value_type, allocator_type> __container_type;
45430b57cec5SDimitry Andric
45440b57cec5SDimitry Andric  __container_type __matches_;
45450b57cec5SDimitry Andric  value_type __unmatched_;
45460b57cec5SDimitry Andric  value_type __prefix_;
45470b57cec5SDimitry Andric  value_type __suffix_;
45480b57cec5SDimitry Andric  bool __ready_;
4549cb14a3feSDimitry Andric
45500b57cec5SDimitry Andricpublic:
45510b57cec5SDimitry Andric  _BidirectionalIterator __position_start_;
45520b57cec5SDimitry Andric  typedef const value_type& const_reference;
45530b57cec5SDimitry Andric  typedef value_type& reference;
45540b57cec5SDimitry Andric  typedef typename __container_type::const_iterator const_iterator;
45550b57cec5SDimitry Andric  typedef const_iterator iterator;
45560b57cec5SDimitry Andric  typedef typename iterator_traits<_BidirectionalIterator>::difference_type difference_type;
45570b57cec5SDimitry Andric  typedef typename allocator_traits<allocator_type>::size_type size_type;
45580b57cec5SDimitry Andric  typedef typename iterator_traits<_BidirectionalIterator>::value_type char_type;
45590b57cec5SDimitry Andric  typedef basic_string<char_type> string_type;
45600b57cec5SDimitry Andric
45610b57cec5SDimitry Andric  // construct/copy/destroy:
4562e8d8bef9SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
4563e8d8bef9SDimitry Andric  match_results() : match_results(allocator_type()) {}
4564e8d8bef9SDimitry Andric  explicit match_results(const allocator_type& __a);
4565e8d8bef9SDimitry Andric#else
45660b57cec5SDimitry Andric  explicit match_results(const allocator_type& __a = allocator_type());
4567e8d8bef9SDimitry Andric#endif
4568e8d8bef9SDimitry Andric
45690b57cec5SDimitry Andric  //    match_results(const match_results&) = default;
45700b57cec5SDimitry Andric  //    match_results& operator=(const match_results&) = default;
45710b57cec5SDimitry Andric  //    match_results(match_results&& __m) = default;
45720b57cec5SDimitry Andric  //    match_results& operator=(match_results&& __m) = default;
45730b57cec5SDimitry Andric  //    ~match_results() = default;
45740b57cec5SDimitry Andric
4575cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI bool ready() const { return __ready_; }
45760b57cec5SDimitry Andric
45770b57cec5SDimitry Andric  // size:
4578cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI size_type size() const _NOEXCEPT { return __matches_.size(); }
4579cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI size_type max_size() const _NOEXCEPT { return __matches_.max_size(); }
4580*0fca6ea1SDimitry Andric  _LIBCPP_NODISCARD _LIBCPP_HIDE_FROM_ABI bool empty() const _NOEXCEPT { return size() == 0; }
45810b57cec5SDimitry Andric
45820b57cec5SDimitry Andric  // element access:
4583cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI difference_type length(size_type __sub = 0) const {
45841db9f3b2SDimitry Andric    // If the match results are not ready, this will return `0`.
45851db9f3b2SDimitry Andric    _LIBCPP_ASSERT_PEDANTIC(ready(), "match_results::length() called when not ready");
45860b57cec5SDimitry Andric    return (*this)[__sub].length();
45870b57cec5SDimitry Andric  }
4588cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI difference_type position(size_type __sub = 0) const {
45891db9f3b2SDimitry Andric    // If the match results are not ready, this will return the result of subtracting two default-constructed iterators
45901db9f3b2SDimitry Andric    // (which is typically a well-defined operation).
45911db9f3b2SDimitry Andric    _LIBCPP_ASSERT_PEDANTIC(ready(), "match_results::position() called when not ready");
45925f757f3fSDimitry Andric    return std::distance(__position_start_, (*this)[__sub].first);
45930b57cec5SDimitry Andric  }
4594cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI string_type str(size_type __sub = 0) const {
45951db9f3b2SDimitry Andric    // If the match results are not ready, this will return an empty string.
45961db9f3b2SDimitry Andric    _LIBCPP_ASSERT_PEDANTIC(ready(), "match_results::str() called when not ready");
45970b57cec5SDimitry Andric    return (*this)[__sub].str();
45980b57cec5SDimitry Andric  }
4599cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_reference operator[](size_type __n) const {
46001db9f3b2SDimitry Andric    // If the match results are not ready, this call will be equivalent to calling this function with `__n >= size()`,
46011db9f3b2SDimitry Andric    // returning an empty subrange.
46021db9f3b2SDimitry Andric    _LIBCPP_ASSERT_PEDANTIC(ready(), "match_results::operator[]() called when not ready");
46030b57cec5SDimitry Andric    return __n < __matches_.size() ? __matches_[__n] : __unmatched_;
46040b57cec5SDimitry Andric  }
46050b57cec5SDimitry Andric
4606cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_reference prefix() const {
46071db9f3b2SDimitry Andric    // If the match results are not ready, this will return a default-constructed empty `__suffix_`.
46081db9f3b2SDimitry Andric    _LIBCPP_ASSERT_PEDANTIC(ready(), "match_results::prefix() called when not ready");
46090b57cec5SDimitry Andric    return __prefix_;
46100b57cec5SDimitry Andric  }
4611cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_reference suffix() const {
46121db9f3b2SDimitry Andric    // If the match results are not ready, this will return a default-constructed empty `__suffix_`.
46131db9f3b2SDimitry Andric    _LIBCPP_ASSERT_PEDANTIC(ready(), "match_results::suffix() called when not ready");
46140b57cec5SDimitry Andric    return __suffix_;
46150b57cec5SDimitry Andric  }
46160b57cec5SDimitry Andric
4617cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_iterator begin() const { return empty() ? __matches_.end() : __matches_.begin(); }
4618cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_iterator end() const { return __matches_.end(); }
4619cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_iterator cbegin() const { return empty() ? __matches_.end() : __matches_.begin(); }
4620cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const_iterator cend() const { return __matches_.end(); }
46210b57cec5SDimitry Andric
46220b57cec5SDimitry Andric  // format:
46230b57cec5SDimitry Andric  template <class _OutputIter>
4624cb14a3feSDimitry Andric  _OutputIter format(_OutputIter __output_iter,
4625cb14a3feSDimitry Andric                     const char_type* __fmt_first,
46260b57cec5SDimitry Andric                     const char_type* __fmt_last,
46270b57cec5SDimitry Andric                     regex_constants::match_flag_type __flags = regex_constants::format_default) const;
46280b57cec5SDimitry Andric  template <class _OutputIter, class _ST, class _SA>
4629cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI _OutputIter
4630cb14a3feSDimitry Andric  format(_OutputIter __output_iter,
4631cb14a3feSDimitry Andric         const basic_string<char_type, _ST, _SA>& __fmt,
4632cb14a3feSDimitry Andric         regex_constants::match_flag_type __flags = regex_constants::format_default) const {
4633cb14a3feSDimitry Andric    return format(__output_iter, __fmt.data(), __fmt.data() + __fmt.size(), __flags);
4634cb14a3feSDimitry Andric  }
46350b57cec5SDimitry Andric  template <class _ST, class _SA>
4636cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI basic_string<char_type, _ST, _SA>
46370b57cec5SDimitry Andric  format(const basic_string<char_type, _ST, _SA>& __fmt,
4638cb14a3feSDimitry Andric         regex_constants::match_flag_type __flags = regex_constants::format_default) const {
46390b57cec5SDimitry Andric    basic_string<char_type, _ST, _SA> __r;
4640cb14a3feSDimitry Andric    format(std::back_inserter(__r), __fmt.data(), __fmt.data() + __fmt.size(), __flags);
46410b57cec5SDimitry Andric    return __r;
46420b57cec5SDimitry Andric  }
4643cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI string_type
4644cb14a3feSDimitry Andric  format(const char_type* __fmt, regex_constants::match_flag_type __flags = regex_constants::format_default) const {
46450b57cec5SDimitry Andric    string_type __r;
4646cb14a3feSDimitry Andric    format(std::back_inserter(__r), __fmt, __fmt + char_traits<char_type>::length(__fmt), __flags);
46470b57cec5SDimitry Andric    return __r;
46480b57cec5SDimitry Andric  }
46490b57cec5SDimitry Andric
46500b57cec5SDimitry Andric  // allocator:
4651cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI allocator_type get_allocator() const { return __matches_.get_allocator(); }
46520b57cec5SDimitry Andric
46530b57cec5SDimitry Andric  // swap:
46540b57cec5SDimitry Andric  void swap(match_results& __m);
46550b57cec5SDimitry Andric
46560b57cec5SDimitry Andric  template <class _Bp, class _Ap>
4657cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI void
4658cb14a3feSDimitry Andric  __assign(_BidirectionalIterator __f,
4659cb14a3feSDimitry Andric           _BidirectionalIterator __l,
4660cb14a3feSDimitry Andric           const match_results<_Bp, _Ap>& __m,
4661cb14a3feSDimitry Andric           bool __no_update_pos) {
46620b57cec5SDimitry Andric    _Bp __mf = __m.prefix().first;
46630b57cec5SDimitry Andric    __matches_.resize(__m.size());
4664cb14a3feSDimitry Andric    for (size_type __i = 0; __i < __matches_.size(); ++__i) {
46655f757f3fSDimitry Andric      __matches_[__i].first   = std::next(__f, std::distance(__mf, __m[__i].first));
46665f757f3fSDimitry Andric      __matches_[__i].second  = std::next(__f, std::distance(__mf, __m[__i].second));
46670b57cec5SDimitry Andric      __matches_[__i].matched = __m[__i].matched;
46680b57cec5SDimitry Andric    }
46690b57cec5SDimitry Andric    __unmatched_.first   = __l;
46700b57cec5SDimitry Andric    __unmatched_.second  = __l;
46710b57cec5SDimitry Andric    __unmatched_.matched = false;
46725f757f3fSDimitry Andric    __prefix_.first      = std::next(__f, std::distance(__mf, __m.prefix().first));
46735f757f3fSDimitry Andric    __prefix_.second     = std::next(__f, std::distance(__mf, __m.prefix().second));
46740b57cec5SDimitry Andric    __prefix_.matched    = __m.prefix().matched;
46755f757f3fSDimitry Andric    __suffix_.first      = std::next(__f, std::distance(__mf, __m.suffix().first));
46765f757f3fSDimitry Andric    __suffix_.second     = std::next(__f, std::distance(__mf, __m.suffix().second));
46770b57cec5SDimitry Andric    __suffix_.matched    = __m.suffix().matched;
46780b57cec5SDimitry Andric    if (!__no_update_pos)
46790b57cec5SDimitry Andric      __position_start_ = __prefix_.first;
46800b57cec5SDimitry Andric    __ready_ = __m.ready();
46810b57cec5SDimitry Andric  }
46820b57cec5SDimitry Andric
46830b57cec5SDimitry Andricprivate:
4684cb14a3feSDimitry Andric  void __init(unsigned __s, _BidirectionalIterator __f, _BidirectionalIterator __l, bool __no_update_pos = false);
46850b57cec5SDimitry Andric
4686cb14a3feSDimitry Andric  template <class, class>
4687cb14a3feSDimitry Andric  friend class basic_regex;
46880b57cec5SDimitry Andric
46890b57cec5SDimitry Andric  template <class _Bp, class _Ap, class _Cp, class _Tp>
4690cb14a3feSDimitry Andric  friend bool
4691cb14a3feSDimitry Andric  regex_match(_Bp, _Bp, match_results<_Bp, _Ap>&, const basic_regex<_Cp, _Tp>&, regex_constants::match_flag_type);
46920b57cec5SDimitry Andric
46930b57cec5SDimitry Andric  template <class _Bp, class _Ap>
4694cb14a3feSDimitry Andric  friend bool operator==(const match_results<_Bp, _Ap>&, const match_results<_Bp, _Ap>&);
46950b57cec5SDimitry Andric
4696cb14a3feSDimitry Andric  template <class, class>
4697cb14a3feSDimitry Andric  friend class __lookahead;
4698*0fca6ea1SDimitry Andric
4699*0fca6ea1SDimitry Andric  template <class, class, class>
4700*0fca6ea1SDimitry Andric  friend class regex_iterator;
47010b57cec5SDimitry Andric};
47020b57cec5SDimitry Andric
47030b57cec5SDimitry Andrictemplate <class _BidirectionalIterator, class _Allocator>
4704cb14a3feSDimitry Andricmatch_results<_BidirectionalIterator, _Allocator>::match_results(const allocator_type& __a)
4705cb14a3feSDimitry Andric    : __matches_(__a), __unmatched_(), __prefix_(), __suffix_(), __ready_(false), __position_start_() {}
47060b57cec5SDimitry Andric
47070b57cec5SDimitry Andrictemplate <class _BidirectionalIterator, class _Allocator>
4708cb14a3feSDimitry Andricvoid match_results<_BidirectionalIterator, _Allocator>::__init(
4709cb14a3feSDimitry Andric    unsigned __s, _BidirectionalIterator __f, _BidirectionalIterator __l, bool __no_update_pos) {
47100b57cec5SDimitry Andric  __unmatched_.first   = __l;
47110b57cec5SDimitry Andric  __unmatched_.second  = __l;
47120b57cec5SDimitry Andric  __unmatched_.matched = false;
47130b57cec5SDimitry Andric  __matches_.assign(__s, __unmatched_);
47140b57cec5SDimitry Andric  __prefix_.first   = __f;
47150b57cec5SDimitry Andric  __prefix_.second  = __f;
47160b57cec5SDimitry Andric  __prefix_.matched = false;
47170b57cec5SDimitry Andric  __suffix_         = __unmatched_;
47180b57cec5SDimitry Andric  if (!__no_update_pos)
47190b57cec5SDimitry Andric    __position_start_ = __prefix_.first;
47200b57cec5SDimitry Andric  __ready_ = true;
47210b57cec5SDimitry Andric}
47220b57cec5SDimitry Andric
47230b57cec5SDimitry Andrictemplate <class _BidirectionalIterator, class _Allocator>
47240b57cec5SDimitry Andrictemplate <class _OutputIter>
4725cb14a3feSDimitry Andric_OutputIter match_results<_BidirectionalIterator, _Allocator>::format(
4726cb14a3feSDimitry Andric    _OutputIter __output_iter,
4727cb14a3feSDimitry Andric    const char_type* __fmt_first,
4728cb14a3feSDimitry Andric    const char_type* __fmt_last,
4729cb14a3feSDimitry Andric    regex_constants::match_flag_type __flags) const {
47301db9f3b2SDimitry Andric  // Note: this duplicates a check in `vector::operator[]` but provides a better error message.
47311db9f3b2SDimitry Andric  _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(ready(), "match_results::format() called when not ready");
4732cb14a3feSDimitry Andric  if (__flags & regex_constants::format_sed) {
4733cb14a3feSDimitry Andric    for (; __fmt_first != __fmt_last; ++__fmt_first) {
47340b57cec5SDimitry Andric      if (*__fmt_first == '&')
4735cb14a3feSDimitry Andric        __output_iter = std::copy(__matches_[0].first, __matches_[0].second, __output_iter);
4736cb14a3feSDimitry Andric      else if (*__fmt_first == '\\' && __fmt_first + 1 != __fmt_last) {
47370b57cec5SDimitry Andric        ++__fmt_first;
4738cb14a3feSDimitry Andric        if ('0' <= *__fmt_first && *__fmt_first <= '9') {
47390b57cec5SDimitry Andric          size_t __i    = *__fmt_first - '0';
4740cb14a3feSDimitry Andric          __output_iter = std::copy((*this)[__i].first, (*this)[__i].second, __output_iter);
4741cb14a3feSDimitry Andric        } else {
4742cb14a3feSDimitry Andric          *__output_iter = *__fmt_first;
4743cb14a3feSDimitry Andric          ++__output_iter;
47440b57cec5SDimitry Andric        }
4745cb14a3feSDimitry Andric      } else {
47460b57cec5SDimitry Andric        *__output_iter = *__fmt_first;
47470b57cec5SDimitry Andric        ++__output_iter;
47480b57cec5SDimitry Andric      }
47490b57cec5SDimitry Andric    }
4750cb14a3feSDimitry Andric  } else {
4751cb14a3feSDimitry Andric    for (; __fmt_first != __fmt_last; ++__fmt_first) {
4752cb14a3feSDimitry Andric      if (*__fmt_first == '$' && __fmt_first + 1 != __fmt_last) {
4753cb14a3feSDimitry Andric        switch (__fmt_first[1]) {
47540b57cec5SDimitry Andric        case '$':
47550b57cec5SDimitry Andric          *__output_iter = *++__fmt_first;
47560b57cec5SDimitry Andric          ++__output_iter;
47570b57cec5SDimitry Andric          break;
47580b57cec5SDimitry Andric        case '&':
47590b57cec5SDimitry Andric          ++__fmt_first;
4760cb14a3feSDimitry Andric          __output_iter = std::copy(__matches_[0].first, __matches_[0].second, __output_iter);
47610b57cec5SDimitry Andric          break;
47620b57cec5SDimitry Andric        case '`':
47630b57cec5SDimitry Andric          ++__fmt_first;
47645f757f3fSDimitry Andric          __output_iter = std::copy(__prefix_.first, __prefix_.second, __output_iter);
47650b57cec5SDimitry Andric          break;
47660b57cec5SDimitry Andric        case '\'':
47670b57cec5SDimitry Andric          ++__fmt_first;
47685f757f3fSDimitry Andric          __output_iter = std::copy(__suffix_.first, __suffix_.second, __output_iter);
47690b57cec5SDimitry Andric          break;
47700b57cec5SDimitry Andric        default:
4771cb14a3feSDimitry Andric          if ('0' <= __fmt_first[1] && __fmt_first[1] <= '9') {
47720b57cec5SDimitry Andric            ++__fmt_first;
47730b57cec5SDimitry Andric            size_t __idx = *__fmt_first - '0';
4774cb14a3feSDimitry Andric            if (__fmt_first + 1 != __fmt_last && '0' <= __fmt_first[1] && __fmt_first[1] <= '9') {
47750b57cec5SDimitry Andric              ++__fmt_first;
4776e8d8bef9SDimitry Andric              if (__idx >= numeric_limits<size_t>::max() / 10)
47770b57cec5SDimitry Andric                __throw_regex_error<regex_constants::error_escape>();
47780b57cec5SDimitry Andric              __idx = 10 * __idx + *__fmt_first - '0';
47790b57cec5SDimitry Andric            }
4780cb14a3feSDimitry Andric            __output_iter = std::copy((*this)[__idx].first, (*this)[__idx].second, __output_iter);
4781cb14a3feSDimitry Andric          } else {
47820b57cec5SDimitry Andric            *__output_iter = *__fmt_first;
47830b57cec5SDimitry Andric            ++__output_iter;
47840b57cec5SDimitry Andric          }
47850b57cec5SDimitry Andric          break;
47860b57cec5SDimitry Andric        }
4787cb14a3feSDimitry Andric      } else {
47880b57cec5SDimitry Andric        *__output_iter = *__fmt_first;
47890b57cec5SDimitry Andric        ++__output_iter;
47900b57cec5SDimitry Andric      }
47910b57cec5SDimitry Andric    }
47920b57cec5SDimitry Andric  }
47930b57cec5SDimitry Andric  return __output_iter;
47940b57cec5SDimitry Andric}
47950b57cec5SDimitry Andric
47960b57cec5SDimitry Andrictemplate <class _BidirectionalIterator, class _Allocator>
4797cb14a3feSDimitry Andricvoid match_results<_BidirectionalIterator, _Allocator>::swap(match_results& __m) {
47985f757f3fSDimitry Andric  using std::swap;
47990b57cec5SDimitry Andric  swap(__matches_, __m.__matches_);
48000b57cec5SDimitry Andric  swap(__unmatched_, __m.__unmatched_);
48010b57cec5SDimitry Andric  swap(__prefix_, __m.__prefix_);
48020b57cec5SDimitry Andric  swap(__suffix_, __m.__suffix_);
48030b57cec5SDimitry Andric  swap(__position_start_, __m.__position_start_);
48040b57cec5SDimitry Andric  swap(__ready_, __m.__ready_);
48050b57cec5SDimitry Andric}
48060b57cec5SDimitry Andric
48070b57cec5SDimitry Andrictemplate <class _BidirectionalIterator, class _Allocator>
4808cb14a3feSDimitry Andric_LIBCPP_HIDE_FROM_ABI bool operator==(const match_results<_BidirectionalIterator, _Allocator>& __x,
4809cb14a3feSDimitry Andric                                      const match_results<_BidirectionalIterator, _Allocator>& __y) {
48100b57cec5SDimitry Andric  if (__x.__ready_ != __y.__ready_)
48110b57cec5SDimitry Andric    return false;
48120b57cec5SDimitry Andric  if (!__x.__ready_)
48130b57cec5SDimitry Andric    return true;
4814cb14a3feSDimitry Andric  return __x.__matches_ == __y.__matches_ && __x.__prefix_ == __y.__prefix_ && __x.__suffix_ == __y.__suffix_;
48150b57cec5SDimitry Andric}
48160b57cec5SDimitry Andric
481706c3fb27SDimitry Andric#if _LIBCPP_STD_VER < 20
48180b57cec5SDimitry Andrictemplate <class _BidirectionalIterator, class _Allocator>
4819cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool operator!=(const match_results<_BidirectionalIterator, _Allocator>& __x,
4820cb14a3feSDimitry Andric                                             const match_results<_BidirectionalIterator, _Allocator>& __y) {
48210b57cec5SDimitry Andric  return !(__x == __y);
48220b57cec5SDimitry Andric}
482306c3fb27SDimitry Andric#endif
48240b57cec5SDimitry Andric
48250b57cec5SDimitry Andrictemplate <class _BidirectionalIterator, class _Allocator>
4826cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI void
4827cb14a3feSDimitry Andricswap(match_results<_BidirectionalIterator, _Allocator>& __x, match_results<_BidirectionalIterator, _Allocator>& __y) {
48280b57cec5SDimitry Andric  __x.swap(__y);
48290b57cec5SDimitry Andric}
48300b57cec5SDimitry Andric
48310b57cec5SDimitry Andric// regex_search
48320b57cec5SDimitry Andric
48330b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
48340b57cec5SDimitry Andrictemplate <class _Allocator>
4835cb14a3feSDimitry Andricbool basic_regex<_CharT, _Traits>::__match_at_start_ecma(
4836cb14a3feSDimitry Andric    const _CharT* __first,
4837cb14a3feSDimitry Andric    const _CharT* __last,
48380b57cec5SDimitry Andric    match_results<const _CharT*, _Allocator>& __m,
4839cb14a3feSDimitry Andric    regex_constants::match_flag_type __flags,
4840cb14a3feSDimitry Andric    bool __at_first) const {
48410b57cec5SDimitry Andric  vector<__state> __states;
48420b57cec5SDimitry Andric  __node* __st = __start_.get();
4843cb14a3feSDimitry Andric  if (__st) {
48440b57cec5SDimitry Andric    sub_match<const _CharT*> __unmatched;
48450b57cec5SDimitry Andric    __unmatched.first   = __last;
48460b57cec5SDimitry Andric    __unmatched.second  = __last;
48470b57cec5SDimitry Andric    __unmatched.matched = false;
48480b57cec5SDimitry Andric
48490b57cec5SDimitry Andric    __states.push_back(__state());
48500b57cec5SDimitry Andric    __states.back().__do_      = 0;
48510b57cec5SDimitry Andric    __states.back().__first_   = __first;
48520b57cec5SDimitry Andric    __states.back().__current_ = __first;
48530b57cec5SDimitry Andric    __states.back().__last_    = __last;
48540b57cec5SDimitry Andric    __states.back().__sub_matches_.resize(mark_count(), __unmatched);
48550b57cec5SDimitry Andric    __states.back().__loop_data_.resize(__loop_count());
48560b57cec5SDimitry Andric    __states.back().__node_     = __st;
48570b57cec5SDimitry Andric    __states.back().__flags_    = __flags;
48580b57cec5SDimitry Andric    __states.back().__at_first_ = __at_first;
48590b57cec5SDimitry Andric    int __counter               = 0;
48600b57cec5SDimitry Andric    int __length                = __last - __first;
4861cb14a3feSDimitry Andric    do {
48620b57cec5SDimitry Andric      ++__counter;
4863cb14a3feSDimitry Andric      if (__counter % _LIBCPP_REGEX_COMPLEXITY_FACTOR == 0 && __counter / _LIBCPP_REGEX_COMPLEXITY_FACTOR >= __length)
48640b57cec5SDimitry Andric        __throw_regex_error<regex_constants::error_complexity>();
48650b57cec5SDimitry Andric      __state& __s = __states.back();
48660b57cec5SDimitry Andric      if (__s.__node_)
48670b57cec5SDimitry Andric        __s.__node_->__exec(__s);
4868cb14a3feSDimitry Andric      switch (__s.__do_) {
48690b57cec5SDimitry Andric      case __state::__end_state:
4870cb14a3feSDimitry Andric        if ((__flags & regex_constants::match_not_null) && __s.__current_ == __first) {
48710b57cec5SDimitry Andric          __states.pop_back();
48720b57cec5SDimitry Andric          break;
48730b57cec5SDimitry Andric        }
4874cb14a3feSDimitry Andric        if ((__flags & regex_constants::__full_match) && __s.__current_ != __last) {
48750b57cec5SDimitry Andric          __states.pop_back();
48760b57cec5SDimitry Andric          break;
48770b57cec5SDimitry Andric        }
48780b57cec5SDimitry Andric        __m.__matches_[0].first   = __first;
48795f757f3fSDimitry Andric        __m.__matches_[0].second  = std::next(__first, __s.__current_ - __first);
48800b57cec5SDimitry Andric        __m.__matches_[0].matched = true;
48810b57cec5SDimitry Andric        for (unsigned __i = 0; __i < __s.__sub_matches_.size(); ++__i)
48820b57cec5SDimitry Andric          __m.__matches_[__i + 1] = __s.__sub_matches_[__i];
48830b57cec5SDimitry Andric        return true;
48840b57cec5SDimitry Andric      case __state::__accept_and_consume:
48850b57cec5SDimitry Andric      case __state::__repeat:
48860b57cec5SDimitry Andric      case __state::__accept_but_not_consume:
48870b57cec5SDimitry Andric        break;
4888cb14a3feSDimitry Andric      case __state::__split: {
48890b57cec5SDimitry Andric        __state __snext = __s;
48900b57cec5SDimitry Andric        __s.__node_->__exec_split(true, __s);
48910b57cec5SDimitry Andric        __snext.__node_->__exec_split(false, __snext);
48925f757f3fSDimitry Andric        __states.push_back(std::move(__snext));
4893cb14a3feSDimitry Andric      } break;
48940b57cec5SDimitry Andric      case __state::__reject:
48950b57cec5SDimitry Andric        __states.pop_back();
48960b57cec5SDimitry Andric        break;
48970b57cec5SDimitry Andric      default:
48980b57cec5SDimitry Andric        __throw_regex_error<regex_constants::__re_err_unknown>();
48990b57cec5SDimitry Andric        break;
49000b57cec5SDimitry Andric      }
49010b57cec5SDimitry Andric    } while (!__states.empty());
49020b57cec5SDimitry Andric  }
49030b57cec5SDimitry Andric  return false;
49040b57cec5SDimitry Andric}
49050b57cec5SDimitry Andric
49060b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
49070b57cec5SDimitry Andrictemplate <class _Allocator>
4908cb14a3feSDimitry Andricbool basic_regex<_CharT, _Traits>::__match_at_start_posix_nosubs(
4909cb14a3feSDimitry Andric    const _CharT* __first,
4910cb14a3feSDimitry Andric    const _CharT* __last,
49110b57cec5SDimitry Andric    match_results<const _CharT*, _Allocator>& __m,
4912cb14a3feSDimitry Andric    regex_constants::match_flag_type __flags,
4913cb14a3feSDimitry Andric    bool __at_first) const {
49140b57cec5SDimitry Andric  deque<__state> __states;
49150b57cec5SDimitry Andric  ptrdiff_t __highest_j = 0;
49165f757f3fSDimitry Andric  ptrdiff_t __np        = std::distance(__first, __last);
49170b57cec5SDimitry Andric  __node* __st          = __start_.get();
4918cb14a3feSDimitry Andric  if (__st) {
49190b57cec5SDimitry Andric    __states.push_back(__state());
49200b57cec5SDimitry Andric    __states.back().__do_      = 0;
49210b57cec5SDimitry Andric    __states.back().__first_   = __first;
49220b57cec5SDimitry Andric    __states.back().__current_ = __first;
49230b57cec5SDimitry Andric    __states.back().__last_    = __last;
49240b57cec5SDimitry Andric    __states.back().__loop_data_.resize(__loop_count());
49250b57cec5SDimitry Andric    __states.back().__node_     = __st;
49260b57cec5SDimitry Andric    __states.back().__flags_    = __flags;
49270b57cec5SDimitry Andric    __states.back().__at_first_ = __at_first;
49280b57cec5SDimitry Andric    bool __matched              = false;
49290b57cec5SDimitry Andric    int __counter               = 0;
49300b57cec5SDimitry Andric    int __length                = __last - __first;
4931cb14a3feSDimitry Andric    do {
49320b57cec5SDimitry Andric      ++__counter;
4933cb14a3feSDimitry Andric      if (__counter % _LIBCPP_REGEX_COMPLEXITY_FACTOR == 0 && __counter / _LIBCPP_REGEX_COMPLEXITY_FACTOR >= __length)
49340b57cec5SDimitry Andric        __throw_regex_error<regex_constants::error_complexity>();
49350b57cec5SDimitry Andric      __state& __s = __states.back();
49360b57cec5SDimitry Andric      if (__s.__node_)
49370b57cec5SDimitry Andric        __s.__node_->__exec(__s);
4938cb14a3feSDimitry Andric      switch (__s.__do_) {
49390b57cec5SDimitry Andric      case __state::__end_state:
4940cb14a3feSDimitry Andric        if ((__flags & regex_constants::match_not_null) && __s.__current_ == __first) {
49410b57cec5SDimitry Andric          __states.pop_back();
49420b57cec5SDimitry Andric          break;
49430b57cec5SDimitry Andric        }
4944cb14a3feSDimitry Andric        if ((__flags & regex_constants::__full_match) && __s.__current_ != __last) {
49450b57cec5SDimitry Andric          __states.pop_back();
49460b57cec5SDimitry Andric          break;
49470b57cec5SDimitry Andric        }
49480b57cec5SDimitry Andric        if (!__matched || __highest_j < __s.__current_ - __s.__first_)
49490b57cec5SDimitry Andric          __highest_j = __s.__current_ - __s.__first_;
49500b57cec5SDimitry Andric        __matched = true;
495106c3fb27SDimitry Andric        if (__highest_j == __np)
49520b57cec5SDimitry Andric          __states.clear();
49530b57cec5SDimitry Andric        else
49540b57cec5SDimitry Andric          __states.pop_back();
49550b57cec5SDimitry Andric        break;
49560b57cec5SDimitry Andric      case __state::__consume_input:
49570b57cec5SDimitry Andric        break;
49580b57cec5SDimitry Andric      case __state::__accept_and_consume:
49595f757f3fSDimitry Andric        __states.push_front(std::move(__s));
49600b57cec5SDimitry Andric        __states.pop_back();
49610b57cec5SDimitry Andric        break;
49620b57cec5SDimitry Andric      case __state::__repeat:
49630b57cec5SDimitry Andric      case __state::__accept_but_not_consume:
49640b57cec5SDimitry Andric        break;
4965cb14a3feSDimitry Andric      case __state::__split: {
49660b57cec5SDimitry Andric        __state __snext = __s;
49670b57cec5SDimitry Andric        __s.__node_->__exec_split(true, __s);
49680b57cec5SDimitry Andric        __snext.__node_->__exec_split(false, __snext);
49695f757f3fSDimitry Andric        __states.push_back(std::move(__snext));
4970cb14a3feSDimitry Andric      } break;
49710b57cec5SDimitry Andric      case __state::__reject:
49720b57cec5SDimitry Andric        __states.pop_back();
49730b57cec5SDimitry Andric        break;
49740b57cec5SDimitry Andric      default:
49750b57cec5SDimitry Andric        __throw_regex_error<regex_constants::__re_err_unknown>();
49760b57cec5SDimitry Andric        break;
49770b57cec5SDimitry Andric      }
49780b57cec5SDimitry Andric    } while (!__states.empty());
4979cb14a3feSDimitry Andric    if (__matched) {
49800b57cec5SDimitry Andric      __m.__matches_[0].first   = __first;
49815f757f3fSDimitry Andric      __m.__matches_[0].second  = std::next(__first, __highest_j);
49820b57cec5SDimitry Andric      __m.__matches_[0].matched = true;
49830b57cec5SDimitry Andric      return true;
49840b57cec5SDimitry Andric    }
49850b57cec5SDimitry Andric  }
49860b57cec5SDimitry Andric  return false;
49870b57cec5SDimitry Andric}
49880b57cec5SDimitry Andric
49890b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
49900b57cec5SDimitry Andrictemplate <class _Allocator>
4991cb14a3feSDimitry Andricbool basic_regex<_CharT, _Traits>::__match_at_start_posix_subs(
4992cb14a3feSDimitry Andric    const _CharT* __first,
4993cb14a3feSDimitry Andric    const _CharT* __last,
49940b57cec5SDimitry Andric    match_results<const _CharT*, _Allocator>& __m,
4995cb14a3feSDimitry Andric    regex_constants::match_flag_type __flags,
4996cb14a3feSDimitry Andric    bool __at_first) const {
49970b57cec5SDimitry Andric  vector<__state> __states;
49980b57cec5SDimitry Andric  __state __best_state;
49990b57cec5SDimitry Andric  ptrdiff_t __highest_j = 0;
50005f757f3fSDimitry Andric  ptrdiff_t __np        = std::distance(__first, __last);
50010b57cec5SDimitry Andric  __node* __st          = __start_.get();
5002cb14a3feSDimitry Andric  if (__st) {
50030b57cec5SDimitry Andric    sub_match<const _CharT*> __unmatched;
50040b57cec5SDimitry Andric    __unmatched.first   = __last;
50050b57cec5SDimitry Andric    __unmatched.second  = __last;
50060b57cec5SDimitry Andric    __unmatched.matched = false;
50070b57cec5SDimitry Andric
50080b57cec5SDimitry Andric    __states.push_back(__state());
50090b57cec5SDimitry Andric    __states.back().__do_      = 0;
50100b57cec5SDimitry Andric    __states.back().__first_   = __first;
50110b57cec5SDimitry Andric    __states.back().__current_ = __first;
50120b57cec5SDimitry Andric    __states.back().__last_    = __last;
50130b57cec5SDimitry Andric    __states.back().__sub_matches_.resize(mark_count(), __unmatched);
50140b57cec5SDimitry Andric    __states.back().__loop_data_.resize(__loop_count());
50150b57cec5SDimitry Andric    __states.back().__node_     = __st;
50160b57cec5SDimitry Andric    __states.back().__flags_    = __flags;
50170b57cec5SDimitry Andric    __states.back().__at_first_ = __at_first;
50180b57cec5SDimitry Andric    bool __matched              = false;
50190b57cec5SDimitry Andric    int __counter               = 0;
50200b57cec5SDimitry Andric    int __length                = __last - __first;
5021cb14a3feSDimitry Andric    do {
50220b57cec5SDimitry Andric      ++__counter;
5023cb14a3feSDimitry Andric      if (__counter % _LIBCPP_REGEX_COMPLEXITY_FACTOR == 0 && __counter / _LIBCPP_REGEX_COMPLEXITY_FACTOR >= __length)
50240b57cec5SDimitry Andric        __throw_regex_error<regex_constants::error_complexity>();
50250b57cec5SDimitry Andric      __state& __s = __states.back();
50260b57cec5SDimitry Andric      if (__s.__node_)
50270b57cec5SDimitry Andric        __s.__node_->__exec(__s);
5028cb14a3feSDimitry Andric      switch (__s.__do_) {
50290b57cec5SDimitry Andric      case __state::__end_state:
5030cb14a3feSDimitry Andric        if ((__flags & regex_constants::match_not_null) && __s.__current_ == __first) {
50310b57cec5SDimitry Andric          __states.pop_back();
50320b57cec5SDimitry Andric          break;
50330b57cec5SDimitry Andric        }
5034cb14a3feSDimitry Andric        if ((__flags & regex_constants::__full_match) && __s.__current_ != __last) {
50350b57cec5SDimitry Andric          __states.pop_back();
50360b57cec5SDimitry Andric          break;
50370b57cec5SDimitry Andric        }
5038cb14a3feSDimitry Andric        if (!__matched || __highest_j < __s.__current_ - __s.__first_) {
50390b57cec5SDimitry Andric          __highest_j  = __s.__current_ - __s.__first_;
50400b57cec5SDimitry Andric          __best_state = __s;
50410b57cec5SDimitry Andric        }
50420b57cec5SDimitry Andric        __matched = true;
504306c3fb27SDimitry Andric        if (__highest_j == __np)
50440b57cec5SDimitry Andric          __states.clear();
50450b57cec5SDimitry Andric        else
50460b57cec5SDimitry Andric          __states.pop_back();
50470b57cec5SDimitry Andric        break;
50480b57cec5SDimitry Andric      case __state::__accept_and_consume:
50490b57cec5SDimitry Andric      case __state::__repeat:
50500b57cec5SDimitry Andric      case __state::__accept_but_not_consume:
50510b57cec5SDimitry Andric        break;
5052cb14a3feSDimitry Andric      case __state::__split: {
50530b57cec5SDimitry Andric        __state __snext = __s;
50540b57cec5SDimitry Andric        __s.__node_->__exec_split(true, __s);
50550b57cec5SDimitry Andric        __snext.__node_->__exec_split(false, __snext);
50565f757f3fSDimitry Andric        __states.push_back(std::move(__snext));
5057cb14a3feSDimitry Andric      } break;
50580b57cec5SDimitry Andric      case __state::__reject:
50590b57cec5SDimitry Andric        __states.pop_back();
50600b57cec5SDimitry Andric        break;
50610b57cec5SDimitry Andric      default:
50620b57cec5SDimitry Andric        __throw_regex_error<regex_constants::__re_err_unknown>();
50630b57cec5SDimitry Andric        break;
50640b57cec5SDimitry Andric      }
50650b57cec5SDimitry Andric    } while (!__states.empty());
5066cb14a3feSDimitry Andric    if (__matched) {
50670b57cec5SDimitry Andric      __m.__matches_[0].first   = __first;
50685f757f3fSDimitry Andric      __m.__matches_[0].second  = std::next(__first, __highest_j);
50690b57cec5SDimitry Andric      __m.__matches_[0].matched = true;
50700b57cec5SDimitry Andric      for (unsigned __i = 0; __i < __best_state.__sub_matches_.size(); ++__i)
50710b57cec5SDimitry Andric        __m.__matches_[__i + 1] = __best_state.__sub_matches_[__i];
50720b57cec5SDimitry Andric      return true;
50730b57cec5SDimitry Andric    }
50740b57cec5SDimitry Andric  }
50750b57cec5SDimitry Andric  return false;
50760b57cec5SDimitry Andric}
50770b57cec5SDimitry Andric
50780b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
50790b57cec5SDimitry Andrictemplate <class _Allocator>
5080cb14a3feSDimitry Andricbool basic_regex<_CharT, _Traits>::__match_at_start(
5081cb14a3feSDimitry Andric    const _CharT* __first,
5082cb14a3feSDimitry Andric    const _CharT* __last,
50830b57cec5SDimitry Andric    match_results<const _CharT*, _Allocator>& __m,
5084cb14a3feSDimitry Andric    regex_constants::match_flag_type __flags,
5085cb14a3feSDimitry Andric    bool __at_first) const {
50860b57cec5SDimitry Andric  if (__get_grammar(__flags_) == ECMAScript)
50870b57cec5SDimitry Andric    return __match_at_start_ecma(__first, __last, __m, __flags, __at_first);
50880b57cec5SDimitry Andric  if (mark_count() == 0)
50890b57cec5SDimitry Andric    return __match_at_start_posix_nosubs(__first, __last, __m, __flags, __at_first);
50900b57cec5SDimitry Andric  return __match_at_start_posix_subs(__first, __last, __m, __flags, __at_first);
50910b57cec5SDimitry Andric}
50920b57cec5SDimitry Andric
50930b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
50940b57cec5SDimitry Andrictemplate <class _Allocator>
5095cb14a3feSDimitry Andricbool basic_regex<_CharT, _Traits>::__search(
5096cb14a3feSDimitry Andric    const _CharT* __first,
5097cb14a3feSDimitry Andric    const _CharT* __last,
50980b57cec5SDimitry Andric    match_results<const _CharT*, _Allocator>& __m,
5099cb14a3feSDimitry Andric    regex_constants::match_flag_type __flags) const {
51005ffd83dbSDimitry Andric  if (__flags & regex_constants::match_prev_avail)
51015ffd83dbSDimitry Andric    __flags &= ~(regex_constants::match_not_bol | regex_constants::match_not_bow);
51025ffd83dbSDimitry Andric
5103cb14a3feSDimitry Andric  __m.__init(1 + mark_count(), __first, __last, __flags & regex_constants::__no_update_pos);
5104cb14a3feSDimitry Andric  if (__match_at_start(__first, __last, __m, __flags, !(__flags & regex_constants::__no_update_pos))) {
51050b57cec5SDimitry Andric    __m.__prefix_.second  = __m[0].first;
51060b57cec5SDimitry Andric    __m.__prefix_.matched = __m.__prefix_.first != __m.__prefix_.second;
51070b57cec5SDimitry Andric    __m.__suffix_.first   = __m[0].second;
51080b57cec5SDimitry Andric    __m.__suffix_.matched = __m.__suffix_.first != __m.__suffix_.second;
51090b57cec5SDimitry Andric    return true;
51100b57cec5SDimitry Andric  }
5111cb14a3feSDimitry Andric  if (__first != __last && !(__flags & regex_constants::match_continuous)) {
51120b57cec5SDimitry Andric    __flags |= regex_constants::match_prev_avail;
5113cb14a3feSDimitry Andric    for (++__first; __first != __last; ++__first) {
51140b57cec5SDimitry Andric      __m.__matches_.assign(__m.size(), __m.__unmatched_);
5115cb14a3feSDimitry Andric      if (__match_at_start(__first, __last, __m, __flags, false)) {
51160b57cec5SDimitry Andric        __m.__prefix_.second  = __m[0].first;
51170b57cec5SDimitry Andric        __m.__prefix_.matched = __m.__prefix_.first != __m.__prefix_.second;
51180b57cec5SDimitry Andric        __m.__suffix_.first   = __m[0].second;
51190b57cec5SDimitry Andric        __m.__suffix_.matched = __m.__suffix_.first != __m.__suffix_.second;
51200b57cec5SDimitry Andric        return true;
51210b57cec5SDimitry Andric      }
51220b57cec5SDimitry Andric      __m.__matches_.assign(__m.size(), __m.__unmatched_);
51230b57cec5SDimitry Andric    }
51247a6dacacSDimitry Andric    __m.__matches_.assign(__m.size(), __m.__unmatched_);
51257a6dacacSDimitry Andric    if (__match_at_start(__first, __last, __m, __flags, false)) {
51267a6dacacSDimitry Andric      __m.__prefix_.second  = __m[0].first;
51277a6dacacSDimitry Andric      __m.__prefix_.matched = __m.__prefix_.first != __m.__prefix_.second;
51287a6dacacSDimitry Andric      __m.__suffix_.first   = __m[0].second;
51297a6dacacSDimitry Andric      __m.__suffix_.matched = __m.__suffix_.first != __m.__suffix_.second;
51307a6dacacSDimitry Andric      return true;
51317a6dacacSDimitry Andric    }
51320b57cec5SDimitry Andric  }
51330b57cec5SDimitry Andric  __m.__matches_.clear();
51340b57cec5SDimitry Andric  return false;
51350b57cec5SDimitry Andric}
51360b57cec5SDimitry Andric
51370b57cec5SDimitry Andrictemplate <class _BidirectionalIterator, class _Allocator, class _CharT, class _Traits>
5138cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool
5139cb14a3feSDimitry Andricregex_search(_BidirectionalIterator __first,
5140cb14a3feSDimitry Andric             _BidirectionalIterator __last,
51410b57cec5SDimitry Andric             match_results<_BidirectionalIterator, _Allocator>& __m,
51420b57cec5SDimitry Andric             const basic_regex<_CharT, _Traits>& __e,
5143cb14a3feSDimitry Andric             regex_constants::match_flag_type __flags = regex_constants::match_default) {
51440b57cec5SDimitry Andric  int __offset = (__flags & regex_constants::match_prev_avail) ? 1 : 0;
51455f757f3fSDimitry Andric  basic_string<_CharT> __s(std::prev(__first, __offset), __last);
51460b57cec5SDimitry Andric  match_results<const _CharT*> __mc;
51470b57cec5SDimitry Andric  bool __r = __e.__search(__s.data() + __offset, __s.data() + __s.size(), __mc, __flags);
51480b57cec5SDimitry Andric  __m.__assign(__first, __last, __mc, __flags & regex_constants::__no_update_pos);
51490b57cec5SDimitry Andric  return __r;
51500b57cec5SDimitry Andric}
51510b57cec5SDimitry Andric
51520b57cec5SDimitry Andrictemplate <class _Iter, class _Allocator, class _CharT, class _Traits>
5153cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool
51540b57cec5SDimitry Andricregex_search(__wrap_iter<_Iter> __first,
51550b57cec5SDimitry Andric             __wrap_iter<_Iter> __last,
51560b57cec5SDimitry Andric             match_results<__wrap_iter<_Iter>, _Allocator>& __m,
51570b57cec5SDimitry Andric             const basic_regex<_CharT, _Traits>& __e,
5158cb14a3feSDimitry Andric             regex_constants::match_flag_type __flags = regex_constants::match_default) {
51590b57cec5SDimitry Andric  match_results<const _CharT*> __mc;
51600b57cec5SDimitry Andric  bool __r = __e.__search(__first.base(), __last.base(), __mc, __flags);
51610b57cec5SDimitry Andric  __m.__assign(__first, __last, __mc, __flags & regex_constants::__no_update_pos);
51620b57cec5SDimitry Andric  return __r;
51630b57cec5SDimitry Andric}
51640b57cec5SDimitry Andric
51650b57cec5SDimitry Andrictemplate <class _Allocator, class _CharT, class _Traits>
5166cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool
5167cb14a3feSDimitry Andricregex_search(const _CharT* __first,
5168cb14a3feSDimitry Andric             const _CharT* __last,
51690b57cec5SDimitry Andric             match_results<const _CharT*, _Allocator>& __m,
51700b57cec5SDimitry Andric             const basic_regex<_CharT, _Traits>& __e,
5171cb14a3feSDimitry Andric             regex_constants::match_flag_type __flags = regex_constants::match_default) {
51720b57cec5SDimitry Andric  return __e.__search(__first, __last, __m, __flags);
51730b57cec5SDimitry Andric}
51740b57cec5SDimitry Andric
51750b57cec5SDimitry Andrictemplate <class _BidirectionalIterator, class _CharT, class _Traits>
5176cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool
5177cb14a3feSDimitry Andricregex_search(_BidirectionalIterator __first,
5178cb14a3feSDimitry Andric             _BidirectionalIterator __last,
51790b57cec5SDimitry Andric             const basic_regex<_CharT, _Traits>& __e,
5180cb14a3feSDimitry Andric             regex_constants::match_flag_type __flags = regex_constants::match_default) {
51810b57cec5SDimitry Andric  basic_string<_CharT> __s(__first, __last);
51820b57cec5SDimitry Andric  match_results<const _CharT*> __mc;
51830b57cec5SDimitry Andric  return __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags);
51840b57cec5SDimitry Andric}
51850b57cec5SDimitry Andric
51860b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
5187cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool
5188cb14a3feSDimitry Andricregex_search(const _CharT* __first,
5189cb14a3feSDimitry Andric             const _CharT* __last,
51900b57cec5SDimitry Andric             const basic_regex<_CharT, _Traits>& __e,
5191cb14a3feSDimitry Andric             regex_constants::match_flag_type __flags = regex_constants::match_default) {
51920b57cec5SDimitry Andric  match_results<const _CharT*> __mc;
51930b57cec5SDimitry Andric  return __e.__search(__first, __last, __mc, __flags);
51940b57cec5SDimitry Andric}
51950b57cec5SDimitry Andric
51960b57cec5SDimitry Andrictemplate <class _CharT, class _Allocator, class _Traits>
5197cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool
5198cb14a3feSDimitry Andricregex_search(const _CharT* __str,
5199cb14a3feSDimitry Andric             match_results<const _CharT*, _Allocator>& __m,
52000b57cec5SDimitry Andric             const basic_regex<_CharT, _Traits>& __e,
5201cb14a3feSDimitry Andric             regex_constants::match_flag_type __flags = regex_constants::match_default) {
52020b57cec5SDimitry Andric  return __e.__search(__str, __str + _Traits::length(__str), __m, __flags);
52030b57cec5SDimitry Andric}
52040b57cec5SDimitry Andric
52050b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
5206cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool
5207cb14a3feSDimitry Andricregex_search(const _CharT* __str,
5208cb14a3feSDimitry Andric             const basic_regex<_CharT, _Traits>& __e,
5209cb14a3feSDimitry Andric             regex_constants::match_flag_type __flags = regex_constants::match_default) {
52100b57cec5SDimitry Andric  match_results<const _CharT*> __m;
52115f757f3fSDimitry Andric  return std::regex_search(__str, __m, __e, __flags);
52120b57cec5SDimitry Andric}
52130b57cec5SDimitry Andric
52140b57cec5SDimitry Andrictemplate <class _ST, class _SA, class _CharT, class _Traits>
5215cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool
52160b57cec5SDimitry Andricregex_search(const basic_string<_CharT, _ST, _SA>& __s,
52170b57cec5SDimitry Andric             const basic_regex<_CharT, _Traits>& __e,
5218cb14a3feSDimitry Andric             regex_constants::match_flag_type __flags = regex_constants::match_default) {
52190b57cec5SDimitry Andric  match_results<const _CharT*> __mc;
52200b57cec5SDimitry Andric  return __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags);
52210b57cec5SDimitry Andric}
52220b57cec5SDimitry Andric
52230b57cec5SDimitry Andrictemplate <class _ST, class _SA, class _Allocator, class _CharT, class _Traits>
5224cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool
52250b57cec5SDimitry Andricregex_search(const basic_string<_CharT, _ST, _SA>& __s,
52260b57cec5SDimitry Andric             match_results<typename basic_string<_CharT, _ST, _SA>::const_iterator, _Allocator>& __m,
52270b57cec5SDimitry Andric             const basic_regex<_CharT, _Traits>& __e,
5228cb14a3feSDimitry Andric             regex_constants::match_flag_type __flags = regex_constants::match_default) {
52290b57cec5SDimitry Andric  match_results<const _CharT*> __mc;
52300b57cec5SDimitry Andric  bool __r = __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags);
52310b57cec5SDimitry Andric  __m.__assign(__s.begin(), __s.end(), __mc, __flags & regex_constants::__no_update_pos);
52320b57cec5SDimitry Andric  return __r;
52330b57cec5SDimitry Andric}
52340b57cec5SDimitry Andric
523506c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 14
52360b57cec5SDimitry Andrictemplate <class _ST, class _SA, class _Ap, class _Cp, class _Tp>
5237cb14a3feSDimitry Andricbool regex_search(const basic_string<_Cp, _ST, _SA>&& __s,
52380b57cec5SDimitry Andric                  match_results<typename basic_string<_Cp, _ST, _SA>::const_iterator, _Ap>&,
52390b57cec5SDimitry Andric                  const basic_regex<_Cp, _Tp>& __e,
52400b57cec5SDimitry Andric                  regex_constants::match_flag_type __flags = regex_constants::match_default) = delete;
52410b57cec5SDimitry Andric#endif
52420b57cec5SDimitry Andric
52430b57cec5SDimitry Andric// regex_match
52440b57cec5SDimitry Andric
52450b57cec5SDimitry Andrictemplate <class _BidirectionalIterator, class _Allocator, class _CharT, class _Traits>
5246bdd1243dSDimitry Andric_LIBCPP_HIDE_FROM_ABI bool
5247cb14a3feSDimitry Andricregex_match(_BidirectionalIterator __first,
5248cb14a3feSDimitry Andric            _BidirectionalIterator __last,
52490b57cec5SDimitry Andric            match_results<_BidirectionalIterator, _Allocator>& __m,
52500b57cec5SDimitry Andric            const basic_regex<_CharT, _Traits>& __e,
5251cb14a3feSDimitry Andric            regex_constants::match_flag_type __flags = regex_constants::match_default) {
52525f757f3fSDimitry Andric  bool __r = std::regex_search(
5253cb14a3feSDimitry Andric      __first, __last, __m, __e, __flags | regex_constants::match_continuous | regex_constants::__full_match);
5254cb14a3feSDimitry Andric  if (__r) {
52550b57cec5SDimitry Andric    __r = !__m.suffix().matched;
52560b57cec5SDimitry Andric    if (!__r)
52570b57cec5SDimitry Andric      __m.__matches_.clear();
52580b57cec5SDimitry Andric  }
52590b57cec5SDimitry Andric  return __r;
52600b57cec5SDimitry Andric}
52610b57cec5SDimitry Andric
52620b57cec5SDimitry Andrictemplate <class _BidirectionalIterator, class _CharT, class _Traits>
5263cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool
5264cb14a3feSDimitry Andricregex_match(_BidirectionalIterator __first,
5265cb14a3feSDimitry Andric            _BidirectionalIterator __last,
52660b57cec5SDimitry Andric            const basic_regex<_CharT, _Traits>& __e,
5267cb14a3feSDimitry Andric            regex_constants::match_flag_type __flags = regex_constants::match_default) {
52680b57cec5SDimitry Andric  match_results<_BidirectionalIterator> __m;
52695f757f3fSDimitry Andric  return std::regex_match(__first, __last, __m, __e, __flags);
52700b57cec5SDimitry Andric}
52710b57cec5SDimitry Andric
52720b57cec5SDimitry Andrictemplate <class _CharT, class _Allocator, class _Traits>
5273cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool
5274cb14a3feSDimitry Andricregex_match(const _CharT* __str,
5275cb14a3feSDimitry Andric            match_results<const _CharT*, _Allocator>& __m,
52760b57cec5SDimitry Andric            const basic_regex<_CharT, _Traits>& __e,
5277cb14a3feSDimitry Andric            regex_constants::match_flag_type __flags = regex_constants::match_default) {
52785f757f3fSDimitry Andric  return std::regex_match(__str, __str + _Traits::length(__str), __m, __e, __flags);
52790b57cec5SDimitry Andric}
52800b57cec5SDimitry Andric
52810b57cec5SDimitry Andrictemplate <class _ST, class _SA, class _Allocator, class _CharT, class _Traits>
5282cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool
52830b57cec5SDimitry Andricregex_match(const basic_string<_CharT, _ST, _SA>& __s,
52840b57cec5SDimitry Andric            match_results<typename basic_string<_CharT, _ST, _SA>::const_iterator, _Allocator>& __m,
52850b57cec5SDimitry Andric            const basic_regex<_CharT, _Traits>& __e,
5286cb14a3feSDimitry Andric            regex_constants::match_flag_type __flags = regex_constants::match_default) {
52875f757f3fSDimitry Andric  return std::regex_match(__s.begin(), __s.end(), __m, __e, __flags);
52880b57cec5SDimitry Andric}
52890b57cec5SDimitry Andric
529006c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 14
52910b57cec5SDimitry Andrictemplate <class _ST, class _SA, class _Allocator, class _CharT, class _Traits>
5292cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool
52930b57cec5SDimitry Andricregex_match(const basic_string<_CharT, _ST, _SA>&& __s,
52940b57cec5SDimitry Andric            match_results<typename basic_string<_CharT, _ST, _SA>::const_iterator, _Allocator>& __m,
52950b57cec5SDimitry Andric            const basic_regex<_CharT, _Traits>& __e,
52960b57cec5SDimitry Andric            regex_constants::match_flag_type __flags = regex_constants::match_default) = delete;
52970b57cec5SDimitry Andric#endif
52980b57cec5SDimitry Andric
52990b57cec5SDimitry Andrictemplate <class _CharT, class _Traits>
5300cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool
5301cb14a3feSDimitry Andricregex_match(const _CharT* __str,
5302cb14a3feSDimitry Andric            const basic_regex<_CharT, _Traits>& __e,
5303cb14a3feSDimitry Andric            regex_constants::match_flag_type __flags = regex_constants::match_default) {
53045f757f3fSDimitry Andric  return std::regex_match(__str, __str + _Traits::length(__str), __e, __flags);
53050b57cec5SDimitry Andric}
53060b57cec5SDimitry Andric
53070b57cec5SDimitry Andrictemplate <class _ST, class _SA, class _CharT, class _Traits>
5308cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI bool
53090b57cec5SDimitry Andricregex_match(const basic_string<_CharT, _ST, _SA>& __s,
53100b57cec5SDimitry Andric            const basic_regex<_CharT, _Traits>& __e,
5311cb14a3feSDimitry Andric            regex_constants::match_flag_type __flags = regex_constants::match_default) {
53125f757f3fSDimitry Andric  return std::regex_match(__s.begin(), __s.end(), __e, __flags);
53130b57cec5SDimitry Andric}
53140b57cec5SDimitry Andric
53150b57cec5SDimitry Andric// regex_iterator
53160b57cec5SDimitry Andric
53170b57cec5SDimitry Andrictemplate <class _BidirectionalIterator,
53180b57cec5SDimitry Andric          class _CharT  = typename iterator_traits<_BidirectionalIterator>::value_type,
53190b57cec5SDimitry Andric          class _Traits = regex_traits<_CharT> >
5320e8d8bef9SDimitry Andricclass _LIBCPP_TEMPLATE_VIS regex_iterator;
5321e8d8bef9SDimitry Andric
5322e8d8bef9SDimitry Andrictypedef regex_iterator<const char*> cregex_iterator;
5323e8d8bef9SDimitry Andrictypedef regex_iterator<string::const_iterator> sregex_iterator;
5324349cc55cSDimitry Andric#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
5325349cc55cSDimitry Andrictypedef regex_iterator<const wchar_t*> wcregex_iterator;
5326e8d8bef9SDimitry Andrictypedef regex_iterator<wstring::const_iterator> wsregex_iterator;
5327349cc55cSDimitry Andric#endif
5328e8d8bef9SDimitry Andric
5329e8d8bef9SDimitry Andrictemplate <class _BidirectionalIterator, class _CharT, class _Traits>
5330cb14a3feSDimitry Andricclass _LIBCPP_TEMPLATE_VIS _LIBCPP_PREFERRED_NAME(cregex_iterator)
5331cb14a3feSDimitry Andric    _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wcregex_iterator)) _LIBCPP_PREFERRED_NAME(sregex_iterator)
5332cb14a3feSDimitry Andric        _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wsregex_iterator)) regex_iterator {
53330b57cec5SDimitry Andricpublic:
53340b57cec5SDimitry Andric  typedef basic_regex<_CharT, _Traits> regex_type;
53350b57cec5SDimitry Andric  typedef match_results<_BidirectionalIterator> value_type;
53360b57cec5SDimitry Andric  typedef ptrdiff_t difference_type;
53370b57cec5SDimitry Andric  typedef const value_type* pointer;
53380b57cec5SDimitry Andric  typedef const value_type& reference;
53390b57cec5SDimitry Andric  typedef forward_iterator_tag iterator_category;
53405f757f3fSDimitry Andric#if _LIBCPP_STD_VER >= 20
53415f757f3fSDimitry Andric  typedef input_iterator_tag iterator_concept;
53425f757f3fSDimitry Andric#endif
53430b57cec5SDimitry Andric
53440b57cec5SDimitry Andricprivate:
53450b57cec5SDimitry Andric  _BidirectionalIterator __begin_;
53460b57cec5SDimitry Andric  _BidirectionalIterator __end_;
53470b57cec5SDimitry Andric  const regex_type* __pregex_;
53480b57cec5SDimitry Andric  regex_constants::match_flag_type __flags_;
53490b57cec5SDimitry Andric  value_type __match_;
53500b57cec5SDimitry Andric
53510b57cec5SDimitry Andricpublic:
53520b57cec5SDimitry Andric  regex_iterator();
5353cb14a3feSDimitry Andric  regex_iterator(_BidirectionalIterator __a,
5354cb14a3feSDimitry Andric                 _BidirectionalIterator __b,
53550b57cec5SDimitry Andric                 const regex_type& __re,
5356cb14a3feSDimitry Andric                 regex_constants::match_flag_type __m = regex_constants::match_default);
535706c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 14
5358cb14a3feSDimitry Andric  regex_iterator(_BidirectionalIterator __a,
5359cb14a3feSDimitry Andric                 _BidirectionalIterator __b,
53600b57cec5SDimitry Andric                 const regex_type&& __re,
5361cb14a3feSDimitry Andric                 regex_constants::match_flag_type __m = regex_constants::match_default) = delete;
53620b57cec5SDimitry Andric#endif
53630b57cec5SDimitry Andric
536406c3fb27SDimitry Andric  _LIBCPP_HIDE_FROM_ABI bool operator==(const regex_iterator& __x) const;
536506c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 20
536606c3fb27SDimitry Andric  _LIBCPP_HIDE_FROM_ABI bool operator==(default_sentinel_t) const { return *this == regex_iterator(); }
536706c3fb27SDimitry Andric#endif
536806c3fb27SDimitry Andric#if _LIBCPP_STD_VER < 20
5369cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI bool operator!=(const regex_iterator& __x) const { return !(*this == __x); }
537006c3fb27SDimitry Andric#endif
53710b57cec5SDimitry Andric
5372cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI reference operator*() const { return __match_; }
5373cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI pointer operator->() const { return std::addressof(__match_); }
53740b57cec5SDimitry Andric
53750b57cec5SDimitry Andric  regex_iterator& operator++();
5376cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI regex_iterator operator++(int) {
53770b57cec5SDimitry Andric    regex_iterator __t(*this);
53780b57cec5SDimitry Andric    ++(*this);
53790b57cec5SDimitry Andric    return __t;
53800b57cec5SDimitry Andric  }
53810b57cec5SDimitry Andric};
53820b57cec5SDimitry Andric
53830b57cec5SDimitry Andrictemplate <class _BidirectionalIterator, class _CharT, class _Traits>
53840b57cec5SDimitry Andricregex_iterator<_BidirectionalIterator, _CharT, _Traits>::regex_iterator()
5385cb14a3feSDimitry Andric    : __begin_(), __end_(), __pregex_(nullptr), __flags_(), __match_() {}
53860b57cec5SDimitry Andric
53870b57cec5SDimitry Andrictemplate <class _BidirectionalIterator, class _CharT, class _Traits>
5388cb14a3feSDimitry Andricregex_iterator<_BidirectionalIterator, _CharT, _Traits>::regex_iterator(
5389cb14a3feSDimitry Andric    _BidirectionalIterator __a,
5390cb14a3feSDimitry Andric    _BidirectionalIterator __b,
5391cb14a3feSDimitry Andric    const regex_type& __re,
5392cb14a3feSDimitry Andric    regex_constants::match_flag_type __m)
5393cb14a3feSDimitry Andric    : __begin_(__a), __end_(__b), __pregex_(std::addressof(__re)), __flags_(__m) {
53945f757f3fSDimitry Andric  std::regex_search(__begin_, __end_, __match_, *__pregex_, __flags_);
53950b57cec5SDimitry Andric}
53960b57cec5SDimitry Andric
53970b57cec5SDimitry Andrictemplate <class _BidirectionalIterator, class _CharT, class _Traits>
5398cb14a3feSDimitry Andricbool regex_iterator<_BidirectionalIterator, _CharT, _Traits>::operator==(const regex_iterator& __x) const {
53990b57cec5SDimitry Andric  if (__match_.empty() && __x.__match_.empty())
54000b57cec5SDimitry Andric    return true;
54010b57cec5SDimitry Andric  if (__match_.empty() || __x.__match_.empty())
54020b57cec5SDimitry Andric    return false;
5403cb14a3feSDimitry Andric  return __begin_ == __x.__begin_ && __end_ == __x.__end_ && __pregex_ == __x.__pregex_ && __flags_ == __x.__flags_ &&
54040b57cec5SDimitry Andric         __match_[0] == __x.__match_[0];
54050b57cec5SDimitry Andric}
54060b57cec5SDimitry Andric
54070b57cec5SDimitry Andrictemplate <class _BidirectionalIterator, class _CharT, class _Traits>
54080b57cec5SDimitry Andricregex_iterator<_BidirectionalIterator, _CharT, _Traits>&
5409cb14a3feSDimitry Andricregex_iterator<_BidirectionalIterator, _CharT, _Traits>::operator++() {
54100b57cec5SDimitry Andric  __flags_ |= regex_constants::__no_update_pos;
54110b57cec5SDimitry Andric  _BidirectionalIterator __start        = __match_[0].second;
5412*0fca6ea1SDimitry Andric  _BidirectionalIterator __prefix_start = __start;
5413*0fca6ea1SDimitry Andric
5414cb14a3feSDimitry Andric  if (__match_[0].first == __match_[0].second) {
5415cb14a3feSDimitry Andric    if (__start == __end_) {
54160b57cec5SDimitry Andric      __match_ = value_type();
54170b57cec5SDimitry Andric      return *this;
5418cb14a3feSDimitry Andric    } else if (std::regex_search(__start,
5419cb14a3feSDimitry Andric                                 __end_,
5420cb14a3feSDimitry Andric                                 __match_,
5421cb14a3feSDimitry Andric                                 *__pregex_,
5422cb14a3feSDimitry Andric                                 __flags_ | regex_constants::match_not_null | regex_constants::match_continuous))
54230b57cec5SDimitry Andric      return *this;
54240b57cec5SDimitry Andric    else
54250b57cec5SDimitry Andric      ++__start;
54260b57cec5SDimitry Andric  }
5427*0fca6ea1SDimitry Andric
54280b57cec5SDimitry Andric  __flags_ |= regex_constants::match_prev_avail;
5429*0fca6ea1SDimitry Andric  if (!std::regex_search(__start, __end_, __match_, *__pregex_, __flags_)) {
54300b57cec5SDimitry Andric    __match_ = value_type();
5431*0fca6ea1SDimitry Andric
5432*0fca6ea1SDimitry Andric  } else {
5433*0fca6ea1SDimitry Andric    // The Standard mandates that if `regex_search` returns true ([re.regiter.incr]), "`match.prefix().first` shall be
5434*0fca6ea1SDimitry Andric    // equal to the previous value of `match[0].second`... It is unspecified how the implementation makes these
5435*0fca6ea1SDimitry Andric    // adjustments." The adjustment is necessary if we incremented `__start` above (the branch that deals with
5436*0fca6ea1SDimitry Andric    // zero-length matches).
5437*0fca6ea1SDimitry Andric    auto& __prefix   = __match_.__prefix_;
5438*0fca6ea1SDimitry Andric    __prefix.first   = __prefix_start;
5439*0fca6ea1SDimitry Andric    __prefix.matched = __prefix.first != __prefix.second;
5440*0fca6ea1SDimitry Andric  }
5441*0fca6ea1SDimitry Andric
54420b57cec5SDimitry Andric  return *this;
54430b57cec5SDimitry Andric}
54440b57cec5SDimitry Andric
54450b57cec5SDimitry Andric// regex_token_iterator
54460b57cec5SDimitry Andric
54470b57cec5SDimitry Andrictemplate <class _BidirectionalIterator,
54480b57cec5SDimitry Andric          class _CharT  = typename iterator_traits<_BidirectionalIterator>::value_type,
54490b57cec5SDimitry Andric          class _Traits = regex_traits<_CharT> >
5450e8d8bef9SDimitry Andricclass _LIBCPP_TEMPLATE_VIS regex_token_iterator;
5451e8d8bef9SDimitry Andric
5452e8d8bef9SDimitry Andrictypedef regex_token_iterator<const char*> cregex_token_iterator;
5453e8d8bef9SDimitry Andrictypedef regex_token_iterator<string::const_iterator> sregex_token_iterator;
5454349cc55cSDimitry Andric#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
5455349cc55cSDimitry Andrictypedef regex_token_iterator<const wchar_t*> wcregex_token_iterator;
5456e8d8bef9SDimitry Andrictypedef regex_token_iterator<wstring::const_iterator> wsregex_token_iterator;
5457349cc55cSDimitry Andric#endif
5458e8d8bef9SDimitry Andric
5459e8d8bef9SDimitry Andrictemplate <class _BidirectionalIterator, class _CharT, class _Traits>
5460cb14a3feSDimitry Andricclass _LIBCPP_TEMPLATE_VIS _LIBCPP_PREFERRED_NAME(cregex_token_iterator)
5461349cc55cSDimitry Andric    _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wcregex_token_iterator))
5462e8d8bef9SDimitry Andric        _LIBCPP_PREFERRED_NAME(sregex_token_iterator)
5463cb14a3feSDimitry Andric            _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wsregex_token_iterator)) regex_token_iterator {
54640b57cec5SDimitry Andricpublic:
54650b57cec5SDimitry Andric  typedef basic_regex<_CharT, _Traits> regex_type;
54660b57cec5SDimitry Andric  typedef sub_match<_BidirectionalIterator> value_type;
54670b57cec5SDimitry Andric  typedef ptrdiff_t difference_type;
54680b57cec5SDimitry Andric  typedef const value_type* pointer;
54690b57cec5SDimitry Andric  typedef const value_type& reference;
54700b57cec5SDimitry Andric  typedef forward_iterator_tag iterator_category;
54715f757f3fSDimitry Andric#if _LIBCPP_STD_VER >= 20
54725f757f3fSDimitry Andric  typedef input_iterator_tag iterator_concept;
54735f757f3fSDimitry Andric#endif
54740b57cec5SDimitry Andric
54750b57cec5SDimitry Andricprivate:
54760b57cec5SDimitry Andric  typedef regex_iterator<_BidirectionalIterator, _CharT, _Traits> _Position;
54770b57cec5SDimitry Andric
54780b57cec5SDimitry Andric  _Position __position_;
54790b57cec5SDimitry Andric  const value_type* __result_;
54800b57cec5SDimitry Andric  value_type __suffix_;
54810b57cec5SDimitry Andric  ptrdiff_t __n_;
54820b57cec5SDimitry Andric  vector<int> __subs_;
54830b57cec5SDimitry Andric
54840b57cec5SDimitry Andricpublic:
54850b57cec5SDimitry Andric  regex_token_iterator();
5486cb14a3feSDimitry Andric  regex_token_iterator(_BidirectionalIterator __a,
5487cb14a3feSDimitry Andric                       _BidirectionalIterator __b,
5488cb14a3feSDimitry Andric                       const regex_type& __re,
5489cb14a3feSDimitry Andric                       int __submatch                       = 0,
5490cb14a3feSDimitry Andric                       regex_constants::match_flag_type __m = regex_constants::match_default);
549106c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 14
5492cb14a3feSDimitry Andric  regex_token_iterator(_BidirectionalIterator __a,
5493cb14a3feSDimitry Andric                       _BidirectionalIterator __b,
5494cb14a3feSDimitry Andric                       const regex_type&& __re,
5495cb14a3feSDimitry Andric                       int __submatch                       = 0,
5496cb14a3feSDimitry Andric                       regex_constants::match_flag_type __m = regex_constants::match_default) = delete;
54970b57cec5SDimitry Andric#endif
54980b57cec5SDimitry Andric
5499cb14a3feSDimitry Andric  regex_token_iterator(_BidirectionalIterator __a,
5500cb14a3feSDimitry Andric                       _BidirectionalIterator __b,
5501cb14a3feSDimitry Andric                       const regex_type& __re,
5502cb14a3feSDimitry Andric                       const vector<int>& __submatches,
5503cb14a3feSDimitry Andric                       regex_constants::match_flag_type __m = regex_constants::match_default);
550406c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 14
5505cb14a3feSDimitry Andric  regex_token_iterator(_BidirectionalIterator __a,
5506cb14a3feSDimitry Andric                       _BidirectionalIterator __b,
5507cb14a3feSDimitry Andric                       const regex_type&& __re,
5508cb14a3feSDimitry Andric                       const vector<int>& __submatches,
5509cb14a3feSDimitry Andric                       regex_constants::match_flag_type __m = regex_constants::match_default) = delete;
55100b57cec5SDimitry Andric#endif
55110b57cec5SDimitry Andric
55120b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
5513cb14a3feSDimitry Andric  regex_token_iterator(_BidirectionalIterator __a,
5514cb14a3feSDimitry Andric                       _BidirectionalIterator __b,
55150b57cec5SDimitry Andric                       const regex_type& __re,
55160b57cec5SDimitry Andric                       initializer_list<int> __submatches,
5517cb14a3feSDimitry Andric                       regex_constants::match_flag_type __m = regex_constants::match_default);
55180b57cec5SDimitry Andric
551906c3fb27SDimitry Andric#  if _LIBCPP_STD_VER >= 14
5520cb14a3feSDimitry Andric  regex_token_iterator(_BidirectionalIterator __a,
5521cb14a3feSDimitry Andric                       _BidirectionalIterator __b,
55220b57cec5SDimitry Andric                       const regex_type&& __re,
55230b57cec5SDimitry Andric                       initializer_list<int> __submatches,
5524cb14a3feSDimitry Andric                       regex_constants::match_flag_type __m = regex_constants::match_default) = delete;
55250b57cec5SDimitry Andric#  endif
55260b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG
55270b57cec5SDimitry Andric  template <size_t _Np>
55280b57cec5SDimitry Andric  regex_token_iterator(_BidirectionalIterator __a,
55290b57cec5SDimitry Andric                       _BidirectionalIterator __b,
55300b57cec5SDimitry Andric                       const regex_type& __re,
55310b57cec5SDimitry Andric                       const int (&__submatches)[_Np],
5532cb14a3feSDimitry Andric                       regex_constants::match_flag_type __m = regex_constants::match_default);
553306c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 14
5534e8d8bef9SDimitry Andric  template <size_t _Np>
55350b57cec5SDimitry Andric  regex_token_iterator(_BidirectionalIterator __a,
55360b57cec5SDimitry Andric                       _BidirectionalIterator __b,
55370b57cec5SDimitry Andric                       const regex_type&& __re,
55380b57cec5SDimitry Andric                       const int (&__submatches)[_Np],
5539cb14a3feSDimitry Andric                       regex_constants::match_flag_type __m = regex_constants::match_default) = delete;
55400b57cec5SDimitry Andric#endif
55410b57cec5SDimitry Andric
55420b57cec5SDimitry Andric  regex_token_iterator(const regex_token_iterator&);
55430b57cec5SDimitry Andric  regex_token_iterator& operator=(const regex_token_iterator&);
55440b57cec5SDimitry Andric
554506c3fb27SDimitry Andric  _LIBCPP_HIDE_FROM_ABI bool operator==(const regex_token_iterator& __x) const;
554606c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 20
554706c3fb27SDimitry Andric  _LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDE_FROM_ABI bool operator==(default_sentinel_t) const {
554806c3fb27SDimitry Andric    return *this == regex_token_iterator();
554906c3fb27SDimitry Andric  }
555006c3fb27SDimitry Andric#endif
555106c3fb27SDimitry Andric#if _LIBCPP_STD_VER < 20
5552cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI bool operator!=(const regex_token_iterator& __x) const { return !(*this == __x); }
555306c3fb27SDimitry Andric#endif
55540b57cec5SDimitry Andric
5555cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const value_type& operator*() const { return *__result_; }
5556cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI const value_type* operator->() const { return __result_; }
55570b57cec5SDimitry Andric
55580b57cec5SDimitry Andric  regex_token_iterator& operator++();
5559cb14a3feSDimitry Andric  _LIBCPP_HIDE_FROM_ABI regex_token_iterator operator++(int) {
55600b57cec5SDimitry Andric    regex_token_iterator __t(*this);
55610b57cec5SDimitry Andric    ++(*this);
55620b57cec5SDimitry Andric    return __t;
55630b57cec5SDimitry Andric  }
55640b57cec5SDimitry Andric
55650b57cec5SDimitry Andricprivate:
55660b57cec5SDimitry Andric  void __init(_BidirectionalIterator __a, _BidirectionalIterator __b);
55670b57cec5SDimitry Andric  void __establish_result() {
55680b57cec5SDimitry Andric    if (__subs_[__n_] == -1)
55690b57cec5SDimitry Andric      __result_ = &__position_->prefix();
55700b57cec5SDimitry Andric    else
55710b57cec5SDimitry Andric      __result_ = &(*__position_)[__subs_[__n_]];
55720b57cec5SDimitry Andric  }
55730b57cec5SDimitry Andric};
55740b57cec5SDimitry Andric
55750b57cec5SDimitry Andrictemplate <class _BidirectionalIterator, class _CharT, class _Traits>
5576cb14a3feSDimitry Andricregex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::regex_token_iterator()
5577cb14a3feSDimitry Andric    : __result_(nullptr), __suffix_(), __n_(0) {}
55780b57cec5SDimitry Andric
55790b57cec5SDimitry Andrictemplate <class _BidirectionalIterator, class _CharT, class _Traits>
5580cb14a3feSDimitry Andricvoid regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::__init(
5581cb14a3feSDimitry Andric    _BidirectionalIterator __a, _BidirectionalIterator __b) {
55820b57cec5SDimitry Andric  if (__position_ != _Position())
55830b57cec5SDimitry Andric    __establish_result();
5584cb14a3feSDimitry Andric  else if (__subs_[__n_] == -1) {
55850b57cec5SDimitry Andric    __suffix_.matched = true;
55860b57cec5SDimitry Andric    __suffix_.first   = __a;
55870b57cec5SDimitry Andric    __suffix_.second  = __b;
55880b57cec5SDimitry Andric    __result_         = &__suffix_;
5589cb14a3feSDimitry Andric  } else
55900b57cec5SDimitry Andric    __result_ = nullptr;
55910b57cec5SDimitry Andric}
55920b57cec5SDimitry Andric
55930b57cec5SDimitry Andrictemplate <class _BidirectionalIterator, class _CharT, class _Traits>
5594cb14a3feSDimitry Andricregex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::regex_token_iterator(
5595cb14a3feSDimitry Andric    _BidirectionalIterator __a,
5596cb14a3feSDimitry Andric    _BidirectionalIterator __b,
5597cb14a3feSDimitry Andric    const regex_type& __re,
5598cb14a3feSDimitry Andric    int __submatch,
55990b57cec5SDimitry Andric    regex_constants::match_flag_type __m)
5600cb14a3feSDimitry Andric    : __position_(__a, __b, __re, __m), __n_(0), __subs_(1, __submatch) {
56010b57cec5SDimitry Andric  __init(__a, __b);
56020b57cec5SDimitry Andric}
56030b57cec5SDimitry Andric
56040b57cec5SDimitry Andrictemplate <class _BidirectionalIterator, class _CharT, class _Traits>
5605cb14a3feSDimitry Andricregex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::regex_token_iterator(
5606cb14a3feSDimitry Andric    _BidirectionalIterator __a,
5607cb14a3feSDimitry Andric    _BidirectionalIterator __b,
5608cb14a3feSDimitry Andric    const regex_type& __re,
5609cb14a3feSDimitry Andric    const vector<int>& __submatches,
56100b57cec5SDimitry Andric    regex_constants::match_flag_type __m)
5611cb14a3feSDimitry Andric    : __position_(__a, __b, __re, __m), __n_(0), __subs_(__submatches) {
56120b57cec5SDimitry Andric  __init(__a, __b);
56130b57cec5SDimitry Andric}
56140b57cec5SDimitry Andric
56150b57cec5SDimitry Andric#ifndef _LIBCPP_CXX03_LANG
56160b57cec5SDimitry Andric
56170b57cec5SDimitry Andrictemplate <class _BidirectionalIterator, class _CharT, class _Traits>
5618cb14a3feSDimitry Andricregex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::regex_token_iterator(
5619cb14a3feSDimitry Andric    _BidirectionalIterator __a,
5620cb14a3feSDimitry Andric    _BidirectionalIterator __b,
56210b57cec5SDimitry Andric    const regex_type& __re,
56220b57cec5SDimitry Andric    initializer_list<int> __submatches,
56230b57cec5SDimitry Andric    regex_constants::match_flag_type __m)
5624cb14a3feSDimitry Andric    : __position_(__a, __b, __re, __m), __n_(0), __subs_(__submatches) {
56250b57cec5SDimitry Andric  __init(__a, __b);
56260b57cec5SDimitry Andric}
56270b57cec5SDimitry Andric
56280b57cec5SDimitry Andric#endif // _LIBCPP_CXX03_LANG
56290b57cec5SDimitry Andric
56300b57cec5SDimitry Andrictemplate <class _BidirectionalIterator, class _CharT, class _Traits>
56310b57cec5SDimitry Andrictemplate <size_t _Np>
5632cb14a3feSDimitry Andricregex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::regex_token_iterator(
5633cb14a3feSDimitry Andric    _BidirectionalIterator __a,
5634cb14a3feSDimitry Andric    _BidirectionalIterator __b,
56350b57cec5SDimitry Andric    const regex_type& __re,
56360b57cec5SDimitry Andric    const int (&__submatches)[_Np],
56370b57cec5SDimitry Andric    regex_constants::match_flag_type __m)
5638cb14a3feSDimitry Andric    : __position_(__a, __b, __re, __m), __n_(0), __subs_(begin(__submatches), end(__submatches)) {
56390b57cec5SDimitry Andric  __init(__a, __b);
56400b57cec5SDimitry Andric}
56410b57cec5SDimitry Andric
56420b57cec5SDimitry Andrictemplate <class _BidirectionalIterator, class _CharT, class _Traits>
5643cb14a3feSDimitry Andricregex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::regex_token_iterator(const regex_token_iterator& __x)
56440b57cec5SDimitry Andric    : __position_(__x.__position_),
56450b57cec5SDimitry Andric      __result_(__x.__result_),
56460b57cec5SDimitry Andric      __suffix_(__x.__suffix_),
56470b57cec5SDimitry Andric      __n_(__x.__n_),
5648cb14a3feSDimitry Andric      __subs_(__x.__subs_) {
56490b57cec5SDimitry Andric  if (__x.__result_ == &__x.__suffix_)
56500b57cec5SDimitry Andric    __result_ = &__suffix_;
56510b57cec5SDimitry Andric  else if (__result_ != nullptr)
56520b57cec5SDimitry Andric    __establish_result();
56530b57cec5SDimitry Andric}
56540b57cec5SDimitry Andric
56550b57cec5SDimitry Andrictemplate <class _BidirectionalIterator, class _CharT, class _Traits>
56560b57cec5SDimitry Andricregex_token_iterator<_BidirectionalIterator, _CharT, _Traits>&
5657cb14a3feSDimitry Andricregex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::operator=(const regex_token_iterator& __x) {
5658cb14a3feSDimitry Andric  if (this != &__x) {
56590b57cec5SDimitry Andric    __position_ = __x.__position_;
56600b57cec5SDimitry Andric    if (__x.__result_ == &__x.__suffix_)
56610b57cec5SDimitry Andric      __result_ = &__suffix_;
56620b57cec5SDimitry Andric    else
56630b57cec5SDimitry Andric      __result_ = __x.__result_;
56640b57cec5SDimitry Andric    __suffix_ = __x.__suffix_;
56650b57cec5SDimitry Andric    __n_      = __x.__n_;
56660b57cec5SDimitry Andric    __subs_   = __x.__subs_;
56670b57cec5SDimitry Andric
56680b57cec5SDimitry Andric    if (__result_ != nullptr && __result_ != &__suffix_)
56690b57cec5SDimitry Andric      __establish_result();
56700b57cec5SDimitry Andric  }
56710b57cec5SDimitry Andric  return *this;
56720b57cec5SDimitry Andric}
56730b57cec5SDimitry Andric
56740b57cec5SDimitry Andrictemplate <class _BidirectionalIterator, class _CharT, class _Traits>
5675cb14a3feSDimitry Andricbool regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::operator==(const regex_token_iterator& __x) const {
56760b57cec5SDimitry Andric  if (__result_ == nullptr && __x.__result_ == nullptr)
56770b57cec5SDimitry Andric    return true;
5678cb14a3feSDimitry Andric  if (__result_ == &__suffix_ && __x.__result_ == &__x.__suffix_ && __suffix_ == __x.__suffix_)
56790b57cec5SDimitry Andric    return true;
56800b57cec5SDimitry Andric  if (__result_ == nullptr || __x.__result_ == nullptr)
56810b57cec5SDimitry Andric    return false;
56820b57cec5SDimitry Andric  if (__result_ == &__suffix_ || __x.__result_ == &__x.__suffix_)
56830b57cec5SDimitry Andric    return false;
5684cb14a3feSDimitry Andric  return __position_ == __x.__position_ && __n_ == __x.__n_ && __subs_ == __x.__subs_;
56850b57cec5SDimitry Andric}
56860b57cec5SDimitry Andric
56870b57cec5SDimitry Andrictemplate <class _BidirectionalIterator, class _CharT, class _Traits>
56880b57cec5SDimitry Andricregex_token_iterator<_BidirectionalIterator, _CharT, _Traits>&
5689cb14a3feSDimitry Andricregex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::operator++() {
56900b57cec5SDimitry Andric  _Position __prev = __position_;
56910b57cec5SDimitry Andric  if (__result_ == &__suffix_)
56920b57cec5SDimitry Andric    __result_ = nullptr;
5693cb14a3feSDimitry Andric  else if (static_cast<size_t>(__n_ + 1) < __subs_.size()) {
56940b57cec5SDimitry Andric    ++__n_;
56950b57cec5SDimitry Andric    __establish_result();
5696cb14a3feSDimitry Andric  } else {
56970b57cec5SDimitry Andric    __n_ = 0;
56980b57cec5SDimitry Andric    ++__position_;
56990b57cec5SDimitry Andric    if (__position_ != _Position())
57000b57cec5SDimitry Andric      __establish_result();
5701cb14a3feSDimitry Andric    else {
5702cb14a3feSDimitry Andric      if (std::find(__subs_.begin(), __subs_.end(), -1) != __subs_.end() && __prev->suffix().length() != 0) {
57030b57cec5SDimitry Andric        __suffix_.matched = true;
57040b57cec5SDimitry Andric        __suffix_.first   = __prev->suffix().first;
57050b57cec5SDimitry Andric        __suffix_.second  = __prev->suffix().second;
57060b57cec5SDimitry Andric        __result_         = &__suffix_;
5707cb14a3feSDimitry Andric      } else
57080b57cec5SDimitry Andric        __result_ = nullptr;
57090b57cec5SDimitry Andric    }
57100b57cec5SDimitry Andric  }
57110b57cec5SDimitry Andric  return *this;
57120b57cec5SDimitry Andric}
57130b57cec5SDimitry Andric
57140b57cec5SDimitry Andric// regex_replace
57150b57cec5SDimitry Andric
5716cb14a3feSDimitry Andrictemplate <class _OutputIterator, class _BidirectionalIterator, class _Traits, class _CharT>
5717cb14a3feSDimitry Andric_LIBCPP_HIDE_FROM_ABI _OutputIterator regex_replace(
5718cb14a3feSDimitry Andric    _OutputIterator __output_iter,
5719cb14a3feSDimitry Andric    _BidirectionalIterator __first,
5720cb14a3feSDimitry Andric    _BidirectionalIterator __last,
5721cb14a3feSDimitry Andric    const basic_regex<_CharT, _Traits>& __e,
5722cb14a3feSDimitry Andric    const _CharT* __fmt,
5723cb14a3feSDimitry Andric    regex_constants::match_flag_type __flags = regex_constants::match_default) {
57240b57cec5SDimitry Andric  typedef regex_iterator<_BidirectionalIterator, _CharT, _Traits> _Iter;
57250b57cec5SDimitry Andric  _Iter __i(__first, __last, __e, __flags);
57260b57cec5SDimitry Andric  _Iter __eof;
5727cb14a3feSDimitry Andric  if (__i == __eof) {
57280b57cec5SDimitry Andric    if (!(__flags & regex_constants::format_no_copy))
57295f757f3fSDimitry Andric      __output_iter = std::copy(__first, __last, __output_iter);
5730cb14a3feSDimitry Andric  } else {
57310b57cec5SDimitry Andric    sub_match<_BidirectionalIterator> __lm;
5732cb14a3feSDimitry Andric    for (size_t __len = char_traits<_CharT>::length(__fmt); __i != __eof; ++__i) {
57330b57cec5SDimitry Andric      if (!(__flags & regex_constants::format_no_copy))
57345f757f3fSDimitry Andric        __output_iter = std::copy(__i->prefix().first, __i->prefix().second, __output_iter);
57350b57cec5SDimitry Andric      __output_iter = __i->format(__output_iter, __fmt, __fmt + __len, __flags);
57360b57cec5SDimitry Andric      __lm          = __i->suffix();
57370b57cec5SDimitry Andric      if (__flags & regex_constants::format_first_only)
57380b57cec5SDimitry Andric        break;
57390b57cec5SDimitry Andric    }
57400b57cec5SDimitry Andric    if (!(__flags & regex_constants::format_no_copy))
57415f757f3fSDimitry Andric      __output_iter = std::copy(__lm.first, __lm.second, __output_iter);
57420b57cec5SDimitry Andric  }
57430b57cec5SDimitry Andric  return __output_iter;
57440b57cec5SDimitry Andric}
57450b57cec5SDimitry Andric
5746cb14a3feSDimitry Andrictemplate <class _OutputIterator, class _BidirectionalIterator, class _Traits, class _CharT, class _ST, class _SA>
5747cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI _OutputIterator regex_replace(
5748cb14a3feSDimitry Andric    _OutputIterator __output_iter,
5749cb14a3feSDimitry Andric    _BidirectionalIterator __first,
5750cb14a3feSDimitry Andric    _BidirectionalIterator __last,
57510b57cec5SDimitry Andric    const basic_regex<_CharT, _Traits>& __e,
57520b57cec5SDimitry Andric    const basic_string<_CharT, _ST, _SA>& __fmt,
5753cb14a3feSDimitry Andric    regex_constants::match_flag_type __flags = regex_constants::match_default) {
57545f757f3fSDimitry Andric  return std::regex_replace(__output_iter, __first, __last, __e, __fmt.c_str(), __flags);
57550b57cec5SDimitry Andric}
57560b57cec5SDimitry Andric
5757cb14a3feSDimitry Andrictemplate <class _Traits, class _CharT, class _ST, class _SA, class _FST, class _FSA>
5758cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI basic_string<_CharT, _ST, _SA>
57590b57cec5SDimitry Andricregex_replace(const basic_string<_CharT, _ST, _SA>& __s,
57600b57cec5SDimitry Andric              const basic_regex<_CharT, _Traits>& __e,
57610b57cec5SDimitry Andric              const basic_string<_CharT, _FST, _FSA>& __fmt,
5762cb14a3feSDimitry Andric              regex_constants::match_flag_type __flags = regex_constants::match_default) {
57630b57cec5SDimitry Andric  basic_string<_CharT, _ST, _SA> __r;
5764cb14a3feSDimitry Andric  std::regex_replace(std::back_inserter(__r), __s.begin(), __s.end(), __e, __fmt.c_str(), __flags);
57650b57cec5SDimitry Andric  return __r;
57660b57cec5SDimitry Andric}
57670b57cec5SDimitry Andric
57680b57cec5SDimitry Andrictemplate <class _Traits, class _CharT, class _ST, class _SA>
5769cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI basic_string<_CharT, _ST, _SA>
57700b57cec5SDimitry Andricregex_replace(const basic_string<_CharT, _ST, _SA>& __s,
5771cb14a3feSDimitry Andric              const basic_regex<_CharT, _Traits>& __e,
5772cb14a3feSDimitry Andric              const _CharT* __fmt,
5773cb14a3feSDimitry Andric              regex_constants::match_flag_type __flags = regex_constants::match_default) {
57740b57cec5SDimitry Andric  basic_string<_CharT, _ST, _SA> __r;
5775cb14a3feSDimitry Andric  std::regex_replace(std::back_inserter(__r), __s.begin(), __s.end(), __e, __fmt, __flags);
57760b57cec5SDimitry Andric  return __r;
57770b57cec5SDimitry Andric}
57780b57cec5SDimitry Andric
57790b57cec5SDimitry Andrictemplate <class _Traits, class _CharT, class _ST, class _SA>
5780cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI basic_string<_CharT>
57810b57cec5SDimitry Andricregex_replace(const _CharT* __s,
57820b57cec5SDimitry Andric              const basic_regex<_CharT, _Traits>& __e,
57830b57cec5SDimitry Andric              const basic_string<_CharT, _ST, _SA>& __fmt,
5784cb14a3feSDimitry Andric              regex_constants::match_flag_type __flags = regex_constants::match_default) {
57850b57cec5SDimitry Andric  basic_string<_CharT> __r;
5786cb14a3feSDimitry Andric  std::regex_replace(std::back_inserter(__r), __s, __s + char_traits<_CharT>::length(__s), __e, __fmt.c_str(), __flags);
57870b57cec5SDimitry Andric  return __r;
57880b57cec5SDimitry Andric}
57890b57cec5SDimitry Andric
57900b57cec5SDimitry Andrictemplate <class _Traits, class _CharT>
5791cb14a3feSDimitry Andricinline _LIBCPP_HIDE_FROM_ABI basic_string<_CharT>
57920b57cec5SDimitry Andricregex_replace(const _CharT* __s,
57930b57cec5SDimitry Andric              const basic_regex<_CharT, _Traits>& __e,
57940b57cec5SDimitry Andric              const _CharT* __fmt,
5795cb14a3feSDimitry Andric              regex_constants::match_flag_type __flags = regex_constants::match_default) {
57960b57cec5SDimitry Andric  basic_string<_CharT> __r;
5797cb14a3feSDimitry Andric  std::regex_replace(std::back_inserter(__r), __s, __s + char_traits<_CharT>::length(__s), __e, __fmt, __flags);
57980b57cec5SDimitry Andric  return __r;
57990b57cec5SDimitry Andric}
58000b57cec5SDimitry Andric
58010b57cec5SDimitry Andric_LIBCPP_END_NAMESPACE_STD
58020b57cec5SDimitry Andric
580306c3fb27SDimitry Andric#if _LIBCPP_STD_VER >= 17
5804bdd1243dSDimitry Andric_LIBCPP_BEGIN_NAMESPACE_STD
5805bdd1243dSDimitry Andricnamespace pmr {
5806bdd1243dSDimitry Andrictemplate <class _BidirT>
5807cb14a3feSDimitry Andricusing match_results _LIBCPP_AVAILABILITY_PMR =
5808cb14a3feSDimitry Andric    std::match_results<_BidirT, polymorphic_allocator<std::sub_match<_BidirT>>>;
5809bdd1243dSDimitry Andric
581006c3fb27SDimitry Andricusing cmatch _LIBCPP_AVAILABILITY_PMR = match_results<const char*>;
581106c3fb27SDimitry Andricusing smatch _LIBCPP_AVAILABILITY_PMR = match_results<std::pmr::string::const_iterator>;
5812bdd1243dSDimitry Andric
5813bdd1243dSDimitry Andric#  ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS
581406c3fb27SDimitry Andricusing wcmatch _LIBCPP_AVAILABILITY_PMR = match_results<const wchar_t*>;
581506c3fb27SDimitry Andricusing wsmatch _LIBCPP_AVAILABILITY_PMR = match_results<std::pmr::wstring::const_iterator>;
5816bdd1243dSDimitry Andric#  endif
5817bdd1243dSDimitry Andric} // namespace pmr
5818bdd1243dSDimitry Andric_LIBCPP_END_NAMESPACE_STD
5819bdd1243dSDimitry Andric#endif
5820bdd1243dSDimitry Andric
58210b57cec5SDimitry Andric_LIBCPP_POP_MACROS
58220b57cec5SDimitry Andric
5823bdd1243dSDimitry Andric#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
5824bdd1243dSDimitry Andric#  include <atomic>
5825bdd1243dSDimitry Andric#  include <concepts>
582606c3fb27SDimitry Andric#  include <cstdlib>
5827bdd1243dSDimitry Andric#  include <iosfwd>
5828bdd1243dSDimitry Andric#  include <iterator>
58295f757f3fSDimitry Andric#  include <mutex>
5830bdd1243dSDimitry Andric#  include <new>
583106c3fb27SDimitry Andric#  include <type_traits>
5832bdd1243dSDimitry Andric#  include <typeinfo>
5833bdd1243dSDimitry Andric#  include <utility>
5834bdd1243dSDimitry Andric#endif
5835bdd1243dSDimitry Andric
58360b57cec5SDimitry Andric#endif // _LIBCPP_REGEX
5837