libstdc++
regex.h
Go to the documentation of this file.
00001 // class template regex -*- C++ -*-
00002 
00003 // Copyright (C) 2010-2014 Free Software Foundation, Inc.
00004 //
00005 // This file is part of the GNU ISO C++ Library.  This library is free
00006 // software; you can redistribute it and/or modify it under the
00007 // terms of the GNU General Public License as published by the
00008 // Free Software Foundation; either version 3, or (at your option)
00009 // any later version.
00010 
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 // GNU General Public License for more details.
00015 
00016 // Under Section 7 of GPL version 3, you are granted additional
00017 // permissions described in the GCC Runtime Library Exception, version
00018 // 3.1, as published by the Free Software Foundation.
00019 
00020 // You should have received a copy of the GNU General Public License and
00021 // a copy of the GCC Runtime Library Exception along with this program;
00022 // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
00023 // <http://www.gnu.org/licenses/>.
00024 
00025 /**
00026  *  @file bits/regex.h
00027  *  This is an internal header file, included by other library headers.
00028  *  Do not attempt to use it directly. @headername{regex}
00029  */
00030 
00031 namespace std _GLIBCXX_VISIBILITY(default)
00032 {
00033 _GLIBCXX_BEGIN_NAMESPACE_VERSION
00034   template<typename, typename>
00035     class basic_regex;
00036 
00037   template<typename, typename>
00038     class match_results;
00039 
00040 _GLIBCXX_END_NAMESPACE_VERSION
00041 
00042 namespace __detail
00043 {
00044 _GLIBCXX_BEGIN_NAMESPACE_VERSION
00045 
00046   enum class _RegexExecutorPolicy : int
00047     { _S_auto, _S_alternate };
00048 
00049   template<typename _BiIter, typename _Alloc,
00050        typename _CharT, typename _TraitsT,
00051        _RegexExecutorPolicy __policy,
00052        bool __match_mode>
00053     bool
00054     __regex_algo_impl(_BiIter                              __s,
00055               _BiIter                              __e,
00056               match_results<_BiIter, _Alloc>&      __m,
00057               const basic_regex<_CharT, _TraitsT>& __re,
00058               regex_constants::match_flag_type     __flags);
00059 
00060   template<typename, typename, typename, bool>
00061     class _Executor;
00062 
00063   template<typename _TraitsT>
00064     inline std::shared_ptr<_NFA<_TraitsT>>
00065     __compile_nfa(const typename _TraitsT::char_type* __first,
00066           const typename _TraitsT::char_type* __last,
00067           const _TraitsT& __traits,
00068           regex_constants::syntax_option_type __flags);
00069 
00070 _GLIBCXX_END_NAMESPACE_VERSION
00071 }
00072 
00073 _GLIBCXX_BEGIN_NAMESPACE_VERSION
00074 
00075   /**
00076    * @addtogroup regex
00077    * @{
00078    */
00079 
00080   /**
00081    * @brief Describes aspects of a regular expression.
00082    *
00083    * A regular expression traits class that satisfies the requirements of
00084    * section [28.7].
00085    *
00086    * The class %regex is parameterized around a set of related types and
00087    * functions used to complete the definition of its semantics.  This class
00088    * satisfies the requirements of such a traits class.
00089    */
00090   template<typename _Ch_type>
00091     struct regex_traits
00092     {
00093     public:
00094       typedef _Ch_type                      char_type;
00095       typedef std::basic_string<char_type>  string_type;
00096       typedef std::locale                   locale_type;
00097     private:
00098       struct _RegexMask
00099     {
00100       typedef typename std::ctype<char_type>::mask _BaseType;
00101       _BaseType _M_base;
00102       unsigned char _M_extended;
00103       static constexpr unsigned char _S_under = 1 << 0;
00104       // FIXME: _S_blank should be removed in the future,
00105       // when locale's complete.
00106       static constexpr unsigned char _S_blank = 1 << 1;
00107       static constexpr unsigned char _S_valid_mask = 0x3;
00108 
00109       constexpr _RegexMask(_BaseType __base = 0,
00110                    unsigned char __extended = 0)
00111       : _M_base(__base), _M_extended(__extended)
00112       { }
00113 
00114       constexpr _RegexMask
00115       operator&(_RegexMask __other) const
00116       {
00117         return _RegexMask(_M_base & __other._M_base,
00118                   _M_extended & __other._M_extended);
00119       }
00120 
00121       constexpr _RegexMask
00122       operator|(_RegexMask __other) const
00123       {
00124         return _RegexMask(_M_base | __other._M_base,
00125                   _M_extended | __other._M_extended);
00126       }
00127 
00128       constexpr _RegexMask
00129       operator^(_RegexMask __other) const
00130       {
00131         return _RegexMask(_M_base ^ __other._M_base,
00132                   _M_extended ^ __other._M_extended);
00133       }
00134 
00135       constexpr _RegexMask
00136       operator~() const
00137       { return _RegexMask(~_M_base, ~_M_extended); }
00138 
00139       _RegexMask&
00140       operator&=(_RegexMask __other)
00141       { return *this = (*this) & __other; }
00142 
00143       _RegexMask&
00144       operator|=(_RegexMask __other)
00145       { return *this = (*this) | __other; }
00146 
00147       _RegexMask&
00148       operator^=(_RegexMask __other)
00149       { return *this = (*this) ^ __other; }
00150 
00151       constexpr bool
00152       operator==(_RegexMask __other) const
00153       {
00154         return (_M_extended & _S_valid_mask)
00155            == (__other._M_extended & _S_valid_mask)
00156              && _M_base == __other._M_base;
00157       }
00158 
00159       constexpr bool
00160       operator!=(_RegexMask __other) const
00161       { return !((*this) == __other); }
00162 
00163     };
00164     public:
00165       typedef _RegexMask char_class_type;
00166 
00167     public:
00168       /**
00169        * @brief Constructs a default traits object.
00170        */
00171       regex_traits() { }
00172 
00173       /**
00174        * @brief Gives the length of a C-style string starting at @p __p.
00175        *
00176        * @param __p a pointer to the start of a character sequence.
00177        *
00178        * @returns the number of characters between @p *__p and the first
00179        * default-initialized value of type @p char_type.  In other words, uses
00180        * the C-string algorithm for determining the length of a sequence of
00181        * characters.
00182        */
00183       static std::size_t
00184       length(const char_type* __p)
00185       { return string_type::traits_type::length(__p); }
00186 
00187       /**
00188        * @brief Performs the identity translation.
00189        *
00190        * @param __c A character to the locale-specific character set.
00191        *
00192        * @returns __c.
00193        */
00194       char_type
00195       translate(char_type __c) const
00196       { return __c; }
00197 
00198       /**
00199        * @brief Translates a character into a case-insensitive equivalent.
00200        *
00201        * @param __c A character to the locale-specific character set.
00202        *
00203        * @returns the locale-specific lower-case equivalent of __c.
00204        * @throws std::bad_cast if the imbued locale does not support the ctype
00205        *         facet.
00206        */
00207       char_type
00208       translate_nocase(char_type __c) const
00209       {
00210     typedef std::ctype<char_type> __ctype_type;
00211     const __ctype_type& __fctyp(use_facet<__ctype_type>(_M_locale));
00212     return __fctyp.tolower(__c);
00213       }
00214 
00215       /**
00216        * @brief Gets a sort key for a character sequence.
00217        *
00218        * @param __first beginning of the character sequence.
00219        * @param __last  one-past-the-end of the character sequence.
00220        *
00221        * Returns a sort key for the character sequence designated by the
00222        * iterator range [F1, F2) such that if the character sequence [G1, G2)
00223        * sorts before the character sequence [H1, H2) then
00224        * v.transform(G1, G2) < v.transform(H1, H2).
00225        *
00226        * What this really does is provide a more efficient way to compare a
00227        * string to multiple other strings in locales with fancy collation
00228        * rules and equivalence classes.
00229        *
00230        * @returns a locale-specific sort key equivalent to the input range.
00231        *
00232        * @throws std::bad_cast if the current locale does not have a collate
00233        *         facet.
00234        */
00235       template<typename _Fwd_iter>
00236     string_type
00237     transform(_Fwd_iter __first, _Fwd_iter __last) const
00238     {
00239       typedef std::collate<char_type> __collate_type;
00240       const __collate_type& __fclt(use_facet<__collate_type>(_M_locale));
00241       string_type __s(__first, __last);
00242       return __fclt.transform(__s.data(), __s.data() + __s.size());
00243     }
00244 
00245       /**
00246        * @brief Gets a sort key for a character sequence, independent of case.
00247        *
00248        * @param __first beginning of the character sequence.
00249        * @param __last  one-past-the-end of the character sequence.
00250        *
00251        * Effects: if typeid(use_facet<collate<_Ch_type> >) ==
00252        * typeid(collate_byname<_Ch_type>) and the form of the sort key
00253        * returned by collate_byname<_Ch_type>::transform(__first, __last)
00254        * is known and can be converted into a primary sort key
00255        * then returns that key, otherwise returns an empty string.
00256        *
00257        * @todo Implement this function correctly.
00258        */
00259       template<typename _Fwd_iter>
00260     string_type
00261     transform_primary(_Fwd_iter __first, _Fwd_iter __last) const
00262     {
00263       // TODO : this is not entirely correct.
00264       // This function requires extra support from the platform.
00265       //
00266       // Read http://gcc.gnu.org/ml/libstdc++/2013-09/msg00117.html and
00267       // http://www.open-std.org/Jtc1/sc22/wg21/docs/papers/2003/n1429.htm
00268       // for details.
00269       typedef std::ctype<char_type> __ctype_type;
00270       const __ctype_type& __fctyp(use_facet<__ctype_type>(_M_locale));
00271       std::vector<char_type> __s(__first, __last);
00272       __fctyp.tolower(__s.data(), __s.data() + __s.size());
00273       return this->transform(__s.data(), __s.data() + __s.size());
00274     }
00275 
00276       /**
00277        * @brief Gets a collation element by name.
00278        *
00279        * @param __first beginning of the collation element name.
00280        * @param __last  one-past-the-end of the collation element name.
00281        *
00282        * @returns a sequence of one or more characters that represents the
00283        * collating element consisting of the character sequence designated by
00284        * the iterator range [__first, __last). Returns an empty string if the
00285        * character sequence is not a valid collating element.
00286        */
00287       template<typename _Fwd_iter>
00288     string_type
00289     lookup_collatename(_Fwd_iter __first, _Fwd_iter __last) const;
00290 
00291       /**
00292        * @brief Maps one or more characters to a named character
00293        *        classification.
00294        *
00295        * @param __first beginning of the character sequence.
00296        * @param __last  one-past-the-end of the character sequence.
00297        * @param __icase ignores the case of the classification name.
00298        *
00299        * @returns an unspecified value that represents the character
00300        * classification named by the character sequence designated by
00301        * the iterator range [__first, __last). If @p icase is true,
00302        * the returned mask identifies the classification regardless of
00303        * the case of the characters to be matched (for example,
00304        * [[:lower:]] is the same as [[:alpha:]]), otherwise a
00305        * case-dependent classification is returned.  The value
00306        * returned shall be independent of the case of the characters
00307        * in the character sequence. If the name is not recognized then
00308        * returns a value that compares equal to 0.
00309        *
00310        * At least the following names (or their wide-character equivalent) are
00311        * supported.
00312        * - d
00313        * - w
00314        * - s
00315        * - alnum
00316        * - alpha
00317        * - blank
00318        * - cntrl
00319        * - digit
00320        * - graph
00321        * - lower
00322        * - print
00323        * - punct
00324        * - space
00325        * - upper
00326        * - xdigit
00327        */
00328       template<typename _Fwd_iter>
00329     char_class_type
00330     lookup_classname(_Fwd_iter __first, _Fwd_iter __last,
00331              bool __icase = false) const;
00332 
00333       /**
00334        * @brief Determines if @p c is a member of an identified class.
00335        *
00336        * @param __c a character.
00337        * @param __f a class type (as returned from lookup_classname).
00338        *
00339        * @returns true if the character @p __c is a member of the classification
00340        * represented by @p __f, false otherwise.
00341        *
00342        * @throws std::bad_cast if the current locale does not have a ctype
00343        *         facet.
00344        */
00345       bool
00346       isctype(_Ch_type __c, char_class_type __f) const;
00347 
00348       /**
00349        * @brief Converts a digit to an int.
00350        *
00351        * @param __ch    a character representing a digit.
00352        * @param __radix the radix if the numeric conversion (limited to 8, 10,
00353        *              or 16).
00354        *
00355        * @returns the value represented by the digit __ch in base radix if the
00356        * character __ch is a valid digit in base radix; otherwise returns -1.
00357        */
00358       int
00359       value(_Ch_type __ch, int __radix) const;
00360 
00361       /**
00362        * @brief Imbues the regex_traits object with a copy of a new locale.
00363        *
00364        * @param __loc A locale.
00365        *
00366        * @returns a copy of the previous locale in use by the regex_traits
00367        *          object.
00368        *
00369        * @note Calling imbue with a different locale than the one currently in
00370        *       use invalidates all cached data held by *this.
00371        */
00372       locale_type
00373       imbue(locale_type __loc)
00374       {
00375     std::swap(_M_locale, __loc);
00376     return __loc;
00377       }
00378 
00379       /**
00380        * @brief Gets a copy of the current locale in use by the regex_traits
00381        * object.
00382        */
00383       locale_type
00384       getloc() const
00385       { return _M_locale; }
00386 
00387     protected:
00388       locale_type _M_locale;
00389     };
00390 
00391   // [7.8] Class basic_regex
00392   /**
00393    * Objects of specializations of this class represent regular expressions
00394    * constructed from sequences of character type @p _Ch_type.
00395    *
00396    * Storage for the regular expression is allocated and deallocated as
00397    * necessary by the member functions of this class.
00398    */
00399   template<typename _Ch_type, typename _Rx_traits = regex_traits<_Ch_type>>
00400     class basic_regex
00401     {
00402     public:
00403       static_assert(is_same<_Ch_type, typename _Rx_traits::char_type>::value,
00404             "regex traits class must have the same char_type");
00405 
00406       // types:
00407       typedef _Ch_type                            value_type;
00408       typedef _Rx_traits                          traits_type;
00409       typedef typename traits_type::string_type   string_type;
00410       typedef regex_constants::syntax_option_type flag_type;
00411       typedef typename traits_type::locale_type   locale_type;
00412 
00413       /**
00414        * @name Constants
00415        * std [28.8.1](1)
00416        */
00417       //@{
00418       static constexpr flag_type icase = regex_constants::icase;
00419       static constexpr flag_type nosubs = regex_constants::nosubs;
00420       static constexpr flag_type optimize = regex_constants::optimize;
00421       static constexpr flag_type collate = regex_constants::collate;
00422       static constexpr flag_type ECMAScript = regex_constants::ECMAScript;
00423       static constexpr flag_type basic = regex_constants::basic;
00424       static constexpr flag_type extended = regex_constants::extended;
00425       static constexpr flag_type awk = regex_constants::awk;
00426       static constexpr flag_type grep = regex_constants::grep;
00427       static constexpr flag_type egrep = regex_constants::egrep;
00428       //@}
00429 
00430       // [7.8.2] construct/copy/destroy
00431       /**
00432        * Constructs a basic regular expression that does not match any
00433        * character sequence.
00434        */
00435       basic_regex()
00436       : _M_flags(ECMAScript), _M_automaton(nullptr)
00437       { }
00438 
00439       /**
00440        * @brief Constructs a basic regular expression from the
00441        * sequence [__p, __p + char_traits<_Ch_type>::length(__p))
00442        * interpreted according to the flags in @p __f.
00443        *
00444        * @param __p A pointer to the start of a C-style null-terminated string
00445        *          containing a regular expression.
00446        * @param __f Flags indicating the syntax rules and options.
00447        *
00448        * @throws regex_error if @p __p is not a valid regular expression.
00449        */
00450       explicit
00451       basic_regex(const _Ch_type* __p, flag_type __f = ECMAScript)
00452       : basic_regex(__p, __p + char_traits<_Ch_type>::length(__p), __f)
00453       { }
00454 
00455       /**
00456        * @brief Constructs a basic regular expression from the sequence
00457        * [p, p + len) interpreted according to the flags in @p f.
00458        *
00459        * @param __p   A pointer to the start of a string containing a regular
00460        *              expression.
00461        * @param __len The length of the string containing the regular
00462        *              expression.
00463        * @param __f   Flags indicating the syntax rules and options.
00464        *
00465        * @throws regex_error if @p __p is not a valid regular expression.
00466        */
00467       basic_regex(const _Ch_type* __p, std::size_t __len,
00468           flag_type __f = ECMAScript)
00469       : basic_regex(__p, __p + __len, __f)
00470       { }
00471 
00472       /**
00473        * @brief Copy-constructs a basic regular expression.
00474        *
00475        * @param __rhs A @p regex object.
00476        */
00477       basic_regex(const basic_regex& __rhs)
00478       : _M_flags(__rhs._M_flags), _M_original_str(__rhs._M_original_str)
00479       {
00480     _M_traits.imbue(__rhs.getloc());
00481     this->assign(_M_original_str, _M_flags);
00482       }
00483 
00484       /**
00485        * @brief Move-constructs a basic regular expression.
00486        *
00487        * @param __rhs A @p regex object.
00488        *
00489        * The implementation is a workaround concerning ABI compatibility. See:
00490        * https://gcc.gnu.org/ml/libstdc++/2014-09/msg00067.html
00491        */
00492       basic_regex(basic_regex&& __rhs)
00493       : _M_flags(__rhs._M_flags),
00494       _M_original_str(std::move(__rhs._M_original_str))
00495       {
00496     _M_traits.imbue(__rhs.getloc());
00497     this->assign(_M_original_str, _M_flags);
00498     __rhs._M_automaton.reset();
00499       }
00500 
00501       /**
00502        * @brief Constructs a basic regular expression from the string
00503        * @p s interpreted according to the flags in @p f.
00504        *
00505        * @param __s A string containing a regular expression.
00506        * @param __f Flags indicating the syntax rules and options.
00507        *
00508        * @throws regex_error if @p __s is not a valid regular expression.
00509        */
00510       template<typename _Ch_traits, typename _Ch_alloc>
00511     explicit
00512     basic_regex(const std::basic_string<_Ch_type, _Ch_traits,
00513                         _Ch_alloc>& __s,
00514             flag_type __f = ECMAScript)
00515     : basic_regex(__s.begin(), __s.end(), __f)
00516     { }
00517 
00518       /**
00519        * @brief Constructs a basic regular expression from the range
00520        * [first, last) interpreted according to the flags in @p f.
00521        *
00522        * @param __first The start of a range containing a valid regular
00523        *                expression.
00524        * @param __last  The end of a range containing a valid regular
00525        *                expression.
00526        * @param __f     The format flags of the regular expression.
00527        *
00528        * @throws regex_error if @p [__first, __last) is not a valid regular
00529        *         expression.
00530        */
00531       template<typename _FwdIter>
00532     basic_regex(_FwdIter __first, _FwdIter __last,
00533             flag_type __f = ECMAScript)
00534     : _M_flags(__f),
00535       _M_original_str(__first, __last),
00536       _M_automaton(__detail::__compile_nfa(_M_original_str.c_str(),
00537                            _M_original_str.c_str()
00538                          + _M_original_str.size(),
00539                            _M_traits,
00540                            _M_flags))
00541     { }
00542 
00543       /**
00544        * @brief Constructs a basic regular expression from an initializer list.
00545        *
00546        * @param __l  The initializer list.
00547        * @param __f  The format flags of the regular expression.
00548        *
00549        * @throws regex_error if @p __l is not a valid regular expression.
00550        */
00551       basic_regex(initializer_list<_Ch_type> __l, flag_type __f = ECMAScript)
00552       : basic_regex(__l.begin(), __l.end(), __f)
00553       { }
00554 
00555       /**
00556        * @brief Destroys a basic regular expression.
00557        */
00558       ~basic_regex()
00559       { }
00560 
00561       /**
00562        * @brief Assigns one regular expression to another.
00563        */
00564       basic_regex&
00565       operator=(const basic_regex& __rhs)
00566       { return this->assign(__rhs); }
00567 
00568       /**
00569        * @brief Move-assigns one regular expression to another.
00570        *
00571        * The implementation is a workaround concerning ABI compatibility. See:
00572        * https://gcc.gnu.org/ml/libstdc++/2014-09/msg00067.html
00573        */
00574       basic_regex&
00575       operator=(basic_regex&& __rhs)
00576       { return this->assign(std::move(__rhs)); }
00577 
00578       /**
00579        * @brief Replaces a regular expression with a new one constructed from
00580        * a C-style null-terminated string.
00581        *
00582        * @param __p A pointer to the start of a null-terminated C-style string
00583        *        containing a regular expression.
00584        */
00585       basic_regex&
00586       operator=(const _Ch_type* __p)
00587       { return this->assign(__p); }
00588 
00589       /**
00590        * @brief Replaces a regular expression with a new one constructed from
00591        * an initializer list.
00592        *
00593        * @param __l  The initializer list.
00594        *
00595        * @throws regex_error if @p __l is not a valid regular expression.
00596        */
00597       basic_regex&
00598       operator=(initializer_list<_Ch_type> __l)
00599       { return this->assign(__l.begin(), __l.end()); }
00600 
00601       /**
00602        * @brief Replaces a regular expression with a new one constructed from
00603        * a string.
00604        *
00605        * @param __s A pointer to a string containing a regular expression.
00606        */
00607       template<typename _Ch_typeraits, typename _Alloc>
00608     basic_regex&
00609     operator=(const basic_string<_Ch_type, _Ch_typeraits, _Alloc>& __s)
00610     { return this->assign(__s); }
00611 
00612       // [7.8.3] assign
00613       /**
00614        * @brief the real assignment operator.
00615        *
00616        * @param __rhs Another regular expression object.
00617        */
00618       basic_regex&
00619       assign(const basic_regex& __rhs)
00620       {
00621     _M_flags = __rhs._M_flags;
00622     _M_original_str = __rhs._M_original_str;
00623     _M_traits.imbue(__rhs.getloc());
00624     this->assign(_M_original_str, _M_flags);
00625     return *this;
00626       }
00627 
00628       /**
00629        * @brief The move-assignment operator.
00630        *
00631        * @param __rhs Another regular expression object.
00632        *
00633        * The implementation is a workaround concerning ABI compatibility. See:
00634        * https://gcc.gnu.org/ml/libstdc++/2014-09/msg00067.html
00635        */
00636       basic_regex&
00637       assign(basic_regex&& __rhs)
00638       {
00639     _M_flags = __rhs._M_flags;
00640     _M_original_str = std::move(__rhs._M_original_str);
00641     __rhs._M_automaton.reset();
00642     _M_traits.imbue(__rhs.getloc());
00643     this->assign(_M_original_str, _M_flags);
00644     return *this;
00645       }
00646 
00647       /**
00648        * @brief Assigns a new regular expression to a regex object from a
00649        * C-style null-terminated string containing a regular expression
00650        * pattern.
00651        *
00652        * @param __p     A pointer to a C-style null-terminated string containing
00653        *              a regular expression pattern.
00654        * @param __flags Syntax option flags.
00655        *
00656        * @throws regex_error if __p does not contain a valid regular
00657        * expression pattern interpreted according to @p __flags.  If
00658        * regex_error is thrown, *this remains unchanged.
00659        */
00660       basic_regex&
00661       assign(const _Ch_type* __p, flag_type __flags = ECMAScript)
00662       { return this->assign(string_type(__p), __flags); }
00663 
00664       /**
00665        * @brief Assigns a new regular expression to a regex object from a
00666        * C-style string containing a regular expression pattern.
00667        *
00668        * @param __p     A pointer to a C-style string containing a
00669        *                regular expression pattern.
00670        * @param __len   The length of the regular expression pattern string.
00671        * @param __flags Syntax option flags.
00672        *
00673        * @throws regex_error if p does not contain a valid regular
00674        * expression pattern interpreted according to @p __flags.  If
00675        * regex_error is thrown, *this remains unchanged.
00676        */
00677       basic_regex&
00678       assign(const _Ch_type* __p, std::size_t __len, flag_type __flags)
00679       { return this->assign(string_type(__p, __len), __flags); }
00680 
00681       /**
00682        * @brief Assigns a new regular expression to a regex object from a
00683        * string containing a regular expression pattern.
00684        *
00685        * @param __s     A string containing a regular expression pattern.
00686        * @param __flags Syntax option flags.
00687        *
00688        * @throws regex_error if __s does not contain a valid regular
00689        * expression pattern interpreted according to @p __flags.  If
00690        * regex_error is thrown, *this remains unchanged.
00691        */
00692       template<typename _Ch_typeraits, typename _Alloc>
00693     basic_regex&
00694     assign(const basic_string<_Ch_type, _Ch_typeraits, _Alloc>& __s,
00695            flag_type __flags = ECMAScript)
00696     {
00697       _M_automaton = __detail::__compile_nfa(
00698         __s.data(), __s.data() + __s.size(), _M_traits, __flags);
00699       _M_original_str = __s;
00700       _M_flags = __flags;
00701       return *this;
00702     }
00703 
00704       /**
00705        * @brief Assigns a new regular expression to a regex object.
00706        *
00707        * @param __first The start of a range containing a valid regular
00708        *                expression.
00709        * @param __last  The end of a range containing a valid regular
00710        *                expression.
00711        * @param __flags Syntax option flags.
00712        *
00713        * @throws regex_error if p does not contain a valid regular
00714        * expression pattern interpreted according to @p __flags.  If
00715        * regex_error is thrown, the object remains unchanged.
00716        */
00717       template<typename _InputIterator>
00718     basic_regex&
00719     assign(_InputIterator __first, _InputIterator __last,
00720            flag_type __flags = ECMAScript)
00721     { return this->assign(string_type(__first, __last), __flags); }
00722 
00723       /**
00724        * @brief Assigns a new regular expression to a regex object.
00725        *
00726        * @param __l     An initializer list representing a regular expression.
00727        * @param __flags Syntax option flags.
00728        *
00729        * @throws regex_error if @p __l does not contain a valid
00730        * regular expression pattern interpreted according to @p
00731        * __flags.  If regex_error is thrown, the object remains
00732        * unchanged.
00733        */
00734       basic_regex&
00735       assign(initializer_list<_Ch_type> __l, flag_type __flags = ECMAScript)
00736       { return this->assign(__l.begin(), __l.end(), __flags); }
00737 
00738       // [7.8.4] const operations
00739       /**
00740        * @brief Gets the number of marked subexpressions within the regular
00741        * expression.
00742        */
00743       unsigned int
00744       mark_count() const
00745       {
00746     if (_M_automaton)
00747       return _M_automaton->_M_sub_count() - 1;
00748     return 0;
00749       }
00750 
00751       /**
00752        * @brief Gets the flags used to construct the regular expression
00753        * or in the last call to assign().
00754        */
00755       flag_type
00756       flags() const
00757       { return _M_flags; }
00758 
00759       // [7.8.5] locale
00760       /**
00761        * @brief Imbues the regular expression object with the given locale.
00762        *
00763        * @param __loc A locale.
00764        */
00765       locale_type
00766       imbue(locale_type __loc)
00767       {
00768     _M_automaton.reset();
00769     return _M_traits.imbue(__loc);
00770       }
00771 
00772       /**
00773        * @brief Gets the locale currently imbued in the regular expression
00774        *        object.
00775        */
00776       locale_type
00777       getloc() const
00778       { return _M_traits.getloc(); }
00779 
00780       // [7.8.6] swap
00781       /**
00782        * @brief Swaps the contents of two regular expression objects.
00783        *
00784        * @param __rhs Another regular expression object.
00785        */
00786       void
00787       swap(basic_regex& __rhs)
00788       {
00789     std::swap(_M_flags, __rhs._M_flags);
00790     std::swap(_M_traits, __rhs._M_traits);
00791     auto __tmp = std::move(_M_original_str);
00792     this->assign(__rhs._M_original_str, _M_flags);
00793     __rhs.assign(__tmp, __rhs._M_flags);
00794       }
00795 
00796 #ifdef _GLIBCXX_DEBUG
00797       void
00798       _M_dot(std::ostream& __ostr)
00799       { _M_automaton->_M_dot(__ostr); }
00800 #endif
00801 
00802     private:
00803       typedef std::shared_ptr<__detail::_NFA<_Rx_traits>> _AutomatonPtr;
00804 
00805       template<typename _Bp, typename _Ap, typename _Cp, typename _Rp,
00806     __detail::_RegexExecutorPolicy, bool>
00807     friend bool
00808     __detail::__regex_algo_impl(_Bp, _Bp, match_results<_Bp, _Ap>&,
00809                     const basic_regex<_Cp, _Rp>&,
00810                     regex_constants::match_flag_type);
00811 
00812       template<typename, typename, typename, bool>
00813     friend class __detail::_Executor;
00814 
00815       flag_type              _M_flags;
00816       _Rx_traits             _M_traits;
00817       basic_string<_Ch_type> _M_original_str;
00818       _AutomatonPtr          _M_automaton;
00819     };
00820 
00821   /** @brief Standard regular expressions. */
00822   typedef basic_regex<char>    regex;
00823 
00824 #ifdef _GLIBCXX_USE_WCHAR_T
00825   /** @brief Standard wide-character regular expressions. */
00826   typedef basic_regex<wchar_t> wregex;
00827 #endif
00828 
00829 
00830   // [7.8.6] basic_regex swap
00831   /**
00832    * @brief Swaps the contents of two regular expression objects.
00833    * @param __lhs First regular expression.
00834    * @param __rhs Second regular expression.
00835    */
00836   template<typename _Ch_type, typename _Rx_traits>
00837     inline void
00838     swap(basic_regex<_Ch_type, _Rx_traits>& __lhs,
00839      basic_regex<_Ch_type, _Rx_traits>& __rhs)
00840     { __lhs.swap(__rhs); }
00841 
00842 
00843   // [7.9] Class template sub_match
00844   /**
00845    * A sequence of characters matched by a particular marked sub-expression.
00846    *
00847    * An object of this class is essentially a pair of iterators marking a
00848    * matched subexpression within a regular expression pattern match. Such
00849    * objects can be converted to and compared with std::basic_string objects
00850    * of a similar base character type as the pattern matched by the regular
00851    * expression.
00852    *
00853    * The iterators that make up the pair are the usual half-open interval
00854    * referencing the actual original pattern matched.
00855    */
00856   template<typename _BiIter>
00857     class sub_match : public std::pair<_BiIter, _BiIter>
00858     {
00859       typedef iterator_traits<_BiIter>          __iter_traits;
00860     
00861     public:
00862       typedef typename __iter_traits::value_type        value_type;
00863       typedef typename __iter_traits::difference_type   difference_type;
00864       typedef _BiIter                                   iterator;
00865       typedef std::basic_string<value_type>             string_type;
00866 
00867       bool matched;
00868 
00869       constexpr sub_match() : matched() { }
00870 
00871       /**
00872        * Gets the length of the matching sequence.
00873        */
00874       difference_type
00875       length() const
00876       { return this->matched ? std::distance(this->first, this->second) : 0; }
00877 
00878       /**
00879        * @brief Gets the matching sequence as a string.
00880        *
00881        * @returns the matching sequence as a string.
00882        *
00883        * This is the implicit conversion operator.  It is identical to the
00884        * str() member function except that it will want to pop up in
00885        * unexpected places and cause a great deal of confusion and cursing
00886        * from the unwary.
00887        */
00888       operator string_type() const
00889       {
00890     return this->matched
00891       ? string_type(this->first, this->second)
00892       : string_type();
00893       }
00894 
00895       /**
00896        * @brief Gets the matching sequence as a string.
00897        *
00898        * @returns the matching sequence as a string.
00899        */
00900       string_type
00901       str() const
00902       {
00903     return this->matched
00904       ? string_type(this->first, this->second)
00905       : string_type();
00906       }
00907 
00908       /**
00909        * @brief Compares this and another matched sequence.
00910        *
00911        * @param __s Another matched sequence to compare to this one.
00912        *
00913        * @retval <0 this matched sequence will collate before @p __s.
00914        * @retval =0 this matched sequence is equivalent to @p __s.
00915        * @retval <0 this matched sequence will collate after @p __s.
00916        */
00917       int
00918       compare(const sub_match& __s) const
00919       { return this->str().compare(__s.str()); }
00920 
00921       /**
00922        * @brief Compares this sub_match to a string.
00923        *
00924        * @param __s A string to compare to this sub_match.
00925        *
00926        * @retval <0 this matched sequence will collate before @p __s.
00927        * @retval =0 this matched sequence is equivalent to @p __s.
00928        * @retval <0 this matched sequence will collate after @p __s.
00929        */
00930       int
00931       compare(const string_type& __s) const
00932       { return this->str().compare(__s); }
00933 
00934       /**
00935        * @brief Compares this sub_match to a C-style string.
00936        *
00937        * @param __s A C-style string to compare to this sub_match.
00938        *
00939        * @retval <0 this matched sequence will collate before @p __s.
00940        * @retval =0 this matched sequence is equivalent to @p __s.
00941        * @retval <0 this matched sequence will collate after @p __s.
00942        */
00943       int
00944       compare(const value_type* __s) const
00945       { return this->str().compare(__s); }
00946     };
00947 
00948 
00949   /** @brief Standard regex submatch over a C-style null-terminated string. */
00950   typedef sub_match<const char*>             csub_match;
00951 
00952   /** @brief Standard regex submatch over a standard string. */
00953   typedef sub_match<string::const_iterator>  ssub_match;
00954 
00955 #ifdef _GLIBCXX_USE_WCHAR_T
00956   /** @brief Regex submatch over a C-style null-terminated wide string. */
00957   typedef sub_match<const wchar_t*>          wcsub_match;
00958 
00959   /** @brief Regex submatch over a standard wide string. */
00960   typedef sub_match<wstring::const_iterator> wssub_match;
00961 #endif
00962 
00963   // [7.9.2] sub_match non-member operators
00964 
00965   /**
00966    * @brief Tests the equivalence of two regular expression submatches.
00967    * @param __lhs First regular expression submatch.
00968    * @param __rhs Second regular expression submatch.
00969    * @returns true if @a __lhs  is equivalent to @a __rhs, false otherwise.
00970    */
00971   template<typename _BiIter>
00972     inline bool
00973     operator==(const sub_match<_BiIter>& __lhs, const sub_match<_BiIter>& __rhs)
00974     { return __lhs.compare(__rhs) == 0; }
00975 
00976   /**
00977    * @brief Tests the inequivalence of two regular expression submatches.
00978    * @param __lhs First regular expression submatch.
00979    * @param __rhs Second regular expression submatch.
00980    * @returns true if @a __lhs  is not equivalent to @a __rhs, false otherwise.
00981    */
00982   template<typename _BiIter>
00983     inline bool
00984     operator!=(const sub_match<_BiIter>& __lhs, const sub_match<_BiIter>& __rhs)
00985     { return __lhs.compare(__rhs) != 0; }
00986 
00987   /**
00988    * @brief Tests the ordering of two regular expression submatches.
00989    * @param __lhs First regular expression submatch.
00990    * @param __rhs Second regular expression submatch.
00991    * @returns true if @a __lhs precedes @a __rhs, false otherwise.
00992    */
00993   template<typename _BiIter>
00994     inline bool
00995     operator<(const sub_match<_BiIter>& __lhs, const sub_match<_BiIter>& __rhs)
00996     { return __lhs.compare(__rhs) < 0; }
00997 
00998   /**
00999    * @brief Tests the ordering of two regular expression submatches.
01000    * @param __lhs First regular expression submatch.
01001    * @param __rhs Second regular expression submatch.
01002    * @returns true if @a __lhs does not succeed @a __rhs, false otherwise.
01003    */
01004   template<typename _BiIter>
01005     inline bool
01006     operator<=(const sub_match<_BiIter>& __lhs, const sub_match<_BiIter>& __rhs)
01007     { return __lhs.compare(__rhs) <= 0; }
01008 
01009   /**
01010    * @brief Tests the ordering of two regular expression submatches.
01011    * @param __lhs First regular expression submatch.
01012    * @param __rhs Second regular expression submatch.
01013    * @returns true if @a __lhs does not precede @a __rhs, false otherwise.
01014    */
01015   template<typename _BiIter>
01016     inline bool
01017     operator>=(const sub_match<_BiIter>& __lhs, const sub_match<_BiIter>& __rhs)
01018     { return __lhs.compare(__rhs) >= 0; }
01019 
01020   /**
01021    * @brief Tests the ordering of two regular expression submatches.
01022    * @param __lhs First regular expression submatch.
01023    * @param __rhs Second regular expression submatch.
01024    * @returns true if @a __lhs succeeds @a __rhs, false otherwise.
01025    */
01026   template<typename _BiIter>
01027     inline bool
01028     operator>(const sub_match<_BiIter>& __lhs, const sub_match<_BiIter>& __rhs)
01029     { return __lhs.compare(__rhs) > 0; }
01030 
01031   // Alias for sub_match'd string.
01032   template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
01033     using __sub_match_string = basic_string<
01034                   typename iterator_traits<_Bi_iter>::value_type,
01035                   _Ch_traits, _Ch_alloc>;
01036 
01037   /**
01038    * @brief Tests the equivalence of a string and a regular expression
01039    *        submatch.
01040    * @param __lhs A string.
01041    * @param __rhs A regular expression submatch.
01042    * @returns true if @a __lhs  is equivalent to @a __rhs, false otherwise.
01043    */
01044   template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
01045     inline bool
01046     operator==(const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __lhs,
01047            const sub_match<_Bi_iter>& __rhs)
01048     { return __rhs.compare(__lhs.c_str()) == 0; }
01049 
01050   /**
01051    * @brief Tests the inequivalence of a string and a regular expression
01052    *        submatch.
01053    * @param __lhs A string.
01054    * @param __rhs A regular expression submatch.
01055    * @returns true if @a __lhs  is not equivalent to @a __rhs, false otherwise.
01056    */
01057   template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
01058     inline bool
01059     operator!=(const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __lhs,
01060            const sub_match<_Bi_iter>& __rhs)
01061     { return !(__lhs == __rhs); }
01062 
01063   /**
01064    * @brief Tests the ordering of a string and a regular expression submatch.
01065    * @param __lhs A string.
01066    * @param __rhs A regular expression submatch.
01067    * @returns true if @a __lhs precedes @a __rhs, false otherwise.
01068    */
01069   template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
01070     inline bool
01071     operator<(const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __lhs,
01072           const sub_match<_Bi_iter>& __rhs)
01073      { return __rhs.compare(__lhs.c_str()) > 0; }
01074 
01075   /**
01076    * @brief Tests the ordering of a string and a regular expression submatch.
01077    * @param __lhs A string.
01078    * @param __rhs A regular expression submatch.
01079    * @returns true if @a __lhs succeeds @a __rhs, false otherwise.
01080    */
01081   template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
01082     inline bool
01083     operator>(const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __lhs,
01084           const sub_match<_Bi_iter>& __rhs)
01085     { return __rhs < __lhs; }
01086 
01087   /**
01088    * @brief Tests the ordering of a string and a regular expression submatch.
01089    * @param __lhs A string.
01090    * @param __rhs A regular expression submatch.
01091    * @returns true if @a __lhs does not precede @a __rhs, false otherwise.
01092    */
01093   template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
01094     inline bool
01095     operator>=(const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __lhs,
01096            const sub_match<_Bi_iter>& __rhs)
01097     { return !(__lhs < __rhs); }
01098 
01099   /**
01100    * @brief Tests the ordering of a string and a regular expression submatch.
01101    * @param __lhs A string.
01102    * @param __rhs A regular expression submatch.
01103    * @returns true if @a __lhs does not succeed @a __rhs, false otherwise.
01104    */
01105   template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
01106     inline bool
01107     operator<=(const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __lhs,
01108            const sub_match<_Bi_iter>& __rhs)
01109     { return !(__rhs < __lhs); }
01110 
01111   /**
01112    * @brief Tests the equivalence of a regular expression submatch and a
01113    *        string.
01114    * @param __lhs A regular expression submatch.
01115    * @param __rhs A string.
01116    * @returns true if @a __lhs is equivalent to @a __rhs, false otherwise.
01117    */
01118   template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
01119     inline bool
01120     operator==(const sub_match<_Bi_iter>& __lhs,
01121            const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __rhs)
01122     { return __lhs.compare(__rhs.c_str()) == 0; }
01123 
01124   /**
01125    * @brief Tests the inequivalence of a regular expression submatch and a
01126    *        string.
01127    * @param __lhs A regular expression submatch.
01128    * @param __rhs A string.
01129    * @returns true if @a __lhs is not equivalent to @a __rhs, false otherwise.
01130    */
01131   template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
01132     inline bool
01133     operator!=(const sub_match<_Bi_iter>& __lhs,
01134            const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __rhs)
01135     { return !(__lhs == __rhs); }
01136 
01137   /**
01138    * @brief Tests the ordering of a regular expression submatch and a string.
01139    * @param __lhs A regular expression submatch.
01140    * @param __rhs A string.
01141    * @returns true if @a __lhs precedes @a __rhs, false otherwise.
01142    */
01143   template<typename _Bi_iter, class _Ch_traits, class _Ch_alloc>
01144     inline bool
01145     operator<(const sub_match<_Bi_iter>& __lhs,
01146           const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __rhs)
01147     { return __lhs.compare(__rhs.c_str()) < 0; }
01148 
01149   /**
01150    * @brief Tests the ordering of a regular expression submatch and a string.
01151    * @param __lhs A regular expression submatch.
01152    * @param __rhs A string.
01153    * @returns true if @a __lhs succeeds @a __rhs, false otherwise.
01154    */
01155   template<typename _Bi_iter, class _Ch_traits, class _Ch_alloc>
01156     inline bool
01157     operator>(const sub_match<_Bi_iter>& __lhs,
01158           const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __rhs)
01159     { return __rhs < __lhs; }
01160 
01161   /**
01162    * @brief Tests the ordering of a regular expression submatch and a string.
01163    * @param __lhs A regular expression submatch.
01164    * @param __rhs A string.
01165    * @returns true if @a __lhs does not precede @a __rhs, false otherwise.
01166    */
01167   template<typename _Bi_iter, class _Ch_traits, class _Ch_alloc>
01168     inline bool
01169     operator>=(const sub_match<_Bi_iter>& __lhs,
01170            const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __rhs)
01171     { return !(__lhs < __rhs); }
01172 
01173   /**
01174    * @brief Tests the ordering of a regular expression submatch and a string.
01175    * @param __lhs A regular expression submatch.
01176    * @param __rhs A string.
01177    * @returns true if @a __lhs does not succeed @a __rhs, false otherwise.
01178    */
01179   template<typename _Bi_iter, class _Ch_traits, class _Ch_alloc>
01180     inline bool
01181     operator<=(const sub_match<_Bi_iter>& __lhs,
01182            const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __rhs)
01183     { return !(__rhs < __lhs); }
01184 
01185   /**
01186    * @brief Tests the equivalence of a C string and a regular expression
01187    *        submatch.
01188    * @param __lhs A C string.
01189    * @param __rhs A regular expression submatch.
01190    * @returns true if @a __lhs  is equivalent to @a __rhs, false otherwise.
01191    */
01192   template<typename _Bi_iter>
01193     inline bool
01194     operator==(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
01195            const sub_match<_Bi_iter>& __rhs)
01196     { return __rhs.compare(__lhs) == 0; }
01197 
01198   /**
01199    * @brief Tests the inequivalence of an iterator value and a regular
01200    *        expression submatch.
01201    * @param __lhs A regular expression submatch.
01202    * @param __rhs A string.
01203    * @returns true if @a __lhs is not equivalent to @a __rhs, false otherwise.
01204    */
01205   template<typename _Bi_iter>
01206     inline bool
01207     operator!=(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
01208            const sub_match<_Bi_iter>& __rhs)
01209     { return !(__lhs == __rhs); }
01210 
01211   /**
01212    * @brief Tests the ordering of a string and a regular expression submatch.
01213    * @param __lhs A string.
01214    * @param __rhs A regular expression submatch.
01215    * @returns true if @a __lhs precedes @a __rhs, false otherwise.
01216    */
01217   template<typename _Bi_iter>
01218     inline bool
01219     operator<(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
01220           const sub_match<_Bi_iter>& __rhs)
01221     { return __rhs.compare(__lhs) > 0; }
01222 
01223   /**
01224    * @brief Tests the ordering of a string and a regular expression submatch.
01225    * @param __lhs A string.
01226    * @param __rhs A regular expression submatch.
01227    * @returns true if @a __lhs succeeds @a __rhs, false otherwise.
01228    */
01229   template<typename _Bi_iter>
01230     inline bool
01231     operator>(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
01232           const sub_match<_Bi_iter>& __rhs)
01233     { return __rhs < __lhs; }
01234 
01235   /**
01236    * @brief Tests the ordering of a string and a regular expression submatch.
01237    * @param __lhs A string.
01238    * @param __rhs A regular expression submatch.
01239    * @returns true if @a __lhs does not precede @a __rhs, false otherwise.
01240    */
01241   template<typename _Bi_iter>
01242     inline bool
01243     operator>=(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
01244            const sub_match<_Bi_iter>& __rhs)
01245     { return !(__lhs < __rhs); }
01246 
01247   /**
01248    * @brief Tests the ordering of a string and a regular expression submatch.
01249    * @param __lhs A string.
01250    * @param __rhs A regular expression submatch.
01251    * @returns true if @a __lhs does not succeed @a __rhs, false otherwise.
01252    */
01253   template<typename _Bi_iter>
01254     inline bool
01255     operator<=(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
01256            const sub_match<_Bi_iter>& __rhs)
01257     { return !(__rhs < __lhs); }
01258 
01259   /**
01260    * @brief Tests the equivalence of a regular expression submatch and a
01261    *        string.
01262    * @param __lhs A regular expression submatch.
01263    * @param __rhs A pointer to a string?
01264    * @returns true if @a __lhs  is equivalent to @a __rhs, false otherwise.
01265    */
01266   template<typename _Bi_iter>
01267     inline bool
01268     operator==(const sub_match<_Bi_iter>& __lhs,
01269            typename iterator_traits<_Bi_iter>::value_type const* __rhs)
01270     { return __lhs.compare(__rhs) == 0; }
01271 
01272   /**
01273    * @brief Tests the inequivalence of a regular expression submatch and a
01274    *        string.
01275    * @param __lhs A regular expression submatch.
01276    * @param __rhs A pointer to a string.
01277    * @returns true if @a __lhs is not equivalent to @a __rhs, false otherwise.
01278    */
01279   template<typename _Bi_iter>
01280     inline bool
01281     operator!=(const sub_match<_Bi_iter>& __lhs,
01282            typename iterator_traits<_Bi_iter>::value_type const* __rhs)
01283     { return !(__lhs == __rhs); }
01284 
01285   /**
01286    * @brief Tests the ordering of a regular expression submatch and a string.
01287    * @param __lhs A regular expression submatch.
01288    * @param __rhs A string.
01289    * @returns true if @a __lhs precedes @a __rhs, false otherwise.
01290    */
01291   template<typename _Bi_iter>
01292     inline bool
01293     operator<(const sub_match<_Bi_iter>& __lhs,
01294           typename iterator_traits<_Bi_iter>::value_type const* __rhs)
01295     { return __lhs.compare(__rhs) < 0; }
01296 
01297   /**
01298    * @brief Tests the ordering of a regular expression submatch and a string.
01299    * @param __lhs A regular expression submatch.
01300    * @param __rhs A string.
01301    * @returns true if @a __lhs succeeds @a __rhs, false otherwise.
01302    */
01303   template<typename _Bi_iter>
01304     inline bool
01305     operator>(const sub_match<_Bi_iter>& __lhs,
01306           typename iterator_traits<_Bi_iter>::value_type const* __rhs)
01307     { return __rhs < __lhs; }
01308 
01309   /**
01310    * @brief Tests the ordering of a regular expression submatch and a string.
01311    * @param __lhs A regular expression submatch.
01312    * @param __rhs A string.
01313    * @returns true if @a __lhs does not precede @a __rhs, false otherwise.
01314    */
01315   template<typename _Bi_iter>
01316     inline bool
01317     operator>=(const sub_match<_Bi_iter>& __lhs,
01318            typename iterator_traits<_Bi_iter>::value_type const* __rhs)
01319     { return !(__lhs < __rhs); }
01320 
01321   /**
01322    * @brief Tests the ordering of a regular expression submatch and a string.
01323    * @param __lhs A regular expression submatch.
01324    * @param __rhs A string.
01325    * @returns true if @a __lhs does not succeed @a __rhs, false otherwise.
01326    */
01327   template<typename _Bi_iter>
01328     inline bool
01329     operator<=(const sub_match<_Bi_iter>& __lhs,
01330            typename iterator_traits<_Bi_iter>::value_type const* __rhs)
01331     { return !(__rhs < __lhs); }
01332 
01333   /**
01334    * @brief Tests the equivalence of a string and a regular expression
01335    *        submatch.
01336    * @param __lhs A string.
01337    * @param __rhs A regular expression submatch.
01338    * @returns true if @a __lhs is equivalent to @a __rhs, false otherwise.
01339    */
01340   template<typename _Bi_iter>
01341     inline bool
01342     operator==(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
01343            const sub_match<_Bi_iter>& __rhs)
01344     {
01345       typedef typename sub_match<_Bi_iter>::string_type string_type;
01346       return __rhs.compare(string_type(1, __lhs)) == 0;
01347     }
01348 
01349   /**
01350    * @brief Tests the inequivalence of a string and a regular expression
01351    *        submatch.
01352    * @param __lhs A string.
01353    * @param __rhs A regular expression submatch.
01354    * @returns true if @a __lhs is not equivalent to @a __rhs, false otherwise.
01355    */
01356   template<typename _Bi_iter>
01357     inline bool
01358     operator!=(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
01359            const sub_match<_Bi_iter>& __rhs)
01360     { return !(__lhs == __rhs); }
01361 
01362   /**
01363    * @brief Tests the ordering of a string and a regular expression submatch.
01364    * @param __lhs A string.
01365    * @param __rhs A regular expression submatch.
01366    * @returns true if @a __lhs precedes @a __rhs, false otherwise.
01367    */
01368   template<typename _Bi_iter>
01369     inline bool
01370     operator<(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
01371           const sub_match<_Bi_iter>& __rhs)
01372     {
01373       typedef typename sub_match<_Bi_iter>::string_type string_type;
01374       return __rhs.compare(string_type(1, __lhs)) > 0;
01375     }
01376 
01377   /**
01378    * @brief Tests the ordering of a string and a regular expression submatch.
01379    * @param __lhs A string.
01380    * @param __rhs A regular expression submatch.
01381    * @returns true if @a __lhs succeeds @a __rhs, false otherwise.
01382    */
01383   template<typename _Bi_iter>
01384     inline bool
01385     operator>(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
01386           const sub_match<_Bi_iter>& __rhs)
01387     { return __rhs < __lhs; }
01388 
01389   /**
01390    * @brief Tests the ordering of a string and a regular expression submatch.
01391    * @param __lhs A string.
01392    * @param __rhs A regular expression submatch.
01393    * @returns true if @a __lhs does not precede @a __rhs, false otherwise.
01394    */
01395   template<typename _Bi_iter>
01396     inline bool
01397     operator>=(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
01398            const sub_match<_Bi_iter>& __rhs)
01399     { return !(__lhs < __rhs); }
01400 
01401   /**
01402    * @brief Tests the ordering of a string and a regular expression submatch.
01403    * @param __lhs A string.
01404    * @param __rhs A regular expression submatch.
01405    * @returns true if @a __lhs does not succeed @a __rhs, false otherwise.
01406    */
01407   template<typename _Bi_iter>
01408     inline bool
01409     operator<=(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
01410            const sub_match<_Bi_iter>& __rhs)
01411     { return !(__rhs < __lhs); }
01412 
01413   /**
01414    * @brief Tests the equivalence of a regular expression submatch and a
01415    *        string.
01416    * @param __lhs A regular expression submatch.
01417    * @param __rhs A const string reference.
01418    * @returns true if @a __lhs  is equivalent to @a __rhs, false otherwise.
01419    */
01420   template<typename _Bi_iter>
01421     inline bool
01422     operator==(const sub_match<_Bi_iter>& __lhs,
01423            typename iterator_traits<_Bi_iter>::value_type const& __rhs)
01424     {
01425       typedef typename sub_match<_Bi_iter>::string_type string_type;
01426       return __lhs.compare(string_type(1, __rhs)) == 0;
01427     }
01428 
01429   /**
01430    * @brief Tests the inequivalence of a regular expression submatch and a
01431    *        string.
01432    * @param __lhs A regular expression submatch.
01433    * @param __rhs A const string reference.
01434    * @returns true if @a __lhs is not equivalent to @a __rhs, false otherwise.
01435    */
01436   template<typename _Bi_iter>
01437     inline bool
01438     operator!=(const sub_match<_Bi_iter>& __lhs,
01439            typename iterator_traits<_Bi_iter>::value_type const& __rhs)
01440     { return !(__lhs == __rhs); }
01441 
01442   /**
01443    * @brief Tests the ordering of a regular expression submatch and a string.
01444    * @param __lhs A regular expression submatch.
01445    * @param __rhs A const string reference.
01446    * @returns true if @a __lhs precedes @a __rhs, false otherwise.
01447    */
01448   template<typename _Bi_iter>
01449     inline bool
01450     operator<(const sub_match<_Bi_iter>& __lhs,
01451           typename iterator_traits<_Bi_iter>::value_type const& __rhs)
01452     {
01453       typedef typename sub_match<_Bi_iter>::string_type string_type;
01454       return __lhs.compare(string_type(1, __rhs)) < 0;
01455     }
01456 
01457   /**
01458    * @brief Tests the ordering of a regular expression submatch and a string.
01459    * @param __lhs A regular expression submatch.
01460    * @param __rhs A const string reference.
01461    * @returns true if @a __lhs succeeds @a __rhs, false otherwise.
01462    */
01463   template<typename _Bi_iter>
01464     inline bool
01465     operator>(const sub_match<_Bi_iter>& __lhs,
01466           typename iterator_traits<_Bi_iter>::value_type const& __rhs)
01467     { return __rhs < __lhs; }
01468 
01469   /**
01470    * @brief Tests the ordering of a regular expression submatch and a string.
01471    * @param __lhs A regular expression submatch.
01472    * @param __rhs A const string reference.
01473    * @returns true if @a __lhs does not precede @a __rhs, false otherwise.
01474    */
01475   template<typename _Bi_iter>
01476     inline bool
01477     operator>=(const sub_match<_Bi_iter>& __lhs,
01478            typename iterator_traits<_Bi_iter>::value_type const& __rhs)
01479     { return !(__lhs < __rhs); }
01480 
01481   /**
01482    * @brief Tests the ordering of a regular expression submatch and a string.
01483    * @param __lhs A regular expression submatch.
01484    * @param __rhs A const string reference.
01485    * @returns true if @a __lhs does not succeed @a __rhs, false otherwise.
01486    */
01487   template<typename _Bi_iter>
01488     inline bool
01489     operator<=(const sub_match<_Bi_iter>& __lhs,
01490            typename iterator_traits<_Bi_iter>::value_type const& __rhs)
01491     { return !(__rhs < __lhs); }
01492 
01493   /**
01494    * @brief Inserts a matched string into an output stream.
01495    *
01496    * @param __os The output stream.
01497    * @param __m  A submatch string.
01498    *
01499    * @returns the output stream with the submatch string inserted.
01500    */
01501   template<typename _Ch_type, typename _Ch_traits, typename _Bi_iter>
01502     inline
01503     basic_ostream<_Ch_type, _Ch_traits>&
01504     operator<<(basic_ostream<_Ch_type, _Ch_traits>& __os,
01505            const sub_match<_Bi_iter>& __m)
01506     { return __os << __m.str(); }
01507 
01508   // [7.10] Class template match_results
01509 
01510   /*
01511    * Special sub_match object representing an unmatched sub-expression.
01512    */
01513   template<typename _Bi_iter>
01514     inline const sub_match<_Bi_iter>&
01515     __unmatched_sub()
01516     {
01517       static const sub_match<_Bi_iter> __unmatched = sub_match<_Bi_iter>();
01518       return __unmatched;
01519     }
01520 
01521   /**
01522    * @brief The results of a match or search operation.
01523    *
01524    * A collection of character sequences representing the result of a regular
01525    * expression match.  Storage for the collection is allocated and freed as
01526    * necessary by the member functions of class template match_results.
01527    *
01528    * This class satisfies the Sequence requirements, with the exception that
01529    * only the operations defined for a const-qualified Sequence are supported.
01530    *
01531    * The sub_match object stored at index 0 represents sub-expression 0, i.e.
01532    * the whole match. In this case the %sub_match member matched is always true.
01533    * The sub_match object stored at index n denotes what matched the marked
01534    * sub-expression n within the matched expression. If the sub-expression n
01535    * participated in a regular expression match then the %sub_match member
01536    * matched evaluates to true, and members first and second denote the range
01537    * of characters [first, second) which formed that match. Otherwise matched
01538    * is false, and members first and second point to the end of the sequence
01539    * that was searched.
01540    *
01541    * @nosubgrouping
01542    */
01543   template<typename _Bi_iter,
01544        typename _Alloc = allocator<sub_match<_Bi_iter> > >
01545     class match_results
01546     : private std::vector<sub_match<_Bi_iter>, _Alloc>
01547     {
01548     private:
01549       /*
01550        * The vector base is empty if this does not represent a successful match.
01551        * Otherwise it contains n+3 elements where n is the number of marked
01552        * sub-expressions:
01553        * [0] entire match
01554        * [1] 1st marked subexpression
01555        * ...
01556        * [n] nth marked subexpression
01557        * [n+1] prefix
01558        * [n+2] suffix
01559        */
01560       typedef std::vector<sub_match<_Bi_iter>, _Alloc>     _Base_type;
01561       typedef std::iterator_traits<_Bi_iter>           __iter_traits;
01562       typedef regex_constants::match_flag_type         match_flag_type;
01563 
01564     public:
01565       /**
01566        * @name 10.? Public Types
01567        */
01568       //@{
01569       typedef sub_match<_Bi_iter>                          value_type;
01570       typedef const value_type&                            const_reference;
01571       typedef const_reference                              reference;
01572       typedef typename _Base_type::const_iterator          const_iterator;
01573       typedef const_iterator                               iterator;
01574       typedef typename __iter_traits::difference_type      difference_type;
01575       typedef typename allocator_traits<_Alloc>::size_type size_type;
01576       typedef _Alloc                                       allocator_type;
01577       typedef typename __iter_traits::value_type       char_type;
01578       typedef std::basic_string<char_type>                 string_type;
01579       //@}
01580 
01581     public:
01582       /**
01583        * @name 28.10.1 Construction, Copying, and Destruction
01584        */
01585       //@{
01586 
01587       /**
01588        * @brief Constructs a default %match_results container.
01589        * @post size() returns 0 and str() returns an empty string.
01590        */
01591       explicit
01592       match_results(const _Alloc& __a = _Alloc())
01593       : _Base_type(__a)
01594       { }
01595 
01596       /**
01597        * @brief Copy constructs a %match_results.
01598        */
01599       match_results(const match_results& __rhs) = default;
01600 
01601       /**
01602        * @brief Move constructs a %match_results.
01603        */
01604       match_results(match_results&& __rhs) noexcept = default;
01605 
01606       /**
01607        * @brief Assigns rhs to *this.
01608        */
01609       match_results&
01610       operator=(const match_results& __rhs) = default;
01611 
01612       /**
01613        * @brief Move-assigns rhs to *this.
01614        */
01615       match_results&
01616       operator=(match_results&& __rhs) = default;
01617 
01618       /**
01619        * @brief Destroys a %match_results object.
01620        */
01621       ~match_results()
01622       { }
01623 
01624       //@}
01625 
01626       // 28.10.2, state:
01627       /**
01628        * @brief Indicates if the %match_results is ready.
01629        * @retval true   The object has a fully-established result state.
01630        * @retval false  The object is not ready.
01631        */
01632       bool ready() const { return !_Base_type::empty(); }
01633 
01634       /**
01635        * @name 28.10.2 Size
01636        */
01637       //@{
01638 
01639       /**
01640        * @brief Gets the number of matches and submatches.
01641        *
01642        * The number of matches for a given regular expression will be either 0
01643        * if there was no match or mark_count() + 1 if a match was successful.
01644        * Some matches may be empty.
01645        *
01646        * @returns the number of matches found.
01647        */
01648       size_type
01649       size() const
01650       {
01651         size_type __size = _Base_type::size();
01652         return (__size && _Base_type::operator[](0).matched) ? __size - 2 : 0;
01653       }
01654 
01655       size_type
01656       max_size() const
01657       { return _Base_type::max_size(); }
01658 
01659       /**
01660        * @brief Indicates if the %match_results contains no results.
01661        * @retval true The %match_results object is empty.
01662        * @retval false The %match_results object is not empty.
01663        */
01664       bool
01665       empty() const
01666       { return size() == 0; }
01667 
01668       //@}
01669 
01670       /**
01671        * @name 10.3 Element Access
01672        */
01673       //@{
01674 
01675       /**
01676        * @brief Gets the length of the indicated submatch.
01677        * @param __sub indicates the submatch.
01678        * @pre   ready() == true
01679        *
01680        * This function returns the length of the indicated submatch, or the
01681        * length of the entire match if @p __sub is zero (the default).
01682        */
01683       difference_type
01684       length(size_type __sub = 0) const
01685       { return (*this)[__sub].length(); }
01686 
01687       /**
01688        * @brief Gets the offset of the beginning of the indicated submatch.
01689        * @param __sub indicates the submatch.
01690        * @pre   ready() == true
01691        *
01692        * This function returns the offset from the beginning of the target
01693        * sequence to the beginning of the submatch, unless the value of @p __sub
01694        * is zero (the default), in which case this function returns the offset
01695        * from the beginning of the target sequence to the beginning of the
01696        * match.
01697        *
01698        * Returns -1 if @p __sub is out of range.
01699        */
01700       difference_type
01701       position(size_type __sub = 0) const
01702       {
01703     return __sub < size() ? std::distance(_M_begin,
01704                           (*this)[__sub].first) : -1;
01705       }
01706 
01707       /**
01708        * @brief Gets the match or submatch converted to a string type.
01709        * @param __sub indicates the submatch.
01710        * @pre   ready() == true
01711        *
01712        * This function gets the submatch (or match, if @p __sub is
01713        * zero) extracted from the target range and converted to the
01714        * associated string type.
01715        */
01716       string_type
01717       str(size_type __sub = 0) const
01718       { return (*this)[__sub].str(); }
01719 
01720       /**
01721        * @brief Gets a %sub_match reference for the match or submatch.
01722        * @param __sub indicates the submatch.
01723        * @pre   ready() == true
01724        *
01725        * This function gets a reference to the indicated submatch, or
01726        * the entire match if @p __sub is zero.
01727        *
01728        * If @p __sub >= size() then this function returns a %sub_match with a
01729        * special value indicating no submatch.
01730        */
01731       const_reference
01732       operator[](size_type __sub) const
01733       {
01734         _GLIBCXX_DEBUG_ASSERT( ready() );
01735         return __sub < size()
01736            ?  _Base_type::operator[](__sub)
01737            : __unmatched_sub<_Bi_iter>();
01738       }
01739 
01740       /**
01741        * @brief Gets a %sub_match representing the match prefix.
01742        * @pre   ready() == true
01743        *
01744        * This function gets a reference to a %sub_match object representing the
01745        * part of the target range between the start of the target range and the
01746        * start of the match.
01747        */
01748       const_reference
01749       prefix() const
01750       {
01751         _GLIBCXX_DEBUG_ASSERT( ready() );
01752         return !empty()
01753                ? _Base_type::operator[](_Base_type::size() - 2)
01754            : __unmatched_sub<_Bi_iter>();
01755       }
01756 
01757       /**
01758        * @brief Gets a %sub_match representing the match suffix.
01759        * @pre   ready() == true
01760        *
01761        * This function gets a reference to a %sub_match object representing the
01762        * part of the target range between the end of the match and the end of
01763        * the target range.
01764        */
01765       const_reference
01766       suffix() const
01767       {
01768     _GLIBCXX_DEBUG_ASSERT( ready() );
01769     return !empty()
01770            ? _Base_type::operator[](_Base_type::size() - 1)
01771            : __unmatched_sub<_Bi_iter>();
01772       }
01773 
01774       /**
01775        * @brief Gets an iterator to the start of the %sub_match collection.
01776        */
01777       const_iterator
01778       begin() const
01779       { return _Base_type::begin(); }
01780 
01781       /**
01782        * @brief Gets an iterator to the start of the %sub_match collection.
01783        */
01784       const_iterator
01785       cbegin() const
01786       { return this->begin(); }
01787 
01788       /**
01789        * @brief Gets an iterator to one-past-the-end of the collection.
01790        */
01791       const_iterator
01792       end() const
01793       { return _Base_type::end() - 2; }
01794 
01795       /**
01796        * @brief Gets an iterator to one-past-the-end of the collection.
01797        */
01798       const_iterator
01799       cend() const
01800       { return this->end(); }
01801 
01802       //@}
01803 
01804       /**
01805        * @name 10.4 Formatting
01806        *
01807        * These functions perform formatted substitution of the matched
01808        * character sequences into their target.  The format specifiers and
01809        * escape sequences accepted by these functions are determined by
01810        * their @p flags parameter as documented above.
01811        */
01812        //@{
01813 
01814       /**
01815        * @pre   ready() == true
01816        */
01817       template<typename _Out_iter>
01818     _Out_iter
01819     format(_Out_iter __out, const char_type* __fmt_first,
01820            const char_type* __fmt_last,
01821            match_flag_type __flags = regex_constants::format_default) const;
01822 
01823       /**
01824        * @pre   ready() == true
01825        */
01826       template<typename _Out_iter, typename _St, typename _Sa>
01827     _Out_iter
01828     format(_Out_iter __out, const basic_string<char_type, _St, _Sa>& __fmt,
01829            match_flag_type __flags = regex_constants::format_default) const
01830     {
01831       return format(__out, __fmt.data(), __fmt.data() + __fmt.size(),
01832             __flags);
01833     }
01834 
01835       /**
01836        * @pre   ready() == true
01837        */
01838       template<typename _St, typename _Sa>
01839     basic_string<char_type, _St, _Sa>
01840     format(const basic_string<char_type, _St, _Sa>& __fmt,
01841            match_flag_type __flags = regex_constants::format_default) const
01842     {
01843       basic_string<char_type, _St, _Sa> __result;
01844       format(std::back_inserter(__result), __fmt, __flags);
01845       return __result;
01846     }
01847 
01848       /**
01849        * @pre   ready() == true
01850        */
01851       string_type
01852       format(const char_type* __fmt,
01853          match_flag_type __flags = regex_constants::format_default) const
01854       {
01855     string_type __result;
01856     format(std::back_inserter(__result),
01857            __fmt,
01858            __fmt + char_traits<char_type>::length(__fmt),
01859            __flags);
01860     return __result;
01861       }
01862 
01863       //@}
01864 
01865       /**
01866        * @name 10.5 Allocator
01867        */
01868       //@{
01869 
01870       /**
01871        * @brief Gets a copy of the allocator.
01872        */
01873       allocator_type
01874       get_allocator() const
01875       { return _Base_type::get_allocator(); }
01876 
01877       //@}
01878 
01879       /**
01880        * @name 10.6 Swap
01881        */
01882        //@{
01883 
01884       /**
01885        * @brief Swaps the contents of two match_results.
01886        */
01887       void
01888       swap(match_results& __that)
01889       {
01890     using std::swap;
01891     _Base_type::swap(__that);
01892     swap(_M_begin, __that._M_begin);
01893       }
01894       //@}
01895 
01896     private:
01897       template<typename, typename, typename, bool>
01898     friend class __detail::_Executor;
01899 
01900       template<typename, typename, typename>
01901     friend class regex_iterator;
01902 
01903       template<typename _Bp, typename _Ap, typename _Cp, typename _Rp,
01904     __detail::_RegexExecutorPolicy, bool>
01905     friend bool
01906     __detail::__regex_algo_impl(_Bp, _Bp, match_results<_Bp, _Ap>&,
01907                     const basic_regex<_Cp, _Rp>&,
01908                     regex_constants::match_flag_type);
01909 
01910       _Bi_iter _M_begin;
01911       bool     _M_in_iterator;
01912     };
01913 
01914   typedef match_results<const char*>             cmatch;
01915   typedef match_results<string::const_iterator>  smatch;
01916 #ifdef _GLIBCXX_USE_WCHAR_T
01917   typedef match_results<const wchar_t*>          wcmatch;
01918   typedef match_results<wstring::const_iterator> wsmatch;
01919 #endif
01920 
01921   // match_results comparisons
01922   /**
01923    * @brief Compares two match_results for equality.
01924    * @returns true if the two objects refer to the same match,
01925    * false otherwise.
01926    */
01927   template<typename _Bi_iter, typename _Alloc>
01928     inline bool
01929     operator==(const match_results<_Bi_iter, _Alloc>& __m1,
01930            const match_results<_Bi_iter, _Alloc>& __m2)
01931     {
01932       if (__m1.ready() != __m2.ready())
01933     return false;
01934       if (!__m1.ready())  // both are not ready
01935     return true;
01936       if (__m1.empty() != __m2.empty())
01937     return false;
01938       if (__m1.empty())   // both are empty
01939     return true;
01940       return __m1.prefix() == __m2.prefix()
01941     && __m1.size() == __m2.size()
01942     && std::equal(__m1.begin(), __m1.end(), __m2.begin())
01943     && __m1.suffix() == __m2.suffix();
01944     }
01945 
01946   /**
01947    * @brief Compares two match_results for inequality.
01948    * @returns true if the two objects do not refer to the same match,
01949    * false otherwise.
01950    */
01951   template<typename _Bi_iter, class _Alloc>
01952     inline bool
01953     operator!=(const match_results<_Bi_iter, _Alloc>& __m1,
01954            const match_results<_Bi_iter, _Alloc>& __m2)
01955     { return !(__m1 == __m2); }
01956 
01957   // [7.10.6] match_results swap
01958   /**
01959    * @brief Swaps two match results.
01960    * @param __lhs A match result.
01961    * @param __rhs A match result.
01962    *
01963    * The contents of the two match_results objects are swapped.
01964    */
01965   template<typename _Bi_iter, typename _Alloc>
01966     inline void
01967     swap(match_results<_Bi_iter, _Alloc>& __lhs,
01968      match_results<_Bi_iter, _Alloc>& __rhs)
01969     { __lhs.swap(__rhs); }
01970 
01971   // [7.11.2] Function template regex_match
01972   /**
01973    * @name Matching, Searching, and Replacing
01974    */
01975   //@{
01976 
01977   /**
01978    * @brief Determines if there is a match between the regular expression @p e
01979    * and all of the character sequence [first, last).
01980    *
01981    * @param __s     Start of the character sequence to match.
01982    * @param __e     One-past-the-end of the character sequence to match.
01983    * @param __m     The match results.
01984    * @param __re    The regular expression.
01985    * @param __flags Controls how the regular expression is matched.
01986    *
01987    * @retval true  A match exists.
01988    * @retval false Otherwise.
01989    *
01990    * @throws an exception of type regex_error.
01991    */
01992   template<typename _Bi_iter, typename _Alloc,
01993        typename _Ch_type, typename _Rx_traits>
01994     inline bool
01995     regex_match(_Bi_iter                                 __s,
01996         _Bi_iter                                 __e,
01997         match_results<_Bi_iter, _Alloc>&         __m,
01998         const basic_regex<_Ch_type, _Rx_traits>& __re,
01999         regex_constants::match_flag_type         __flags
02000                    = regex_constants::match_default)
02001     {
02002       return __detail::__regex_algo_impl<_Bi_iter, _Alloc, _Ch_type, _Rx_traits,
02003     __detail::_RegexExecutorPolicy::_S_auto, true>
02004       (__s, __e, __m, __re, __flags);
02005     }
02006 
02007   /**
02008    * @brief Indicates if there is a match between the regular expression @p e
02009    * and all of the character sequence [first, last).
02010    *
02011    * @param __first Beginning of the character sequence to match.
02012    * @param __last  One-past-the-end of the character sequence to match.
02013    * @param __re    The regular expression.
02014    * @param __flags Controls how the regular expression is matched.
02015    *
02016    * @retval true  A match exists.
02017    * @retval false Otherwise.
02018    *
02019    * @throws an exception of type regex_error.
02020    */
02021   template<typename _Bi_iter, typename _Ch_type, typename _Rx_traits>
02022     inline bool
02023     regex_match(_Bi_iter __first, _Bi_iter __last,
02024         const basic_regex<_Ch_type, _Rx_traits>& __re,
02025         regex_constants::match_flag_type __flags
02026         = regex_constants::match_default)
02027     {
02028       match_results<_Bi_iter> __what;
02029       return regex_match(__first, __last, __what, __re, __flags);
02030     }
02031 
02032   /**
02033    * @brief Determines if there is a match between the regular expression @p e
02034    * and a C-style null-terminated string.
02035    *
02036    * @param __s  The C-style null-terminated string to match.
02037    * @param __m  The match results.
02038    * @param __re The regular expression.
02039    * @param __f  Controls how the regular expression is matched.
02040    *
02041    * @retval true  A match exists.
02042    * @retval false Otherwise.
02043    *
02044    * @throws an exception of type regex_error.
02045    */
02046   template<typename _Ch_type, typename _Alloc, typename _Rx_traits>
02047     inline bool
02048     regex_match(const _Ch_type* __s,
02049         match_results<const _Ch_type*, _Alloc>& __m,
02050         const basic_regex<_Ch_type, _Rx_traits>& __re,
02051         regex_constants::match_flag_type __f
02052         = regex_constants::match_default)
02053     { return regex_match(__s, __s + _Rx_traits::length(__s), __m, __re, __f); }
02054 
02055   /**
02056    * @brief Determines if there is a match between the regular expression @p e
02057    * and a string.
02058    *
02059    * @param __s     The string to match.
02060    * @param __m     The match results.
02061    * @param __re    The regular expression.
02062    * @param __flags Controls how the regular expression is matched.
02063    *
02064    * @retval true  A match exists.
02065    * @retval false Otherwise.
02066    *
02067    * @throws an exception of type regex_error.
02068    */
02069   template<typename _Ch_traits, typename _Ch_alloc,
02070        typename _Alloc, typename _Ch_type, typename _Rx_traits>
02071     inline bool
02072     regex_match(const basic_string<_Ch_type, _Ch_traits, _Ch_alloc>& __s,
02073         match_results<typename basic_string<_Ch_type,
02074         _Ch_traits, _Ch_alloc>::const_iterator, _Alloc>& __m,
02075         const basic_regex<_Ch_type, _Rx_traits>& __re,
02076         regex_constants::match_flag_type __flags
02077         = regex_constants::match_default)
02078     { return regex_match(__s.begin(), __s.end(), __m, __re, __flags); }
02079 
02080   /**
02081    * @brief Indicates if there is a match between the regular expression @p e
02082    * and a C-style null-terminated string.
02083    *
02084    * @param __s  The C-style null-terminated string to match.
02085    * @param __re The regular expression.
02086    * @param __f  Controls how the regular expression is matched.
02087    *
02088    * @retval true  A match exists.
02089    * @retval false Otherwise.
02090    *
02091    * @throws an exception of type regex_error.
02092    */
02093   template<typename _Ch_type, class _Rx_traits>
02094     inline bool
02095     regex_match(const _Ch_type* __s,
02096         const basic_regex<_Ch_type, _Rx_traits>& __re,
02097         regex_constants::match_flag_type __f
02098         = regex_constants::match_default)
02099     { return regex_match(__s, __s + _Rx_traits::length(__s), __re, __f); }
02100 
02101   /**
02102    * @brief Indicates if there is a match between the regular expression @p e
02103    * and a string.
02104    *
02105    * @param __s     [IN] The string to match.
02106    * @param __re    [IN] The regular expression.
02107    * @param __flags [IN] Controls how the regular expression is matched.
02108    *
02109    * @retval true  A match exists.
02110    * @retval false Otherwise.
02111    *
02112    * @throws an exception of type regex_error.
02113    */
02114   template<typename _Ch_traits, typename _Str_allocator,
02115        typename _Ch_type, typename _Rx_traits>
02116     inline bool
02117     regex_match(const basic_string<_Ch_type, _Ch_traits, _Str_allocator>& __s,
02118         const basic_regex<_Ch_type, _Rx_traits>& __re,
02119         regex_constants::match_flag_type __flags
02120         = regex_constants::match_default)
02121     { return regex_match(__s.begin(), __s.end(), __re, __flags); }
02122 
02123   // [7.11.3] Function template regex_search
02124   /**
02125    * Searches for a regular expression within a range.
02126    * @param __s     [IN]  The start of the string to search.
02127    * @param __e     [IN]  One-past-the-end of the string to search.
02128    * @param __m     [OUT] The match results.
02129    * @param __re    [IN]  The regular expression to search for.
02130    * @param __flags [IN]  Search policy flags.
02131    * @retval true  A match was found within the string.
02132    * @retval false No match was found within the string, the content of %m is
02133    *               undefined.
02134    *
02135    * @throws an exception of type regex_error.
02136    */
02137   template<typename _Bi_iter, typename _Alloc,
02138        typename _Ch_type, typename _Rx_traits>
02139     inline bool
02140     regex_search(_Bi_iter __s, _Bi_iter __e,
02141          match_results<_Bi_iter, _Alloc>& __m,
02142          const basic_regex<_Ch_type, _Rx_traits>& __re,
02143          regex_constants::match_flag_type __flags
02144          = regex_constants::match_default)
02145     {
02146       return __detail::__regex_algo_impl<_Bi_iter, _Alloc, _Ch_type, _Rx_traits,
02147     __detail::_RegexExecutorPolicy::_S_auto, false>
02148       (__s, __e, __m, __re, __flags);
02149     }
02150 
02151   /**
02152    * Searches for a regular expression within a range.
02153    * @param __first [IN]  The start of the string to search.
02154    * @param __last  [IN]  One-past-the-end of the string to search.
02155    * @param __re    [IN]  The regular expression to search for.
02156    * @param __flags [IN]  Search policy flags.
02157    * @retval true  A match was found within the string.
02158    * @retval false No match was found within the string.
02159    *
02160    * @throws an exception of type regex_error.
02161    */
02162   template<typename _Bi_iter, typename _Ch_type, typename _Rx_traits>
02163     inline bool
02164     regex_search(_Bi_iter __first, _Bi_iter __last,
02165          const basic_regex<_Ch_type, _Rx_traits>& __re,
02166          regex_constants::match_flag_type __flags
02167          = regex_constants::match_default)
02168     {
02169       match_results<_Bi_iter> __what;
02170       return regex_search(__first, __last, __what, __re, __flags);
02171     }
02172 
02173   /**
02174    * @brief Searches for a regular expression within a C-string.
02175    * @param __s [IN]  A C-string to search for the regex.
02176    * @param __m [OUT] The set of regex matches.
02177    * @param __e [IN]  The regex to search for in @p s.
02178    * @param __f [IN]  The search flags.
02179    * @retval true  A match was found within the string.
02180    * @retval false No match was found within the string, the content of %m is
02181    *               undefined.
02182    *
02183    * @throws an exception of type regex_error.
02184    */
02185   template<typename _Ch_type, class _Alloc, class _Rx_traits>
02186     inline bool
02187     regex_search(const _Ch_type* __s,
02188          match_results<const _Ch_type*, _Alloc>& __m,
02189          const basic_regex<_Ch_type, _Rx_traits>& __e,
02190          regex_constants::match_flag_type __f
02191          = regex_constants::match_default)
02192     { return regex_search(__s, __s + _Rx_traits::length(__s), __m, __e, __f); }
02193 
02194   /**
02195    * @brief Searches for a regular expression within a C-string.
02196    * @param __s [IN]  The C-string to search.
02197    * @param __e [IN]  The regular expression to search for.
02198    * @param __f [IN]  Search policy flags.
02199    * @retval true  A match was found within the string.
02200    * @retval false No match was found within the string.
02201    *
02202    * @throws an exception of type regex_error.
02203    */
02204   template<typename _Ch_type, typename _Rx_traits>
02205     inline bool
02206     regex_search(const _Ch_type* __s,
02207          const basic_regex<_Ch_type, _Rx_traits>& __e,
02208          regex_constants::match_flag_type __f
02209          = regex_constants::match_default)
02210     { return regex_search(__s, __s + _Rx_traits::length(__s), __e, __f); }
02211 
02212   /**
02213    * @brief Searches for a regular expression within a string.
02214    * @param __s     [IN]  The string to search.
02215    * @param __e     [IN]  The regular expression to search for.
02216    * @param __flags [IN]  Search policy flags.
02217    * @retval true  A match was found within the string.
02218    * @retval false No match was found within the string.
02219    *
02220    * @throws an exception of type regex_error.
02221    */
02222   template<typename _Ch_traits, typename _String_allocator,
02223        typename _Ch_type, typename _Rx_traits>
02224     inline bool
02225     regex_search(const basic_string<_Ch_type, _Ch_traits,
02226          _String_allocator>& __s,
02227          const basic_regex<_Ch_type, _Rx_traits>& __e,
02228          regex_constants::match_flag_type __flags
02229          = regex_constants::match_default)
02230     { return regex_search(__s.begin(), __s.end(), __e, __flags); }
02231 
02232   /**
02233    * @brief Searches for a regular expression within a string.
02234    * @param __s [IN]  A C++ string to search for the regex.
02235    * @param __m [OUT] The set of regex matches.
02236    * @param __e [IN]  The regex to search for in @p s.
02237    * @param __f [IN]  The search flags.
02238    * @retval true  A match was found within the string.
02239    * @retval false No match was found within the string, the content of %m is
02240    *               undefined.
02241    *
02242    * @throws an exception of type regex_error.
02243    */
02244   template<typename _Ch_traits, typename _Ch_alloc,
02245        typename _Alloc, typename _Ch_type,
02246        typename _Rx_traits>
02247     inline bool
02248     regex_search(const basic_string<_Ch_type, _Ch_traits, _Ch_alloc>& __s,
02249          match_results<typename basic_string<_Ch_type,
02250          _Ch_traits, _Ch_alloc>::const_iterator, _Alloc>& __m,
02251          const basic_regex<_Ch_type, _Rx_traits>& __e,
02252          regex_constants::match_flag_type __f
02253          = regex_constants::match_default)
02254     { return regex_search(__s.begin(), __s.end(), __m, __e, __f); }
02255 
02256   // std [28.11.4] Function template regex_replace
02257   /**
02258    * @brief Search for a regular expression within a range for multiple times,
02259    and replace the matched parts through filling a format string.
02260    * @param __out   [OUT] The output iterator.
02261    * @param __first [IN]  The start of the string to search.
02262    * @param __last  [IN]  One-past-the-end of the string to search.
02263    * @param __e     [IN]  The regular expression to search for.
02264    * @param __fmt   [IN]  The format string.
02265    * @param __flags [IN]  Search and replace policy flags.
02266    *
02267    * @returns __out
02268    * @throws an exception of type regex_error.
02269    */
02270   template<typename _Out_iter, typename _Bi_iter,
02271        typename _Rx_traits, typename _Ch_type,
02272        typename _St, typename _Sa>
02273     inline _Out_iter
02274     regex_replace(_Out_iter __out, _Bi_iter __first, _Bi_iter __last,
02275           const basic_regex<_Ch_type, _Rx_traits>& __e,
02276           const basic_string<_Ch_type, _St, _Sa>& __fmt,
02277           regex_constants::match_flag_type __flags
02278           = regex_constants::match_default)
02279     {
02280       return regex_replace(__out, __first, __last, __e, __fmt.c_str(), __flags);
02281     }
02282 
02283   /**
02284    * @brief Search for a regular expression within a range for multiple times,
02285    and replace the matched parts through filling a format C-string.
02286    * @param __out   [OUT] The output iterator.
02287    * @param __first [IN]  The start of the string to search.
02288    * @param __last  [IN]  One-past-the-end of the string to search.
02289    * @param __e     [IN]  The regular expression to search for.
02290    * @param __fmt   [IN]  The format C-string.
02291    * @param __flags [IN]  Search and replace policy flags.
02292    *
02293    * @returns __out
02294    * @throws an exception of type regex_error.
02295    */
02296   template<typename _Out_iter, typename _Bi_iter,
02297        typename _Rx_traits, typename _Ch_type>
02298     _Out_iter
02299     regex_replace(_Out_iter __out, _Bi_iter __first, _Bi_iter __last,
02300           const basic_regex<_Ch_type, _Rx_traits>& __e,
02301           const _Ch_type* __fmt,
02302           regex_constants::match_flag_type __flags
02303           = regex_constants::match_default);
02304 
02305   /**
02306    * @brief Search for a regular expression within a string for multiple times,
02307    and replace the matched parts through filling a format string.
02308    * @param __s     [IN] The string to search and replace.
02309    * @param __e     [IN] The regular expression to search for.
02310    * @param __fmt   [IN] The format string.
02311    * @param __flags [IN] Search and replace policy flags.
02312    *
02313    * @returns The string after replacing.
02314    * @throws an exception of type regex_error.
02315    */
02316   template<typename _Rx_traits, typename _Ch_type,
02317        typename _St, typename _Sa, typename _Fst, typename _Fsa>
02318     inline basic_string<_Ch_type, _St, _Sa>
02319     regex_replace(const basic_string<_Ch_type, _St, _Sa>& __s,
02320           const basic_regex<_Ch_type, _Rx_traits>& __e,
02321           const basic_string<_Ch_type, _Fst, _Fsa>& __fmt,
02322           regex_constants::match_flag_type __flags
02323           = regex_constants::match_default)
02324     {
02325       basic_string<_Ch_type, _St, _Sa> __result;
02326       regex_replace(std::back_inserter(__result),
02327             __s.begin(), __s.end(), __e, __fmt, __flags);
02328       return __result;
02329     }
02330 
02331   /**
02332    * @brief Search for a regular expression within a string for multiple times,
02333    and replace the matched parts through filling a format C-string.
02334    * @param __s     [IN] The string to search and replace.
02335    * @param __e     [IN] The regular expression to search for.
02336    * @param __fmt   [IN] The format C-string.
02337    * @param __flags [IN] Search and replace policy flags.
02338    *
02339    * @returns The string after replacing.
02340    * @throws an exception of type regex_error.
02341    */
02342   template<typename _Rx_traits, typename _Ch_type,
02343        typename _St, typename _Sa>
02344     inline basic_string<_Ch_type, _St, _Sa>
02345     regex_replace(const basic_string<_Ch_type, _St, _Sa>& __s,
02346           const basic_regex<_Ch_type, _Rx_traits>& __e,
02347           const _Ch_type* __fmt,
02348           regex_constants::match_flag_type __flags
02349           = regex_constants::match_default)
02350     {
02351       basic_string<_Ch_type, _St, _Sa> __result;
02352       regex_replace(std::back_inserter(__result),
02353             __s.begin(), __s.end(), __e, __fmt, __flags);
02354       return __result;
02355     }
02356 
02357   /**
02358    * @brief Search for a regular expression within a C-string for multiple
02359    times, and replace the matched parts through filling a format string.
02360    * @param __s     [IN] The C-string to search and replace.
02361    * @param __e     [IN] The regular expression to search for.
02362    * @param __fmt   [IN] The format string.
02363    * @param __flags [IN] Search and replace policy flags.
02364    *
02365    * @returns The string after replacing.
02366    * @throws an exception of type regex_error.
02367    */
02368   template<typename _Rx_traits, typename _Ch_type,
02369        typename _St, typename _Sa>
02370     inline basic_string<_Ch_type>
02371     regex_replace(const _Ch_type* __s,
02372           const basic_regex<_Ch_type, _Rx_traits>& __e,
02373           const basic_string<_Ch_type, _St, _Sa>& __fmt,
02374           regex_constants::match_flag_type __flags
02375           = regex_constants::match_default)
02376     {
02377       basic_string<_Ch_type> __result;
02378       regex_replace(std::back_inserter(__result), __s,
02379             __s + char_traits<_Ch_type>::length(__s),
02380             __e, __fmt, __flags);
02381       return __result;
02382     }
02383 
02384   /**
02385    * @brief Search for a regular expression within a C-string for multiple
02386    times, and replace the matched parts through filling a format C-string.
02387    * @param __s     [IN] The C-string to search and replace.
02388    * @param __e     [IN] The regular expression to search for.
02389    * @param __fmt   [IN] The format C-string.
02390    * @param __flags [IN] Search and replace policy flags.
02391    *
02392    * @returns The string after replacing.
02393    * @throws an exception of type regex_error.
02394    */
02395   template<typename _Rx_traits, typename _Ch_type>
02396     inline basic_string<_Ch_type>
02397     regex_replace(const _Ch_type* __s,
02398           const basic_regex<_Ch_type, _Rx_traits>& __e,
02399           const _Ch_type* __fmt,
02400           regex_constants::match_flag_type __flags
02401           = regex_constants::match_default)
02402     {
02403       basic_string<_Ch_type> __result;
02404       regex_replace(std::back_inserter(__result), __s,
02405             __s + char_traits<_Ch_type>::length(__s),
02406             __e, __fmt, __flags);
02407       return __result;
02408     }
02409 
02410   //@}
02411 
02412   // std [28.12] Class template regex_iterator
02413   /**
02414    * An iterator adaptor that will provide repeated calls of regex_search over
02415    * a range until no more matches remain.
02416    */
02417   template<typename _Bi_iter,
02418        typename _Ch_type = typename iterator_traits<_Bi_iter>::value_type,
02419        typename _Rx_traits = regex_traits<_Ch_type> >
02420     class regex_iterator
02421     {
02422     public:
02423       typedef basic_regex<_Ch_type, _Rx_traits>  regex_type;
02424       typedef match_results<_Bi_iter>            value_type;
02425       typedef std::ptrdiff_t                     difference_type;
02426       typedef const value_type*                  pointer;
02427       typedef const value_type&                  reference;
02428       typedef std::forward_iterator_tag          iterator_category;
02429 
02430       /**
02431        * @brief Provides a singular iterator, useful for indicating
02432        * one-past-the-end of a range.
02433        */
02434       regex_iterator()
02435       : _M_match()
02436       { }
02437 
02438       /**
02439        * Constructs a %regex_iterator...
02440        * @param __a  [IN] The start of a text range to search.
02441        * @param __b  [IN] One-past-the-end of the text range to search.
02442        * @param __re [IN] The regular expression to match.
02443        * @param __m  [IN] Policy flags for match rules.
02444        */
02445       regex_iterator(_Bi_iter __a, _Bi_iter __b, const regex_type& __re,
02446              regex_constants::match_flag_type __m
02447              = regex_constants::match_default)
02448       : _M_begin(__a), _M_end(__b), _M_pregex(&__re), _M_flags(__m), _M_match()
02449       {
02450     if (!regex_search(_M_begin, _M_end, _M_match, *_M_pregex, _M_flags))
02451       *this = regex_iterator();
02452       }
02453 
02454       /**
02455        * Copy constructs a %regex_iterator.
02456        */
02457       regex_iterator(const regex_iterator& __rhs) = default;
02458 
02459       /**
02460        * @brief Assigns one %regex_iterator to another.
02461        */
02462       regex_iterator&
02463       operator=(const regex_iterator& __rhs) = default;
02464 
02465       /**
02466        * @brief Tests the equivalence of two regex iterators.
02467        */
02468       bool
02469       operator==(const regex_iterator& __rhs) const;
02470 
02471       /**
02472        * @brief Tests the inequivalence of two regex iterators.
02473        */
02474       bool
02475       operator!=(const regex_iterator& __rhs) const
02476       { return !(*this == __rhs); }
02477 
02478       /**
02479        * @brief Dereferences a %regex_iterator.
02480        */
02481       const value_type&
02482       operator*() const
02483       { return _M_match; }
02484 
02485       /**
02486        * @brief Selects a %regex_iterator member.
02487        */
02488       const value_type*
02489       operator->() const
02490       { return &_M_match; }
02491 
02492       /**
02493        * @brief Increments a %regex_iterator.
02494        */
02495       regex_iterator&
02496       operator++();
02497 
02498       /**
02499        * @brief Postincrements a %regex_iterator.
02500        */
02501       regex_iterator
02502       operator++(int)
02503       {
02504     auto __tmp = *this;
02505     ++(*this);
02506     return __tmp;
02507       }
02508 
02509     private:
02510       _Bi_iter                         _M_begin;
02511       _Bi_iter                         _M_end;
02512       const regex_type*                _M_pregex;
02513       regex_constants::match_flag_type _M_flags;
02514       match_results<_Bi_iter>          _M_match;
02515     };
02516 
02517   typedef regex_iterator<const char*>             cregex_iterator;
02518   typedef regex_iterator<string::const_iterator>  sregex_iterator;
02519 #ifdef _GLIBCXX_USE_WCHAR_T
02520   typedef regex_iterator<const wchar_t*>          wcregex_iterator;
02521   typedef regex_iterator<wstring::const_iterator> wsregex_iterator;
02522 #endif
02523 
02524   // [7.12.2] Class template regex_token_iterator
02525   /**
02526    * Iterates over submatches in a range (or @a splits a text string).
02527    *
02528    * The purpose of this iterator is to enumerate all, or all specified,
02529    * matches of a regular expression within a text range.  The dereferenced
02530    * value of an iterator of this class is a std::sub_match object.
02531    */
02532   template<typename _Bi_iter,
02533        typename _Ch_type = typename iterator_traits<_Bi_iter>::value_type,
02534        typename _Rx_traits = regex_traits<_Ch_type> >
02535     class regex_token_iterator
02536     {
02537     public:
02538       typedef basic_regex<_Ch_type, _Rx_traits> regex_type;
02539       typedef sub_match<_Bi_iter>               value_type;
02540       typedef std::ptrdiff_t                    difference_type;
02541       typedef const value_type*                 pointer;
02542       typedef const value_type&                 reference;
02543       typedef std::forward_iterator_tag         iterator_category;
02544 
02545     public:
02546       /**
02547        * @brief Default constructs a %regex_token_iterator.
02548        *
02549        * A default-constructed %regex_token_iterator is a singular iterator
02550        * that will compare equal to the one-past-the-end value for any
02551        * iterator of the same type.
02552        */
02553       regex_token_iterator()
02554       : _M_position(), _M_subs(), _M_suffix(), _M_n(0), _M_result(nullptr),
02555       _M_has_m1(false)
02556       { }
02557 
02558       /**
02559        * Constructs a %regex_token_iterator...
02560        * @param __a          [IN] The start of the text to search.
02561        * @param __b          [IN] One-past-the-end of the text to search.
02562        * @param __re         [IN] The regular expression to search for.
02563        * @param __submatch   [IN] Which submatch to return.  There are some
02564        *                        special values for this parameter:
02565        *                        - -1 each enumerated subexpression does NOT
02566        *                          match the regular expression (aka field
02567        *                          splitting)
02568        *                        - 0 the entire string matching the
02569        *                          subexpression is returned for each match
02570        *                          within the text.
02571        *                        - >0 enumerates only the indicated
02572        *                          subexpression from a match within the text.
02573        * @param __m          [IN] Policy flags for match rules.
02574        */
02575       regex_token_iterator(_Bi_iter __a, _Bi_iter __b, const regex_type& __re,
02576                int __submatch = 0,
02577                regex_constants::match_flag_type __m
02578                = regex_constants::match_default)
02579       : _M_position(__a, __b, __re, __m), _M_subs(1, __submatch), _M_n(0)
02580       { _M_init(__a, __b); }
02581 
02582       /**
02583        * Constructs a %regex_token_iterator...
02584        * @param __a          [IN] The start of the text to search.
02585        * @param __b          [IN] One-past-the-end of the text to search.
02586        * @param __re         [IN] The regular expression to search for.
02587        * @param __submatches [IN] A list of subexpressions to return for each
02588        *                          regular expression match within the text.
02589        * @param __m          [IN] Policy flags for match rules.
02590        */
02591       regex_token_iterator(_Bi_iter __a, _Bi_iter __b,
02592                const regex_type& __re,
02593                const std::vector<int>& __submatches,
02594                regex_constants::match_flag_type __m
02595                  = regex_constants::match_default)
02596       : _M_position(__a, __b, __re, __m), _M_subs(__submatches), _M_n(0)
02597       { _M_init(__a, __b); }
02598 
02599       /**
02600        * Constructs a %regex_token_iterator...
02601        * @param __a          [IN] The start of the text to search.
02602        * @param __b          [IN] One-past-the-end of the text to search.
02603        * @param __re         [IN] The regular expression to search for.
02604        * @param __submatches [IN] A list of subexpressions to return for each
02605        *                          regular expression match within the text.
02606        * @param __m          [IN] Policy flags for match rules.
02607        */
02608       regex_token_iterator(_Bi_iter __a, _Bi_iter __b,
02609                const regex_type& __re,
02610                initializer_list<int> __submatches,
02611                regex_constants::match_flag_type __m
02612                  = regex_constants::match_default)
02613       : _M_position(__a, __b, __re, __m), _M_subs(__submatches), _M_n(0)
02614       { _M_init(__a, __b); }
02615 
02616       /**
02617        * Constructs a %regex_token_iterator...
02618        * @param __a          [IN] The start of the text to search.
02619        * @param __b          [IN] One-past-the-end of the text to search.
02620        * @param __re         [IN] The regular expression to search for.
02621        * @param __submatches [IN] A list of subexpressions to return for each
02622        *                          regular expression match within the text.
02623        * @param __m          [IN] Policy flags for match rules.
02624        */
02625       template<std::size_t _Nm>
02626     regex_token_iterator(_Bi_iter __a, _Bi_iter __b,
02627                  const regex_type& __re,
02628                  const int (&__submatches)[_Nm],
02629                  regex_constants::match_flag_type __m
02630                  = regex_constants::match_default)
02631       : _M_position(__a, __b, __re, __m),
02632       _M_subs(__submatches, __submatches + _Nm), _M_n(0)
02633       { _M_init(__a, __b); }
02634 
02635       /**
02636        * @brief Copy constructs a %regex_token_iterator.
02637        * @param __rhs [IN] A %regex_token_iterator to copy.
02638        */
02639       regex_token_iterator(const regex_token_iterator& __rhs)
02640       : _M_position(__rhs._M_position), _M_subs(__rhs._M_subs),
02641       _M_suffix(__rhs._M_suffix), _M_n(__rhs._M_n), _M_has_m1(__rhs._M_has_m1)
02642       { _M_normalize_result(); }
02643 
02644       /**
02645        * @brief Assigns a %regex_token_iterator to another.
02646        * @param __rhs [IN] A %regex_token_iterator to copy.
02647        */
02648       regex_token_iterator&
02649       operator=(const regex_token_iterator& __rhs);
02650 
02651       /**
02652        * @brief Compares a %regex_token_iterator to another for equality.
02653        */
02654       bool
02655       operator==(const regex_token_iterator& __rhs) const;
02656 
02657       /**
02658        * @brief Compares a %regex_token_iterator to another for inequality.
02659        */
02660       bool
02661       operator!=(const regex_token_iterator& __rhs) const
02662       { return !(*this == __rhs); }
02663 
02664       /**
02665        * @brief Dereferences a %regex_token_iterator.
02666        */
02667       const value_type&
02668       operator*() const
02669       { return *_M_result; }
02670 
02671       /**
02672        * @brief Selects a %regex_token_iterator member.
02673        */
02674       const value_type*
02675       operator->() const
02676       { return _M_result; }
02677 
02678       /**
02679        * @brief Increments a %regex_token_iterator.
02680        */
02681       regex_token_iterator&
02682       operator++();
02683 
02684       /**
02685        * @brief Postincrements a %regex_token_iterator.
02686        */
02687       regex_token_iterator
02688       operator++(int)
02689       {
02690     auto __tmp = *this;
02691     ++(*this);
02692     return __tmp;
02693       }
02694 
02695     private:
02696       typedef regex_iterator<_Bi_iter, _Ch_type, _Rx_traits> _Position;
02697 
02698       void
02699       _M_init(_Bi_iter __a, _Bi_iter __b);
02700 
02701       const value_type&
02702       _M_current_match() const
02703       {
02704     if (_M_subs[_M_n] == -1)
02705       return (*_M_position).prefix();
02706     else
02707       return (*_M_position)[_M_subs[_M_n]];
02708       }
02709 
02710       constexpr bool
02711       _M_end_of_seq() const
02712       { return _M_result == nullptr; }
02713 
02714       // [28.12.2.2.4]
02715       void
02716       _M_normalize_result()
02717       {
02718     if (_M_position != _Position())
02719       _M_result = &_M_current_match();
02720     else if (_M_has_m1)
02721       _M_result = &_M_suffix;
02722     else
02723       _M_result = nullptr;
02724       }
02725 
02726       _Position         _M_position;
02727       std::vector<int>  _M_subs;
02728       value_type        _M_suffix;
02729       std::size_t       _M_n;
02730       const value_type* _M_result;
02731 
02732       // Show whether _M_subs contains -1
02733       bool              _M_has_m1;
02734     };
02735 
02736   /** @brief Token iterator for C-style NULL-terminated strings. */
02737   typedef regex_token_iterator<const char*>             cregex_token_iterator;
02738 
02739   /** @brief Token iterator for standard strings. */
02740   typedef regex_token_iterator<string::const_iterator>  sregex_token_iterator;
02741 
02742 #ifdef _GLIBCXX_USE_WCHAR_T
02743   /** @brief Token iterator for C-style NULL-terminated wide strings. */
02744   typedef regex_token_iterator<const wchar_t*>          wcregex_token_iterator;
02745 
02746   /** @brief Token iterator for standard wide-character strings. */
02747   typedef regex_token_iterator<wstring::const_iterator> wsregex_token_iterator;
02748 #endif
02749 
02750   //@} // group regex
02751 _GLIBCXX_END_NAMESPACE_VERSION
02752 } // namespace
02753 
02754 #include <bits/regex.tcc>