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