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), _M_loc(std::move(__loc)),
00766         _M_automaton(__detail::__compile_nfa<_FwdIter, _Rx_traits>(
00767           std::move(__first), std::move(__last), _M_loc, _M_flags))
00768         { }
00769 
00770       template<typename _Bp, typename _Ap, typename _Cp, typename _Rp,
00771         __detail::_RegexExecutorPolicy, bool>
00772         friend bool __detail::
00773 #if _GLIBCXX_INLINE_VERSION
00774         __7:: // Required due to PR c++/59256
00775 #endif
00776         __regex_algo_impl(_Bp, _Bp, match_results<_Bp, _Ap>&,
00777                           const basic_regex<_Cp, _Rp>&,
00778                           regex_constants::match_flag_type);
00779 
00780       template<typename, typename, typename, bool>
00781         friend class __detail::_Executor;
00782 
00783       flag_type              _M_flags;
00784       locale_type            _M_loc;
00785       _AutomatonPtr          _M_automaton;
00786     };
00787 
00788   /** @brief Standard regular expressions. */
00789   typedef basic_regex<char>    regex;
00790 
00791 #ifdef _GLIBCXX_USE_WCHAR_T
00792   /** @brief Standard wide-character regular expressions. */
00793   typedef basic_regex<wchar_t> wregex;
00794 #endif
00795 
00796 
00797   // [7.8.6] basic_regex swap
00798   /**
00799    * @brief Swaps the contents of two regular expression objects.
00800    * @param __lhs First regular expression.
00801    * @param __rhs Second regular expression.
00802    */
00803   template<typename _Ch_type, typename _Rx_traits>
00804     inline void
00805     swap(basic_regex<_Ch_type, _Rx_traits>& __lhs,
00806          basic_regex<_Ch_type, _Rx_traits>& __rhs)
00807     { __lhs.swap(__rhs); }
00808 
00809 
00810   // [7.9] Class template sub_match
00811   /**
00812    * A sequence of characters matched by a particular marked sub-expression.
00813    *
00814    * An object of this class is essentially a pair of iterators marking a
00815    * matched subexpression within a regular expression pattern match. Such
00816    * objects can be converted to and compared with std::basic_string objects
00817    * of a similar base character type as the pattern matched by the regular
00818    * expression.
00819    *
00820    * The iterators that make up the pair are the usual half-open interval
00821    * referencing the actual original pattern matched.
00822    */
00823   template<typename _BiIter>
00824     class sub_match : public std::pair<_BiIter, _BiIter>
00825     {
00826       typedef iterator_traits<_BiIter>                  __iter_traits;
00827         
00828     public:
00829       typedef typename __iter_traits::value_type        value_type;
00830       typedef typename __iter_traits::difference_type   difference_type;
00831       typedef _BiIter                                   iterator;
00832       typedef std::basic_string<value_type>             string_type;
00833 
00834       bool matched;
00835 
00836       constexpr sub_match() : matched() { }
00837 
00838       /**
00839        * Gets the length of the matching sequence.
00840        */
00841       difference_type
00842       length() const
00843       { return this->matched ? std::distance(this->first, this->second) : 0; }
00844 
00845       /**
00846        * @brief Gets the matching sequence as a string.
00847        *
00848        * @returns the matching sequence as a string.
00849        *
00850        * This is the implicit conversion operator.  It is identical to the
00851        * str() member function except that it will want to pop up in
00852        * unexpected places and cause a great deal of confusion and cursing
00853        * from the unwary.
00854        */
00855       operator string_type() const
00856       {
00857         return this->matched
00858           ? string_type(this->first, this->second)
00859           : string_type();
00860       }
00861 
00862       /**
00863        * @brief Gets the matching sequence as a string.
00864        *
00865        * @returns the matching sequence as a string.
00866        */
00867       string_type
00868       str() const
00869       {
00870         return this->matched
00871           ? string_type(this->first, this->second)
00872           : string_type();
00873       }
00874 
00875       /**
00876        * @brief Compares this and another matched sequence.
00877        *
00878        * @param __s Another matched sequence to compare to this one.
00879        *
00880        * @retval <0 this matched sequence will collate before @p __s.
00881        * @retval =0 this matched sequence is equivalent to @p __s.
00882        * @retval <0 this matched sequence will collate after @p __s.
00883        */
00884       int
00885       compare(const sub_match& __s) const
00886       { return this->str().compare(__s.str()); }
00887 
00888       /**
00889        * @brief Compares this sub_match to a string.
00890        *
00891        * @param __s A string to compare to this sub_match.
00892        *
00893        * @retval <0 this matched sequence will collate before @p __s.
00894        * @retval =0 this matched sequence is equivalent to @p __s.
00895        * @retval <0 this matched sequence will collate after @p __s.
00896        */
00897       int
00898       compare(const string_type& __s) const
00899       { return this->str().compare(__s); }
00900 
00901       /**
00902        * @brief Compares this sub_match to a C-style string.
00903        *
00904        * @param __s A C-style string to compare to this sub_match.
00905        *
00906        * @retval <0 this matched sequence will collate before @p __s.
00907        * @retval =0 this matched sequence is equivalent to @p __s.
00908        * @retval <0 this matched sequence will collate after @p __s.
00909        */
00910       int
00911       compare(const value_type* __s) const
00912       { return this->str().compare(__s); }
00913     };
00914 
00915 
00916   /** @brief Standard regex submatch over a C-style null-terminated string. */
00917   typedef sub_match<const char*>             csub_match;
00918 
00919   /** @brief Standard regex submatch over a standard string. */
00920   typedef sub_match<string::const_iterator>  ssub_match;
00921 
00922 #ifdef _GLIBCXX_USE_WCHAR_T
00923   /** @brief Regex submatch over a C-style null-terminated wide string. */
00924   typedef sub_match<const wchar_t*>          wcsub_match;
00925 
00926   /** @brief Regex submatch over a standard wide string. */
00927   typedef sub_match<wstring::const_iterator> wssub_match;
00928 #endif
00929 
00930   // [7.9.2] sub_match non-member operators
00931 
00932   /**
00933    * @brief Tests the equivalence of two regular expression submatches.
00934    * @param __lhs First regular expression submatch.
00935    * @param __rhs Second regular expression submatch.
00936    * @returns true if @a __lhs  is equivalent to @a __rhs, false otherwise.
00937    */
00938   template<typename _BiIter>
00939     inline bool
00940     operator==(const sub_match<_BiIter>& __lhs, const sub_match<_BiIter>& __rhs)
00941     { return __lhs.compare(__rhs) == 0; }
00942 
00943   /**
00944    * @brief Tests the inequivalence of two regular expression submatches.
00945    * @param __lhs First regular expression submatch.
00946    * @param __rhs Second regular expression submatch.
00947    * @returns true if @a __lhs  is not equivalent to @a __rhs, false otherwise.
00948    */
00949   template<typename _BiIter>
00950     inline bool
00951     operator!=(const sub_match<_BiIter>& __lhs, const sub_match<_BiIter>& __rhs)
00952     { return __lhs.compare(__rhs) != 0; }
00953 
00954   /**
00955    * @brief Tests the ordering of two regular expression submatches.
00956    * @param __lhs First regular expression submatch.
00957    * @param __rhs Second regular expression submatch.
00958    * @returns true if @a __lhs precedes @a __rhs, false otherwise.
00959    */
00960   template<typename _BiIter>
00961     inline bool
00962     operator<(const sub_match<_BiIter>& __lhs, const sub_match<_BiIter>& __rhs)
00963     { return __lhs.compare(__rhs) < 0; }
00964 
00965   /**
00966    * @brief Tests the ordering of two regular expression submatches.
00967    * @param __lhs First regular expression submatch.
00968    * @param __rhs Second regular expression submatch.
00969    * @returns true if @a __lhs does not succeed @a __rhs, false otherwise.
00970    */
00971   template<typename _BiIter>
00972     inline bool
00973     operator<=(const sub_match<_BiIter>& __lhs, const sub_match<_BiIter>& __rhs)
00974     { return __lhs.compare(__rhs) <= 0; }
00975 
00976   /**
00977    * @brief Tests the ordering of two regular expression submatches.
00978    * @param __lhs First regular expression submatch.
00979    * @param __rhs Second regular expression submatch.
00980    * @returns true if @a __lhs does not precede @a __rhs, false otherwise.
00981    */
00982   template<typename _BiIter>
00983     inline bool
00984     operator>=(const sub_match<_BiIter>& __lhs, const sub_match<_BiIter>& __rhs)
00985     { return __lhs.compare(__rhs) >= 0; }
00986 
00987   /**
00988    * @brief Tests the ordering of two regular expression submatches.
00989    * @param __lhs First regular expression submatch.
00990    * @param __rhs Second regular expression submatch.
00991    * @returns true if @a __lhs succeeds @a __rhs, false otherwise.
00992    */
00993   template<typename _BiIter>
00994     inline bool
00995     operator>(const sub_match<_BiIter>& __lhs, const sub_match<_BiIter>& __rhs)
00996     { return __lhs.compare(__rhs) > 0; }
00997 
00998   // Alias for sub_match'd string.
00999   template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
01000     using __sub_match_string = basic_string<
01001                               typename iterator_traits<_Bi_iter>::value_type,
01002                               _Ch_traits, _Ch_alloc>;
01003 
01004   /**
01005    * @brief Tests the equivalence of a string and a regular expression
01006    *        submatch.
01007    * @param __lhs A string.
01008    * @param __rhs A regular expression submatch.
01009    * @returns true if @a __lhs  is equivalent to @a __rhs, false otherwise.
01010    */
01011   template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
01012     inline bool
01013     operator==(const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __lhs,
01014                const sub_match<_Bi_iter>& __rhs)
01015     {
01016       typedef typename sub_match<_Bi_iter>::string_type string_type;
01017       return __rhs.compare(string_type(__lhs.data(), __lhs.size())) == 0;
01018     }
01019 
01020   /**
01021    * @brief Tests the inequivalence of a string and a regular expression
01022    *        submatch.
01023    * @param __lhs A string.
01024    * @param __rhs A regular expression submatch.
01025    * @returns true if @a __lhs  is not equivalent to @a __rhs, false otherwise.
01026    */
01027   template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
01028     inline bool
01029     operator!=(const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __lhs,
01030                const sub_match<_Bi_iter>& __rhs)
01031     { return !(__lhs == __rhs); }
01032 
01033   /**
01034    * @brief Tests the ordering of a string and a regular expression submatch.
01035    * @param __lhs A string.
01036    * @param __rhs A regular expression submatch.
01037    * @returns true if @a __lhs precedes @a __rhs, false otherwise.
01038    */
01039   template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
01040     inline bool
01041     operator<(const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __lhs,
01042               const sub_match<_Bi_iter>& __rhs)
01043     {
01044       typedef typename sub_match<_Bi_iter>::string_type string_type;
01045       return __rhs.compare(string_type(__lhs.data(), __lhs.size())) > 0;
01046     }
01047 
01048   /**
01049    * @brief Tests the ordering of a string and a regular expression submatch.
01050    * @param __lhs A string.
01051    * @param __rhs A regular expression submatch.
01052    * @returns true if @a __lhs succeeds @a __rhs, false otherwise.
01053    */
01054   template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
01055     inline bool
01056     operator>(const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __lhs,
01057               const sub_match<_Bi_iter>& __rhs)
01058     { return __rhs < __lhs; }
01059 
01060   /**
01061    * @brief Tests the ordering of a string and a regular expression submatch.
01062    * @param __lhs A string.
01063    * @param __rhs A regular expression submatch.
01064    * @returns true if @a __lhs does not precede @a __rhs, false otherwise.
01065    */
01066   template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
01067     inline bool
01068     operator>=(const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __lhs,
01069                const sub_match<_Bi_iter>& __rhs)
01070     { return !(__lhs < __rhs); }
01071 
01072   /**
01073    * @brief Tests the ordering of a string and a regular expression submatch.
01074    * @param __lhs A string.
01075    * @param __rhs A regular expression submatch.
01076    * @returns true if @a __lhs does not succeed @a __rhs, false otherwise.
01077    */
01078   template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
01079     inline bool
01080     operator<=(const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __lhs,
01081                const sub_match<_Bi_iter>& __rhs)
01082     { return !(__rhs < __lhs); }
01083 
01084   /**
01085    * @brief Tests the equivalence of a regular expression submatch and a
01086    *        string.
01087    * @param __lhs A regular expression submatch.
01088    * @param __rhs A string.
01089    * @returns true if @a __lhs is equivalent to @a __rhs, false otherwise.
01090    */
01091   template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
01092     inline bool
01093     operator==(const sub_match<_Bi_iter>& __lhs,
01094                const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __rhs)
01095     {
01096       typedef typename sub_match<_Bi_iter>::string_type string_type;
01097       return __lhs.compare(string_type(__rhs.data(), __rhs.size())) == 0;
01098     }
01099 
01100   /**
01101    * @brief Tests the inequivalence of a regular expression submatch and a
01102    *        string.
01103    * @param __lhs A regular expression submatch.
01104    * @param __rhs A string.
01105    * @returns true if @a __lhs is not equivalent to @a __rhs, false otherwise.
01106    */
01107   template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
01108     inline bool
01109     operator!=(const sub_match<_Bi_iter>& __lhs,
01110                const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __rhs)
01111     { return !(__lhs == __rhs); }
01112 
01113   /**
01114    * @brief Tests the ordering of a regular expression submatch and a string.
01115    * @param __lhs A regular expression submatch.
01116    * @param __rhs A string.
01117    * @returns true if @a __lhs precedes @a __rhs, false otherwise.
01118    */
01119   template<typename _Bi_iter, class _Ch_traits, class _Ch_alloc>
01120     inline bool
01121     operator<(const sub_match<_Bi_iter>& __lhs,
01122               const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __rhs)
01123     {
01124       typedef typename sub_match<_Bi_iter>::string_type string_type;
01125       return __lhs.compare(string_type(__rhs.data(), __rhs.size())) < 0;
01126     }
01127 
01128   /**
01129    * @brief Tests the ordering of a regular expression submatch and a string.
01130    * @param __lhs A regular expression submatch.
01131    * @param __rhs A string.
01132    * @returns true if @a __lhs succeeds @a __rhs, false otherwise.
01133    */
01134   template<typename _Bi_iter, class _Ch_traits, class _Ch_alloc>
01135     inline bool
01136     operator>(const sub_match<_Bi_iter>& __lhs,
01137               const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __rhs)
01138     { return __rhs < __lhs; }
01139 
01140   /**
01141    * @brief Tests the ordering of a regular expression submatch and a string.
01142    * @param __lhs A regular expression submatch.
01143    * @param __rhs A string.
01144    * @returns true if @a __lhs does not precede @a __rhs, false otherwise.
01145    */
01146   template<typename _Bi_iter, class _Ch_traits, class _Ch_alloc>
01147     inline bool
01148     operator>=(const sub_match<_Bi_iter>& __lhs,
01149                const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __rhs)
01150     { return !(__lhs < __rhs); }
01151 
01152   /**
01153    * @brief Tests the ordering of a regular expression submatch and a string.
01154    * @param __lhs A regular expression submatch.
01155    * @param __rhs A string.
01156    * @returns true if @a __lhs does not succeed @a __rhs, false otherwise.
01157    */
01158   template<typename _Bi_iter, class _Ch_traits, class _Ch_alloc>
01159     inline bool
01160     operator<=(const sub_match<_Bi_iter>& __lhs,
01161                const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __rhs)
01162     { return !(__rhs < __lhs); }
01163 
01164   /**
01165    * @brief Tests the equivalence of a C string and a regular expression
01166    *        submatch.
01167    * @param __lhs A C string.
01168    * @param __rhs A regular expression submatch.
01169    * @returns true if @a __lhs  is equivalent to @a __rhs, false otherwise.
01170    */
01171   template<typename _Bi_iter>
01172     inline bool
01173     operator==(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
01174                const sub_match<_Bi_iter>& __rhs)
01175     { return __rhs.compare(__lhs) == 0; }
01176 
01177   /**
01178    * @brief Tests the inequivalence of an iterator value and a regular
01179    *        expression submatch.
01180    * @param __lhs A regular expression submatch.
01181    * @param __rhs A string.
01182    * @returns true if @a __lhs is not equivalent to @a __rhs, false otherwise.
01183    */
01184   template<typename _Bi_iter>
01185     inline bool
01186     operator!=(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
01187                const sub_match<_Bi_iter>& __rhs)
01188     { return !(__lhs == __rhs); }
01189 
01190   /**
01191    * @brief Tests the ordering of a string and a regular expression submatch.
01192    * @param __lhs A string.
01193    * @param __rhs A regular expression submatch.
01194    * @returns true if @a __lhs precedes @a __rhs, false otherwise.
01195    */
01196   template<typename _Bi_iter>
01197     inline bool
01198     operator<(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
01199               const sub_match<_Bi_iter>& __rhs)
01200     { return __rhs.compare(__lhs) > 0; }
01201 
01202   /**
01203    * @brief Tests the ordering of a string and a regular expression submatch.
01204    * @param __lhs A string.
01205    * @param __rhs A regular expression submatch.
01206    * @returns true if @a __lhs succeeds @a __rhs, false otherwise.
01207    */
01208   template<typename _Bi_iter>
01209     inline bool
01210     operator>(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
01211               const sub_match<_Bi_iter>& __rhs)
01212     { return __rhs < __lhs; }
01213 
01214   /**
01215    * @brief Tests the ordering of a string and a regular expression submatch.
01216    * @param __lhs A string.
01217    * @param __rhs A regular expression submatch.
01218    * @returns true if @a __lhs does not precede @a __rhs, false otherwise.
01219    */
01220   template<typename _Bi_iter>
01221     inline bool
01222     operator>=(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
01223                const sub_match<_Bi_iter>& __rhs)
01224     { return !(__lhs < __rhs); }
01225 
01226   /**
01227    * @brief Tests the ordering of a string and a regular expression submatch.
01228    * @param __lhs A string.
01229    * @param __rhs A regular expression submatch.
01230    * @returns true if @a __lhs does not succeed @a __rhs, false otherwise.
01231    */
01232   template<typename _Bi_iter>
01233     inline bool
01234     operator<=(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
01235                const sub_match<_Bi_iter>& __rhs)
01236     { return !(__rhs < __lhs); }
01237 
01238   /**
01239    * @brief Tests the equivalence of a regular expression submatch and a
01240    *        string.
01241    * @param __lhs A regular expression submatch.
01242    * @param __rhs A pointer to a string?
01243    * @returns true if @a __lhs  is equivalent to @a __rhs, false otherwise.
01244    */
01245   template<typename _Bi_iter>
01246     inline bool
01247     operator==(const sub_match<_Bi_iter>& __lhs,
01248                typename iterator_traits<_Bi_iter>::value_type const* __rhs)
01249     { return __lhs.compare(__rhs) == 0; }
01250 
01251   /**
01252    * @brief Tests the inequivalence of a regular expression submatch and a
01253    *        string.
01254    * @param __lhs A regular expression submatch.
01255    * @param __rhs A pointer to a string.
01256    * @returns true if @a __lhs is not equivalent to @a __rhs, false otherwise.
01257    */
01258   template<typename _Bi_iter>
01259     inline bool
01260     operator!=(const sub_match<_Bi_iter>& __lhs,
01261                typename iterator_traits<_Bi_iter>::value_type const* __rhs)
01262     { return !(__lhs == __rhs); }
01263 
01264   /**
01265    * @brief Tests the ordering of a regular expression submatch and a string.
01266    * @param __lhs A regular expression submatch.
01267    * @param __rhs A string.
01268    * @returns true if @a __lhs precedes @a __rhs, false otherwise.
01269    */
01270   template<typename _Bi_iter>
01271     inline bool
01272     operator<(const sub_match<_Bi_iter>& __lhs,
01273               typename iterator_traits<_Bi_iter>::value_type const* __rhs)
01274     { return __lhs.compare(__rhs) < 0; }
01275 
01276   /**
01277    * @brief Tests the ordering of a regular expression submatch and a string.
01278    * @param __lhs A regular expression submatch.
01279    * @param __rhs A string.
01280    * @returns true if @a __lhs succeeds @a __rhs, false otherwise.
01281    */
01282   template<typename _Bi_iter>
01283     inline bool
01284     operator>(const sub_match<_Bi_iter>& __lhs,
01285               typename iterator_traits<_Bi_iter>::value_type const* __rhs)
01286     { return __rhs < __lhs; }
01287 
01288   /**
01289    * @brief Tests the ordering of a regular expression submatch and a string.
01290    * @param __lhs A regular expression submatch.
01291    * @param __rhs A string.
01292    * @returns true if @a __lhs does not precede @a __rhs, false otherwise.
01293    */
01294   template<typename _Bi_iter>
01295     inline bool
01296     operator>=(const sub_match<_Bi_iter>& __lhs,
01297                typename iterator_traits<_Bi_iter>::value_type const* __rhs)
01298     { return !(__lhs < __rhs); }
01299 
01300   /**
01301    * @brief Tests the ordering of a regular expression submatch and a string.
01302    * @param __lhs A regular expression submatch.
01303    * @param __rhs A string.
01304    * @returns true if @a __lhs does not succeed @a __rhs, false otherwise.
01305    */
01306   template<typename _Bi_iter>
01307     inline bool
01308     operator<=(const sub_match<_Bi_iter>& __lhs,
01309                typename iterator_traits<_Bi_iter>::value_type const* __rhs)
01310     { return !(__rhs < __lhs); }
01311 
01312   /**
01313    * @brief Tests the equivalence of a string and a regular expression
01314    *        submatch.
01315    * @param __lhs A string.
01316    * @param __rhs A regular expression submatch.
01317    * @returns true if @a __lhs is equivalent to @a __rhs, false otherwise.
01318    */
01319   template<typename _Bi_iter>
01320     inline bool
01321     operator==(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
01322                const sub_match<_Bi_iter>& __rhs)
01323     {
01324       typedef typename sub_match<_Bi_iter>::string_type string_type;
01325       return __rhs.compare(string_type(1, __lhs)) == 0;
01326     }
01327 
01328   /**
01329    * @brief Tests the inequivalence of a string and a regular expression
01330    *        submatch.
01331    * @param __lhs A string.
01332    * @param __rhs A regular expression submatch.
01333    * @returns true if @a __lhs is not equivalent to @a __rhs, false otherwise.
01334    */
01335   template<typename _Bi_iter>
01336     inline bool
01337     operator!=(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
01338                const sub_match<_Bi_iter>& __rhs)
01339     { return !(__lhs == __rhs); }
01340 
01341   /**
01342    * @brief Tests the ordering of a string and a regular expression submatch.
01343    * @param __lhs A string.
01344    * @param __rhs A regular expression submatch.
01345    * @returns true if @a __lhs precedes @a __rhs, false otherwise.
01346    */
01347   template<typename _Bi_iter>
01348     inline bool
01349     operator<(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
01350               const sub_match<_Bi_iter>& __rhs)
01351     {
01352       typedef typename sub_match<_Bi_iter>::string_type string_type;
01353       return __rhs.compare(string_type(1, __lhs)) > 0;
01354     }
01355 
01356   /**
01357    * @brief Tests the ordering of a string and a regular expression submatch.
01358    * @param __lhs A string.
01359    * @param __rhs A regular expression submatch.
01360    * @returns true if @a __lhs succeeds @a __rhs, false otherwise.
01361    */
01362   template<typename _Bi_iter>
01363     inline bool
01364     operator>(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
01365               const sub_match<_Bi_iter>& __rhs)
01366     { return __rhs < __lhs; }
01367 
01368   /**
01369    * @brief Tests the ordering of a string and a regular expression submatch.
01370    * @param __lhs A string.
01371    * @param __rhs A regular expression submatch.
01372    * @returns true if @a __lhs does not precede @a __rhs, false otherwise.
01373    */
01374   template<typename _Bi_iter>
01375     inline bool
01376     operator>=(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
01377                const sub_match<_Bi_iter>& __rhs)
01378     { return !(__lhs < __rhs); }
01379 
01380   /**
01381    * @brief Tests the ordering of a string and a regular expression submatch.
01382    * @param __lhs A string.
01383    * @param __rhs A regular expression submatch.
01384    * @returns true if @a __lhs does not succeed @a __rhs, false otherwise.
01385    */
01386   template<typename _Bi_iter>
01387     inline bool
01388     operator<=(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
01389                const sub_match<_Bi_iter>& __rhs)
01390     { return !(__rhs < __lhs); }
01391 
01392   /**
01393    * @brief Tests the equivalence of a regular expression submatch and a
01394    *        string.
01395    * @param __lhs A regular expression submatch.
01396    * @param __rhs A const string reference.
01397    * @returns true if @a __lhs  is equivalent to @a __rhs, false otherwise.
01398    */
01399   template<typename _Bi_iter>
01400     inline bool
01401     operator==(const sub_match<_Bi_iter>& __lhs,
01402                typename iterator_traits<_Bi_iter>::value_type const& __rhs)
01403     {
01404       typedef typename sub_match<_Bi_iter>::string_type string_type;
01405       return __lhs.compare(string_type(1, __rhs)) == 0;
01406     }
01407 
01408   /**
01409    * @brief Tests the inequivalence of a regular expression submatch and a
01410    *        string.
01411    * @param __lhs A regular expression submatch.
01412    * @param __rhs A const string reference.
01413    * @returns true if @a __lhs is not equivalent to @a __rhs, false otherwise.
01414    */
01415   template<typename _Bi_iter>
01416     inline bool
01417     operator!=(const sub_match<_Bi_iter>& __lhs,
01418                typename iterator_traits<_Bi_iter>::value_type const& __rhs)
01419     { return !(__lhs == __rhs); }
01420 
01421   /**
01422    * @brief Tests the ordering of a regular expression submatch and a string.
01423    * @param __lhs A regular expression submatch.
01424    * @param __rhs A const string reference.
01425    * @returns true if @a __lhs precedes @a __rhs, false otherwise.
01426    */
01427   template<typename _Bi_iter>
01428     inline bool
01429     operator<(const sub_match<_Bi_iter>& __lhs,
01430               typename iterator_traits<_Bi_iter>::value_type const& __rhs)
01431     {
01432       typedef typename sub_match<_Bi_iter>::string_type string_type;
01433       return __lhs.compare(string_type(1, __rhs)) < 0;
01434     }
01435 
01436   /**
01437    * @brief Tests the ordering of a regular expression submatch and a string.
01438    * @param __lhs A regular expression submatch.
01439    * @param __rhs A const string reference.
01440    * @returns true if @a __lhs succeeds @a __rhs, false otherwise.
01441    */
01442   template<typename _Bi_iter>
01443     inline bool
01444     operator>(const sub_match<_Bi_iter>& __lhs,
01445               typename iterator_traits<_Bi_iter>::value_type const& __rhs)
01446     { return __rhs < __lhs; }
01447 
01448   /**
01449    * @brief Tests the ordering of a regular expression submatch and a string.
01450    * @param __lhs A regular expression submatch.
01451    * @param __rhs A const string reference.
01452    * @returns true if @a __lhs does not precede @a __rhs, false otherwise.
01453    */
01454   template<typename _Bi_iter>
01455     inline bool
01456     operator>=(const sub_match<_Bi_iter>& __lhs,
01457                typename iterator_traits<_Bi_iter>::value_type const& __rhs)
01458     { return !(__lhs < __rhs); }
01459 
01460   /**
01461    * @brief Tests the ordering of a regular expression submatch and a string.
01462    * @param __lhs A regular expression submatch.
01463    * @param __rhs A const string reference.
01464    * @returns true if @a __lhs does not succeed @a __rhs, false otherwise.
01465    */
01466   template<typename _Bi_iter>
01467     inline bool
01468     operator<=(const sub_match<_Bi_iter>& __lhs,
01469                typename iterator_traits<_Bi_iter>::value_type const& __rhs)
01470     { return !(__rhs < __lhs); }
01471 
01472   /**
01473    * @brief Inserts a matched string into an output stream.
01474    *
01475    * @param __os The output stream.
01476    * @param __m  A submatch string.
01477    *
01478    * @returns the output stream with the submatch string inserted.
01479    */
01480   template<typename _Ch_type, typename _Ch_traits, typename _Bi_iter>
01481     inline
01482     basic_ostream<_Ch_type, _Ch_traits>&
01483     operator<<(basic_ostream<_Ch_type, _Ch_traits>& __os,
01484                const sub_match<_Bi_iter>& __m)
01485     { return __os << __m.str(); }
01486 
01487   // [7.10] Class template match_results
01488 
01489   /**
01490    * @brief The results of a match or search operation.
01491    *
01492    * A collection of character sequences representing the result of a regular
01493    * expression match.  Storage for the collection is allocated and freed as
01494    * necessary by the member functions of class template match_results.
01495    *
01496    * This class satisfies the Sequence requirements, with the exception that
01497    * only the operations defined for a const-qualified Sequence are supported.
01498    *
01499    * The sub_match object stored at index 0 represents sub-expression 0, i.e.
01500    * the whole match. In this case the %sub_match member matched is always true.
01501    * The sub_match object stored at index n denotes what matched the marked
01502    * sub-expression n within the matched expression. If the sub-expression n
01503    * participated in a regular expression match then the %sub_match member
01504    * matched evaluates to true, and members first and second denote the range
01505    * of characters [first, second) which formed that match. Otherwise matched
01506    * is false, and members first and second point to the end of the sequence
01507    * that was searched.
01508    *
01509    * @nosubgrouping
01510    */
01511   template<typename _Bi_iter,
01512            typename _Alloc = allocator<sub_match<_Bi_iter> > >
01513     class match_results
01514     : private std::vector<sub_match<_Bi_iter>, _Alloc>
01515     {
01516     private:
01517       /*
01518        * The vector base is empty if this does not represent a match (!ready());
01519        * Otherwise if it's a match failure, it contains 3 elements:
01520        * [0] unmatched
01521        * [1] prefix
01522        * [2] suffix
01523        * Otherwise it contains n+4 elements where n is the number of marked
01524        * sub-expressions:
01525        * [0] entire match
01526        * [1] 1st marked subexpression
01527        * ...
01528        * [n] nth marked subexpression
01529        * [n+1] unmatched
01530        * [n+2] prefix
01531        * [n+3] suffix
01532        */
01533       typedef std::vector<sub_match<_Bi_iter>, _Alloc>     _Base_type;
01534       typedef std::iterator_traits<_Bi_iter>               __iter_traits;
01535       typedef regex_constants::match_flag_type             match_flag_type;
01536 
01537     public:
01538       /**
01539        * @name 10.? Public Types
01540        */
01541       //@{
01542       typedef sub_match<_Bi_iter>                          value_type;
01543       typedef const value_type&                            const_reference;
01544       typedef const_reference                              reference;
01545       typedef typename _Base_type::const_iterator          const_iterator;
01546       typedef const_iterator                               iterator;
01547       typedef typename __iter_traits::difference_type      difference_type;
01548       typedef typename allocator_traits<_Alloc>::size_type size_type;
01549       typedef _Alloc                                       allocator_type;
01550       typedef typename __iter_traits::value_type           char_type;
01551       typedef std::basic_string<char_type>                 string_type;
01552       //@}
01553 
01554     public:
01555       /**
01556        * @name 28.10.1 Construction, Copying, and Destruction
01557        */
01558       //@{
01559 
01560       /**
01561        * @brief Constructs a default %match_results container.
01562        * @post size() returns 0 and str() returns an empty string.
01563        */
01564       explicit
01565       match_results(const _Alloc& __a = _Alloc())
01566       : _Base_type(__a)
01567       { }
01568 
01569       /**
01570        * @brief Copy constructs a %match_results.
01571        */
01572       match_results(const match_results& __rhs) = default;
01573 
01574       /**
01575        * @brief Move constructs a %match_results.
01576        */
01577       match_results(match_results&& __rhs) noexcept = default;
01578 
01579       /**
01580        * @brief Assigns rhs to *this.
01581        */
01582       match_results&
01583       operator=(const match_results& __rhs) = default;
01584 
01585       /**
01586        * @brief Move-assigns rhs to *this.
01587        */
01588       match_results&
01589       operator=(match_results&& __rhs) = default;
01590 
01591       /**
01592        * @brief Destroys a %match_results object.
01593        */
01594       ~match_results()
01595       { }
01596 
01597       //@}
01598 
01599       // 28.10.2, state:
01600       /**
01601        * @brief Indicates if the %match_results is ready.
01602        * @retval true   The object has a fully-established result state.
01603        * @retval false  The object is not ready.
01604        */
01605       bool ready() const { return !_Base_type::empty(); }
01606 
01607       /**
01608        * @name 28.10.2 Size
01609        */
01610       //@{
01611 
01612       /**
01613        * @brief Gets the number of matches and submatches.
01614        *
01615        * The number of matches for a given regular expression will be either 0
01616        * if there was no match or mark_count() + 1 if a match was successful.
01617        * Some matches may be empty.
01618        *
01619        * @returns the number of matches found.
01620        */
01621       size_type
01622       size() const
01623       { return _Base_type::empty() ? 0 : _Base_type::size() - 3; }
01624 
01625       size_type
01626       max_size() const
01627       { return _Base_type::max_size(); }
01628 
01629       /**
01630        * @brief Indicates if the %match_results contains no results.
01631        * @retval true The %match_results object is empty.
01632        * @retval false The %match_results object is not empty.
01633        */
01634       bool
01635       empty() const
01636       { return size() == 0; }
01637 
01638       //@}
01639 
01640       /**
01641        * @name 10.3 Element Access
01642        */
01643       //@{
01644 
01645       /**
01646        * @brief Gets the length of the indicated submatch.
01647        * @param __sub indicates the submatch.
01648        * @pre   ready() == true
01649        *
01650        * This function returns the length of the indicated submatch, or the
01651        * length of the entire match if @p __sub is zero (the default).
01652        */
01653       difference_type
01654       length(size_type __sub = 0) const
01655       { return (*this)[__sub].length(); }
01656 
01657       /**
01658        * @brief Gets the offset of the beginning of the indicated submatch.
01659        * @param __sub indicates the submatch.
01660        * @pre   ready() == true
01661        *
01662        * This function returns the offset from the beginning of the target
01663        * sequence to the beginning of the submatch, unless the value of @p __sub
01664        * is zero (the default), in which case this function returns the offset
01665        * from the beginning of the target sequence to the beginning of the
01666        * match.
01667        */
01668       difference_type
01669       position(size_type __sub = 0) const
01670       { return std::distance(_M_begin, (*this)[__sub].first); }
01671 
01672       /**
01673        * @brief Gets the match or submatch converted to a string type.
01674        * @param __sub indicates the submatch.
01675        * @pre   ready() == true
01676        *
01677        * This function gets the submatch (or match, if @p __sub is
01678        * zero) extracted from the target range and converted to the
01679        * associated string type.
01680        */
01681       string_type
01682       str(size_type __sub = 0) const
01683       { return string_type((*this)[__sub]); }
01684 
01685       /**
01686        * @brief Gets a %sub_match reference for the match or submatch.
01687        * @param __sub indicates the submatch.
01688        * @pre   ready() == true
01689        *
01690        * This function gets a reference to the indicated submatch, or
01691        * the entire match if @p __sub is zero.
01692        *
01693        * If @p __sub >= size() then this function returns a %sub_match with a
01694        * special value indicating no submatch.
01695        */
01696       const_reference
01697       operator[](size_type __sub) const
01698       {
01699         __glibcxx_assert( ready() );
01700         return __sub < size()
01701                ? _Base_type::operator[](__sub)
01702                : _M_unmatched_sub();
01703       }
01704 
01705       /**
01706        * @brief Gets a %sub_match representing the match prefix.
01707        * @pre   ready() == true
01708        *
01709        * This function gets a reference to a %sub_match object representing the
01710        * part of the target range between the start of the target range and the
01711        * start of the match.
01712        */
01713       const_reference
01714       prefix() const
01715       {
01716         __glibcxx_assert( ready() );
01717         return !empty() ? _M_prefix() : _M_unmatched_sub();
01718       }
01719 
01720       /**
01721        * @brief Gets a %sub_match representing the match suffix.
01722        * @pre   ready() == true
01723        *
01724        * This function gets a reference to a %sub_match object representing the
01725        * part of the target range between the end of the match and the end of
01726        * the target range.
01727        */
01728       const_reference
01729       suffix() const
01730       {
01731         __glibcxx_assert( ready() );
01732         return !empty() ? _M_suffix() : _M_unmatched_sub();
01733       }
01734 
01735       /**
01736        * @brief Gets an iterator to the start of the %sub_match collection.
01737        */
01738       const_iterator
01739       begin() const
01740       { return _Base_type::begin(); }
01741 
01742       /**
01743        * @brief Gets an iterator to the start of the %sub_match collection.
01744        */
01745       const_iterator
01746       cbegin() const
01747       { return this->begin(); }
01748 
01749       /**
01750        * @brief Gets an iterator to one-past-the-end of the collection.
01751        */
01752       const_iterator
01753       end() const
01754       { return _Base_type::end() - (empty() ? 0 : 3); }
01755 
01756       /**
01757        * @brief Gets an iterator to one-past-the-end of the collection.
01758        */
01759       const_iterator
01760       cend() const
01761       { return this->end(); }
01762 
01763       //@}
01764 
01765       /**
01766        * @name 10.4 Formatting
01767        *
01768        * These functions perform formatted substitution of the matched
01769        * character sequences into their target.  The format specifiers and
01770        * escape sequences accepted by these functions are determined by
01771        * their @p flags parameter as documented above.
01772        */
01773        //@{
01774 
01775       /**
01776        * @pre   ready() == true
01777        */
01778       template<typename _Out_iter>
01779         _Out_iter
01780         format(_Out_iter __out, const char_type* __fmt_first,
01781                const char_type* __fmt_last,
01782                match_flag_type __flags = regex_constants::format_default) const;
01783 
01784       /**
01785        * @pre   ready() == true
01786        */
01787       template<typename _Out_iter, typename _St, typename _Sa>
01788         _Out_iter
01789         format(_Out_iter __out, const basic_string<char_type, _St, _Sa>& __fmt,
01790                match_flag_type __flags = regex_constants::format_default) const
01791         {
01792           return format(__out, __fmt.data(), __fmt.data() + __fmt.size(),
01793                         __flags);
01794         }
01795 
01796       /**
01797        * @pre   ready() == true
01798        */
01799       template<typename _St, typename _Sa>
01800         basic_string<char_type, _St, _Sa>
01801         format(const basic_string<char_type, _St, _Sa>& __fmt,
01802                match_flag_type __flags = regex_constants::format_default) const
01803         {
01804           basic_string<char_type, _St, _Sa> __result;
01805           format(std::back_inserter(__result), __fmt, __flags);
01806           return __result;
01807         }
01808 
01809       /**
01810        * @pre   ready() == true
01811        */
01812       string_type
01813       format(const char_type* __fmt,
01814              match_flag_type __flags = regex_constants::format_default) const
01815       {
01816         string_type __result;
01817         format(std::back_inserter(__result),
01818                __fmt,
01819                __fmt + char_traits<char_type>::length(__fmt),
01820                __flags);
01821         return __result;
01822       }
01823 
01824       //@}
01825 
01826       /**
01827        * @name 10.5 Allocator
01828        */
01829       //@{
01830 
01831       /**
01832        * @brief Gets a copy of the allocator.
01833        */
01834       allocator_type
01835       get_allocator() const
01836       { return _Base_type::get_allocator(); }
01837 
01838       //@}
01839 
01840       /**
01841        * @name 10.6 Swap
01842        */
01843        //@{
01844 
01845       /**
01846        * @brief Swaps the contents of two match_results.
01847        */
01848       void
01849       swap(match_results& __that)
01850       {
01851         using std::swap;
01852         _Base_type::swap(__that);
01853         swap(_M_begin, __that._M_begin);
01854       }
01855       //@}
01856 
01857     private:
01858       template<typename, typename, typename, bool>
01859         friend class __detail::_Executor;
01860 
01861       template<typename, typename, typename>
01862         friend class regex_iterator;
01863 
01864       template<typename _Bp, typename _Ap, typename _Cp, typename _Rp,
01865         __detail::_RegexExecutorPolicy, bool>
01866         friend bool __detail::
01867 #if _GLIBCXX_INLINE_VERSION
01868         __7:: // Required due to PR c++/59256
01869 #endif
01870         __regex_algo_impl(_Bp, _Bp, match_results<_Bp, _Ap>&,
01871                           const basic_regex<_Cp, _Rp>&,
01872                           regex_constants::match_flag_type);
01873 
01874       void
01875       _M_resize(unsigned int __size)
01876       { _Base_type::resize(__size + 3); }
01877 
01878       const_reference
01879       _M_unmatched_sub() const
01880       { return _Base_type::operator[](_Base_type::size() - 3); }
01881 
01882       sub_match<_Bi_iter>&
01883       _M_unmatched_sub()
01884       { return _Base_type::operator[](_Base_type::size() - 3); }
01885 
01886       const_reference
01887       _M_prefix() const
01888       { return _Base_type::operator[](_Base_type::size() - 2); }
01889 
01890       sub_match<_Bi_iter>&
01891       _M_prefix()
01892       { return _Base_type::operator[](_Base_type::size() - 2); }
01893 
01894       const_reference
01895       _M_suffix() const
01896       { return _Base_type::operator[](_Base_type::size() - 1); }
01897 
01898       sub_match<_Bi_iter>&
01899       _M_suffix()
01900       { return _Base_type::operator[](_Base_type::size() - 1); }
01901 
01902       _Bi_iter _M_begin;
01903     };
01904 
01905   typedef match_results<const char*>             cmatch;
01906   typedef match_results<string::const_iterator>  smatch;
01907 #ifdef _GLIBCXX_USE_WCHAR_T
01908   typedef match_results<const wchar_t*>          wcmatch;
01909   typedef match_results<wstring::const_iterator> wsmatch;
01910 #endif
01911 
01912   // match_results comparisons
01913   /**
01914    * @brief Compares two match_results for equality.
01915    * @returns true if the two objects refer to the same match,
01916    * false otherwise.
01917    */
01918   template<typename _Bi_iter, typename _Alloc>
01919     inline bool
01920     operator==(const match_results<_Bi_iter, _Alloc>& __m1,
01921                const match_results<_Bi_iter, _Alloc>& __m2)
01922     {
01923       if (__m1.ready() != __m2.ready())
01924         return false;
01925       if (!__m1.ready())  // both are not ready
01926         return true;
01927       if (__m1.empty() != __m2.empty())
01928         return false;
01929       if (__m1.empty())   // both are empty
01930         return true;
01931       return __m1.prefix() == __m2.prefix()
01932         && __m1.size() == __m2.size()
01933         && std::equal(__m1.begin(), __m1.end(), __m2.begin())
01934         && __m1.suffix() == __m2.suffix();
01935     }
01936 
01937   /**
01938    * @brief Compares two match_results for inequality.
01939    * @returns true if the two objects do not refer to the same match,
01940    * false otherwise.
01941    */
01942   template<typename _Bi_iter, class _Alloc>
01943     inline bool
01944     operator!=(const match_results<_Bi_iter, _Alloc>& __m1,
01945                const match_results<_Bi_iter, _Alloc>& __m2)
01946     { return !(__m1 == __m2); }
01947 
01948   // [7.10.6] match_results swap
01949   /**
01950    * @brief Swaps two match results.
01951    * @param __lhs A match result.
01952    * @param __rhs A match result.
01953    *
01954    * The contents of the two match_results objects are swapped.
01955    */
01956   template<typename _Bi_iter, typename _Alloc>
01957     inline void
01958     swap(match_results<_Bi_iter, _Alloc>& __lhs,
01959          match_results<_Bi_iter, _Alloc>& __rhs)
01960     { __lhs.swap(__rhs); }
01961 
01962 _GLIBCXX_END_NAMESPACE_CXX11
01963 
01964   // [7.11.2] Function template regex_match
01965   /**
01966    * @name Matching, Searching, and Replacing
01967    */
01968   //@{
01969 
01970   /**
01971    * @brief Determines if there is a match between the regular expression @p e
01972    * and all of the character sequence [first, last).
01973    *
01974    * @param __s     Start of the character sequence to match.
01975    * @param __e     One-past-the-end of the character sequence to match.
01976    * @param __m     The match results.
01977    * @param __re    The regular expression.
01978    * @param __flags Controls how the regular expression is matched.
01979    *
01980    * @retval true  A match exists.
01981    * @retval false Otherwise.
01982    *
01983    * @throws an exception of type regex_error.
01984    */
01985   template<typename _Bi_iter, typename _Alloc,
01986            typename _Ch_type, typename _Rx_traits>
01987     inline bool
01988     regex_match(_Bi_iter                                 __s,
01989                 _Bi_iter                                 __e,
01990                 match_results<_Bi_iter, _Alloc>&         __m,
01991                 const basic_regex<_Ch_type, _Rx_traits>& __re,
01992                 regex_constants::match_flag_type         __flags
01993                                = regex_constants::match_default)
01994     {
01995       return __detail::__regex_algo_impl<_Bi_iter, _Alloc, _Ch_type, _Rx_traits,
01996         __detail::_RegexExecutorPolicy::_S_auto, true>
01997           (__s, __e, __m, __re, __flags);
01998     }
01999 
02000   /**
02001    * @brief Indicates if there is a match between the regular expression @p e
02002    * and all of the character sequence [first, last).
02003    *
02004    * @param __first Beginning of the character sequence to match.
02005    * @param __last  One-past-the-end of the character sequence to match.
02006    * @param __re    The regular expression.
02007    * @param __flags Controls how the regular expression is matched.
02008    *
02009    * @retval true  A match exists.
02010    * @retval false Otherwise.
02011    *
02012    * @throws an exception of type regex_error.
02013    */
02014   template<typename _Bi_iter, typename _Ch_type, typename _Rx_traits>
02015     inline bool
02016     regex_match(_Bi_iter __first, _Bi_iter __last,
02017                 const basic_regex<_Ch_type, _Rx_traits>& __re,
02018                 regex_constants::match_flag_type __flags
02019                 = regex_constants::match_default)
02020     {
02021       match_results<_Bi_iter> __what;
02022       return regex_match(__first, __last, __what, __re, __flags);
02023     }
02024 
02025   /**
02026    * @brief Determines if there is a match between the regular expression @p e
02027    * and a C-style null-terminated string.
02028    *
02029    * @param __s  The C-style null-terminated string to match.
02030    * @param __m  The match results.
02031    * @param __re The regular expression.
02032    * @param __f  Controls how the regular expression is matched.
02033    *
02034    * @retval true  A match exists.
02035    * @retval false Otherwise.
02036    *
02037    * @throws an exception of type regex_error.
02038    */
02039   template<typename _Ch_type, typename _Alloc, typename _Rx_traits>
02040     inline bool
02041     regex_match(const _Ch_type* __s,
02042                 match_results<const _Ch_type*, _Alloc>& __m,
02043                 const basic_regex<_Ch_type, _Rx_traits>& __re,
02044                 regex_constants::match_flag_type __f
02045                 = regex_constants::match_default)
02046     { return regex_match(__s, __s + _Rx_traits::length(__s), __m, __re, __f); }
02047 
02048   /**
02049    * @brief Determines if there is a match between the regular expression @p e
02050    * and a string.
02051    *
02052    * @param __s     The string to match.
02053    * @param __m     The match results.
02054    * @param __re    The regular expression.
02055    * @param __flags Controls how the regular expression is matched.
02056    *
02057    * @retval true  A match exists.
02058    * @retval false Otherwise.
02059    *
02060    * @throws an exception of type regex_error.
02061    */
02062   template<typename _Ch_traits, typename _Ch_alloc,
02063            typename _Alloc, typename _Ch_type, typename _Rx_traits>
02064     inline bool
02065     regex_match(const basic_string<_Ch_type, _Ch_traits, _Ch_alloc>& __s,
02066                 match_results<typename basic_string<_Ch_type,
02067                 _Ch_traits, _Ch_alloc>::const_iterator, _Alloc>& __m,
02068                 const basic_regex<_Ch_type, _Rx_traits>& __re,
02069                 regex_constants::match_flag_type __flags
02070                 = regex_constants::match_default)
02071     { return regex_match(__s.begin(), __s.end(), __m, __re, __flags); }
02072 
02073   // _GLIBCXX_RESOLVE_LIB_DEFECTS
02074   // 2329. regex_match() with match_results should forbid temporary strings
02075   /// Prevent unsafe attempts to get match_results from a temporary string.
02076   template<typename _Ch_traits, typename _Ch_alloc,
02077            typename _Alloc, typename _Ch_type, typename _Rx_traits>
02078     bool
02079     regex_match(const basic_string<_Ch_type, _Ch_traits, _Ch_alloc>&&,
02080                 match_results<typename basic_string<_Ch_type,
02081                 _Ch_traits, _Ch_alloc>::const_iterator, _Alloc>&,
02082                 const basic_regex<_Ch_type, _Rx_traits>&,
02083                 regex_constants::match_flag_type
02084                 = regex_constants::match_default) = delete;
02085 
02086   /**
02087    * @brief Indicates if there is a match between the regular expression @p e
02088    * and a C-style null-terminated string.
02089    *
02090    * @param __s  The C-style null-terminated string to match.
02091    * @param __re The regular expression.
02092    * @param __f  Controls how the regular expression is matched.
02093    *
02094    * @retval true  A match exists.
02095    * @retval false Otherwise.
02096    *
02097    * @throws an exception of type regex_error.
02098    */
02099   template<typename _Ch_type, class _Rx_traits>
02100     inline bool
02101     regex_match(const _Ch_type* __s,
02102                 const basic_regex<_Ch_type, _Rx_traits>& __re,
02103                 regex_constants::match_flag_type __f
02104                 = regex_constants::match_default)
02105     { return regex_match(__s, __s + _Rx_traits::length(__s), __re, __f); }
02106 
02107   /**
02108    * @brief Indicates if there is a match between the regular expression @p e
02109    * and a string.
02110    *
02111    * @param __s     [IN] The string to match.
02112    * @param __re    [IN] The regular expression.
02113    * @param __flags [IN] Controls how the regular expression is matched.
02114    *
02115    * @retval true  A match exists.
02116    * @retval false Otherwise.
02117    *
02118    * @throws an exception of type regex_error.
02119    */
02120   template<typename _Ch_traits, typename _Str_allocator,
02121            typename _Ch_type, typename _Rx_traits>
02122     inline bool
02123     regex_match(const basic_string<_Ch_type, _Ch_traits, _Str_allocator>& __s,
02124                 const basic_regex<_Ch_type, _Rx_traits>& __re,
02125                 regex_constants::match_flag_type __flags
02126                 = regex_constants::match_default)
02127     { return regex_match(__s.begin(), __s.end(), __re, __flags); }
02128 
02129   // [7.11.3] Function template regex_search
02130   /**
02131    * Searches for a regular expression within a range.
02132    * @param __s     [IN]  The start of the string to search.
02133    * @param __e     [IN]  One-past-the-end of the string to search.
02134    * @param __m     [OUT] The match results.
02135    * @param __re    [IN]  The regular expression to search for.
02136    * @param __flags [IN]  Search policy flags.
02137    * @retval true  A match was found within the string.
02138    * @retval false No match was found within the string, the content of %m is
02139    *               undefined.
02140    *
02141    * @throws an exception of type regex_error.
02142    */
02143   template<typename _Bi_iter, typename _Alloc,
02144            typename _Ch_type, typename _Rx_traits>
02145     inline bool
02146     regex_search(_Bi_iter __s, _Bi_iter __e,
02147                  match_results<_Bi_iter, _Alloc>& __m,
02148                  const basic_regex<_Ch_type, _Rx_traits>& __re,
02149                  regex_constants::match_flag_type __flags
02150                  = regex_constants::match_default)
02151     {
02152       return __detail::__regex_algo_impl<_Bi_iter, _Alloc, _Ch_type, _Rx_traits,
02153         __detail::_RegexExecutorPolicy::_S_auto, false>
02154           (__s, __e, __m, __re, __flags);
02155     }
02156 
02157   /**
02158    * Searches for a regular expression within a range.
02159    * @param __first [IN]  The start of the string to search.
02160    * @param __last  [IN]  One-past-the-end of the string to search.
02161    * @param __re    [IN]  The regular expression to search for.
02162    * @param __flags [IN]  Search policy flags.
02163    * @retval true  A match was found within the string.
02164    * @retval false No match was found within the string.
02165    *
02166    * @throws an exception of type regex_error.
02167    */
02168   template<typename _Bi_iter, typename _Ch_type, typename _Rx_traits>
02169     inline bool
02170     regex_search(_Bi_iter __first, _Bi_iter __last,
02171                  const basic_regex<_Ch_type, _Rx_traits>& __re,
02172                  regex_constants::match_flag_type __flags
02173                  = regex_constants::match_default)
02174     {
02175       match_results<_Bi_iter> __what;
02176       return regex_search(__first, __last, __what, __re, __flags);
02177     }
02178 
02179   /**
02180    * @brief Searches for a regular expression within a C-string.
02181    * @param __s [IN]  A C-string to search for the regex.
02182    * @param __m [OUT] The set of regex matches.
02183    * @param __e [IN]  The regex to search for in @p s.
02184    * @param __f [IN]  The search flags.
02185    * @retval true  A match was found within the string.
02186    * @retval false No match was found within the string, the content of %m is
02187    *               undefined.
02188    *
02189    * @throws an exception of type regex_error.
02190    */
02191   template<typename _Ch_type, class _Alloc, class _Rx_traits>
02192     inline bool
02193     regex_search(const _Ch_type* __s,
02194                  match_results<const _Ch_type*, _Alloc>& __m,
02195                  const basic_regex<_Ch_type, _Rx_traits>& __e,
02196                  regex_constants::match_flag_type __f
02197                  = regex_constants::match_default)
02198     { return regex_search(__s, __s + _Rx_traits::length(__s), __m, __e, __f); }
02199 
02200   /**
02201    * @brief Searches for a regular expression within a C-string.
02202    * @param __s [IN]  The C-string to search.
02203    * @param __e [IN]  The regular expression to search for.
02204    * @param __f [IN]  Search policy flags.
02205    * @retval true  A match was found within the string.
02206    * @retval false No match was found within the string.
02207    *
02208    * @throws an exception of type regex_error.
02209    */
02210   template<typename _Ch_type, typename _Rx_traits>
02211     inline bool
02212     regex_search(const _Ch_type* __s,
02213                  const basic_regex<_Ch_type, _Rx_traits>& __e,
02214                  regex_constants::match_flag_type __f
02215                  = regex_constants::match_default)
02216     { return regex_search(__s, __s + _Rx_traits::length(__s), __e, __f); }
02217 
02218   /**
02219    * @brief Searches for a regular expression within a string.
02220    * @param __s     [IN]  The string to search.
02221    * @param __e     [IN]  The regular expression to search for.
02222    * @param __flags [IN]  Search policy flags.
02223    * @retval true  A match was found within the string.
02224    * @retval false No match was found within the string.
02225    *
02226    * @throws an exception of type regex_error.
02227    */
02228   template<typename _Ch_traits, typename _String_allocator,
02229            typename _Ch_type, typename _Rx_traits>
02230     inline bool
02231     regex_search(const basic_string<_Ch_type, _Ch_traits,
02232                  _String_allocator>& __s,
02233                  const basic_regex<_Ch_type, _Rx_traits>& __e,
02234                  regex_constants::match_flag_type __flags
02235                  = regex_constants::match_default)
02236     { return regex_search(__s.begin(), __s.end(), __e, __flags); }
02237 
02238   /**
02239    * @brief Searches for a regular expression within a string.
02240    * @param __s [IN]  A C++ string to search for the regex.
02241    * @param __m [OUT] The set of regex matches.
02242    * @param __e [IN]  The regex to search for in @p s.
02243    * @param __f [IN]  The search flags.
02244    * @retval true  A match was found within the string.
02245    * @retval false No match was found within the string, the content of %m is
02246    *               undefined.
02247    *
02248    * @throws an exception of type regex_error.
02249    */
02250   template<typename _Ch_traits, typename _Ch_alloc,
02251            typename _Alloc, typename _Ch_type,
02252            typename _Rx_traits>
02253     inline bool
02254     regex_search(const basic_string<_Ch_type, _Ch_traits, _Ch_alloc>& __s,
02255                  match_results<typename basic_string<_Ch_type,
02256                  _Ch_traits, _Ch_alloc>::const_iterator, _Alloc>& __m,
02257                  const basic_regex<_Ch_type, _Rx_traits>& __e,
02258                  regex_constants::match_flag_type __f
02259                  = regex_constants::match_default)
02260     { return regex_search(__s.begin(), __s.end(), __m, __e, __f); }
02261 
02262   // _GLIBCXX_RESOLVE_LIB_DEFECTS
02263   // 2329. regex_search() with match_results should forbid temporary strings
02264   /// Prevent unsafe attempts to get match_results from a temporary string.
02265   template<typename _Ch_traits, typename _Ch_alloc,
02266            typename _Alloc, typename _Ch_type,
02267            typename _Rx_traits>
02268     bool
02269     regex_search(const basic_string<_Ch_type, _Ch_traits, _Ch_alloc>&&,
02270                  match_results<typename basic_string<_Ch_type,
02271                  _Ch_traits, _Ch_alloc>::const_iterator, _Alloc>&,
02272                  const basic_regex<_Ch_type, _Rx_traits>&,
02273                  regex_constants::match_flag_type
02274                  = regex_constants::match_default) = delete;
02275 
02276   // std [28.11.4] Function template regex_replace
02277   /**
02278    * @brief Search for a regular expression within a range for multiple times,
02279    and replace the matched parts through filling a format string.
02280    * @param __out   [OUT] The output iterator.
02281    * @param __first [IN]  The start of the string to search.
02282    * @param __last  [IN]  One-past-the-end of the string to search.
02283    * @param __e     [IN]  The regular expression to search for.
02284    * @param __fmt   [IN]  The format string.
02285    * @param __flags [IN]  Search and replace policy flags.
02286    *
02287    * @returns __out
02288    * @throws an exception of type regex_error.
02289    */
02290   template<typename _Out_iter, typename _Bi_iter,
02291            typename _Rx_traits, typename _Ch_type,
02292            typename _St, typename _Sa>
02293     inline _Out_iter
02294     regex_replace(_Out_iter __out, _Bi_iter __first, _Bi_iter __last,
02295                   const basic_regex<_Ch_type, _Rx_traits>& __e,
02296                   const basic_string<_Ch_type, _St, _Sa>& __fmt,
02297                   regex_constants::match_flag_type __flags
02298                   = regex_constants::match_default)
02299     {
02300       return regex_replace(__out, __first, __last, __e, __fmt.c_str(), __flags);
02301     }
02302 
02303   /**
02304    * @brief Search for a regular expression within a range for multiple times,
02305    and replace the matched parts through filling a format C-string.
02306    * @param __out   [OUT] The output iterator.
02307    * @param __first [IN]  The start of the string to search.
02308    * @param __last  [IN]  One-past-the-end of the string to search.
02309    * @param __e     [IN]  The regular expression to search for.
02310    * @param __fmt   [IN]  The format C-string.
02311    * @param __flags [IN]  Search and replace policy flags.
02312    *
02313    * @returns __out
02314    * @throws an exception of type regex_error.
02315    */
02316   template<typename _Out_iter, typename _Bi_iter,
02317            typename _Rx_traits, typename _Ch_type>
02318     _Out_iter
02319     regex_replace(_Out_iter __out, _Bi_iter __first, _Bi_iter __last,
02320                   const basic_regex<_Ch_type, _Rx_traits>& __e,
02321                   const _Ch_type* __fmt,
02322                   regex_constants::match_flag_type __flags
02323                   = regex_constants::match_default);
02324 
02325   /**
02326    * @brief Search for a regular expression within a string for multiple times,
02327    and replace the matched parts through filling a format string.
02328    * @param __s     [IN] The string to search and replace.
02329    * @param __e     [IN] The regular expression to search for.
02330    * @param __fmt   [IN] The format string.
02331    * @param __flags [IN] Search and replace policy flags.
02332    *
02333    * @returns The string after replacing.
02334    * @throws an exception of type regex_error.
02335    */
02336   template<typename _Rx_traits, typename _Ch_type,
02337            typename _St, typename _Sa, typename _Fst, typename _Fsa>
02338     inline basic_string<_Ch_type, _St, _Sa>
02339     regex_replace(const basic_string<_Ch_type, _St, _Sa>& __s,
02340                   const basic_regex<_Ch_type, _Rx_traits>& __e,
02341                   const basic_string<_Ch_type, _Fst, _Fsa>& __fmt,
02342                   regex_constants::match_flag_type __flags
02343                   = regex_constants::match_default)
02344     {
02345       basic_string<_Ch_type, _St, _Sa> __result;
02346       regex_replace(std::back_inserter(__result),
02347                     __s.begin(), __s.end(), __e, __fmt, __flags);
02348       return __result;
02349     }
02350 
02351   /**
02352    * @brief Search for a regular expression within a string for multiple times,
02353    and replace the matched parts through filling a format C-string.
02354    * @param __s     [IN] The string to search and replace.
02355    * @param __e     [IN] The regular expression to search for.
02356    * @param __fmt   [IN] The format C-string.
02357    * @param __flags [IN] Search and replace policy flags.
02358    *
02359    * @returns The string after replacing.
02360    * @throws an exception of type regex_error.
02361    */
02362   template<typename _Rx_traits, typename _Ch_type,
02363            typename _St, typename _Sa>
02364     inline basic_string<_Ch_type, _St, _Sa>
02365     regex_replace(const basic_string<_Ch_type, _St, _Sa>& __s,
02366                   const basic_regex<_Ch_type, _Rx_traits>& __e,
02367                   const _Ch_type* __fmt,
02368                   regex_constants::match_flag_type __flags
02369                   = regex_constants::match_default)
02370     {
02371       basic_string<_Ch_type, _St, _Sa> __result;
02372       regex_replace(std::back_inserter(__result),
02373                     __s.begin(), __s.end(), __e, __fmt, __flags);
02374       return __result;
02375     }
02376 
02377   /**
02378    * @brief Search for a regular expression within a C-string for multiple
02379    times, and replace the matched parts through filling a format string.
02380    * @param __s     [IN] The C-string to search and replace.
02381    * @param __e     [IN] The regular expression to search for.
02382    * @param __fmt   [IN] The format string.
02383    * @param __flags [IN] Search and replace policy flags.
02384    *
02385    * @returns The string after replacing.
02386    * @throws an exception of type regex_error.
02387    */
02388   template<typename _Rx_traits, typename _Ch_type,
02389            typename _St, typename _Sa>
02390     inline basic_string<_Ch_type>
02391     regex_replace(const _Ch_type* __s,
02392                   const basic_regex<_Ch_type, _Rx_traits>& __e,
02393                   const basic_string<_Ch_type, _St, _Sa>& __fmt,
02394                   regex_constants::match_flag_type __flags
02395                   = regex_constants::match_default)
02396     {
02397       basic_string<_Ch_type> __result;
02398       regex_replace(std::back_inserter(__result), __s,
02399                     __s + char_traits<_Ch_type>::length(__s),
02400                     __e, __fmt, __flags);
02401       return __result;
02402     }
02403 
02404   /**
02405    * @brief Search for a regular expression within a C-string for multiple
02406    times, and replace the matched parts through filling a format C-string.
02407    * @param __s     [IN] The C-string to search and replace.
02408    * @param __e     [IN] The regular expression to search for.
02409    * @param __fmt   [IN] The format C-string.
02410    * @param __flags [IN] Search and replace policy flags.
02411    *
02412    * @returns The string after replacing.
02413    * @throws an exception of type regex_error.
02414    */
02415   template<typename _Rx_traits, typename _Ch_type>
02416     inline basic_string<_Ch_type>
02417     regex_replace(const _Ch_type* __s,
02418                   const basic_regex<_Ch_type, _Rx_traits>& __e,
02419                   const _Ch_type* __fmt,
02420                   regex_constants::match_flag_type __flags
02421                   = regex_constants::match_default)
02422     {
02423       basic_string<_Ch_type> __result;
02424       regex_replace(std::back_inserter(__result), __s,
02425                     __s + char_traits<_Ch_type>::length(__s),
02426                     __e, __fmt, __flags);
02427       return __result;
02428     }
02429 
02430   //@}
02431 
02432 _GLIBCXX_BEGIN_NAMESPACE_CXX11
02433 
02434   // std [28.12] Class template regex_iterator
02435   /**
02436    * An iterator adaptor that will provide repeated calls of regex_search over
02437    * a range until no more matches remain.
02438    */
02439   template<typename _Bi_iter,
02440            typename _Ch_type = typename iterator_traits<_Bi_iter>::value_type,
02441            typename _Rx_traits = regex_traits<_Ch_type> >
02442     class regex_iterator
02443     {
02444     public:
02445       typedef basic_regex<_Ch_type, _Rx_traits>  regex_type;
02446       typedef match_results<_Bi_iter>            value_type;
02447       typedef std::ptrdiff_t                     difference_type;
02448       typedef const value_type*                  pointer;
02449       typedef const value_type&                  reference;
02450       typedef std::forward_iterator_tag          iterator_category;
02451 
02452       /**
02453        * @brief Provides a singular iterator, useful for indicating
02454        * one-past-the-end of a range.
02455        */
02456       regex_iterator()
02457       : _M_pregex()
02458       { }
02459 
02460       /**
02461        * Constructs a %regex_iterator...
02462        * @param __a  [IN] The start of a text range to search.
02463        * @param __b  [IN] One-past-the-end of the text range to search.
02464        * @param __re [IN] The regular expression to match.
02465        * @param __m  [IN] Policy flags for match rules.
02466        */
02467       regex_iterator(_Bi_iter __a, _Bi_iter __b, const regex_type& __re,
02468                      regex_constants::match_flag_type __m
02469                      = regex_constants::match_default)
02470       : _M_begin(__a), _M_end(__b), _M_pregex(&__re), _M_flags(__m), _M_match()
02471       {
02472         if (!regex_search(_M_begin, _M_end, _M_match, *_M_pregex, _M_flags))
02473           *this = regex_iterator();
02474       }
02475 
02476       // _GLIBCXX_RESOLVE_LIB_DEFECTS
02477       // 2332. regex_iterator should forbid temporary regexes
02478       regex_iterator(_Bi_iter, _Bi_iter, const regex_type&&,
02479                      regex_constants::match_flag_type
02480                      = regex_constants::match_default) = delete;
02481       /**
02482        * Copy constructs a %regex_iterator.
02483        */
02484       regex_iterator(const regex_iterator& __rhs) = default;
02485 
02486       /**
02487        * @brief Assigns one %regex_iterator to another.
02488        */
02489       regex_iterator&
02490       operator=(const regex_iterator& __rhs) = default;
02491 
02492       /**
02493        * @brief Tests the equivalence of two regex iterators.
02494        */
02495       bool
02496       operator==(const regex_iterator& __rhs) const;
02497 
02498       /**
02499        * @brief Tests the inequivalence of two regex iterators.
02500        */
02501       bool
02502       operator!=(const regex_iterator& __rhs) const
02503       { return !(*this == __rhs); }
02504 
02505       /**
02506        * @brief Dereferences a %regex_iterator.
02507        */
02508       const value_type&
02509       operator*() const
02510       { return _M_match; }
02511 
02512       /**
02513        * @brief Selects a %regex_iterator member.
02514        */
02515       const value_type*
02516       operator->() const
02517       { return &_M_match; }
02518 
02519       /**
02520        * @brief Increments a %regex_iterator.
02521        */
02522       regex_iterator&
02523       operator++();
02524 
02525       /**
02526        * @brief Postincrements a %regex_iterator.
02527        */
02528       regex_iterator
02529       operator++(int)
02530       {
02531         auto __tmp = *this;
02532         ++(*this);
02533         return __tmp;
02534       }
02535 
02536     private:
02537       _Bi_iter                         _M_begin;
02538       _Bi_iter                         _M_end;
02539       const regex_type*                _M_pregex;
02540       regex_constants::match_flag_type _M_flags;
02541       match_results<_Bi_iter>          _M_match;
02542     };
02543 
02544   typedef regex_iterator<const char*>             cregex_iterator;
02545   typedef regex_iterator<string::const_iterator>  sregex_iterator;
02546 #ifdef _GLIBCXX_USE_WCHAR_T
02547   typedef regex_iterator<const wchar_t*>          wcregex_iterator;
02548   typedef regex_iterator<wstring::const_iterator> wsregex_iterator;
02549 #endif
02550 
02551   // [7.12.2] Class template regex_token_iterator
02552   /**
02553    * Iterates over submatches in a range (or @a splits a text string).
02554    *
02555    * The purpose of this iterator is to enumerate all, or all specified,
02556    * matches of a regular expression within a text range.  The dereferenced
02557    * value of an iterator of this class is a std::sub_match object.
02558    */
02559   template<typename _Bi_iter,
02560            typename _Ch_type = typename iterator_traits<_Bi_iter>::value_type,
02561            typename _Rx_traits = regex_traits<_Ch_type> >
02562     class regex_token_iterator
02563     {
02564     public:
02565       typedef basic_regex<_Ch_type, _Rx_traits> regex_type;
02566       typedef sub_match<_Bi_iter>               value_type;
02567       typedef std::ptrdiff_t                    difference_type;
02568       typedef const value_type*                 pointer;
02569       typedef const value_type&                 reference;
02570       typedef std::forward_iterator_tag         iterator_category;
02571 
02572     public:
02573       /**
02574        * @brief Default constructs a %regex_token_iterator.
02575        *
02576        * A default-constructed %regex_token_iterator is a singular iterator
02577        * that will compare equal to the one-past-the-end value for any
02578        * iterator of the same type.
02579        */
02580       regex_token_iterator()
02581       : _M_position(), _M_subs(), _M_suffix(), _M_n(0), _M_result(nullptr),
02582       _M_has_m1(false)
02583       { }
02584 
02585       /**
02586        * Constructs a %regex_token_iterator...
02587        * @param __a          [IN] The start of the text to search.
02588        * @param __b          [IN] One-past-the-end of the text to search.
02589        * @param __re         [IN] The regular expression to search for.
02590        * @param __submatch   [IN] Which submatch to return.  There are some
02591        *                        special values for this parameter:
02592        *                        - -1 each enumerated subexpression does NOT
02593        *                          match the regular expression (aka field
02594        *                          splitting)
02595        *                        - 0 the entire string matching the
02596        *                          subexpression is returned for each match
02597        *                          within the text.
02598        *                        - >0 enumerates only the indicated
02599        *                          subexpression from a match within the text.
02600        * @param __m          [IN] Policy flags for match rules.
02601        */
02602       regex_token_iterator(_Bi_iter __a, _Bi_iter __b, const regex_type& __re,
02603                            int __submatch = 0,
02604                            regex_constants::match_flag_type __m
02605                            = regex_constants::match_default)
02606       : _M_position(__a, __b, __re, __m), _M_subs(1, __submatch), _M_n(0)
02607       { _M_init(__a, __b); }
02608 
02609       /**
02610        * Constructs a %regex_token_iterator...
02611        * @param __a          [IN] The start of the text to search.
02612        * @param __b          [IN] One-past-the-end of the text to search.
02613        * @param __re         [IN] The regular expression to search for.
02614        * @param __submatches [IN] A list of subexpressions to return for each
02615        *                          regular expression match within the text.
02616        * @param __m          [IN] Policy flags for match rules.
02617        */
02618       regex_token_iterator(_Bi_iter __a, _Bi_iter __b,
02619                            const regex_type& __re,
02620                            const std::vector<int>& __submatches,
02621                            regex_constants::match_flag_type __m
02622                              = regex_constants::match_default)
02623       : _M_position(__a, __b, __re, __m), _M_subs(__submatches), _M_n(0)
02624       { _M_init(__a, __b); }
02625 
02626       /**
02627        * Constructs a %regex_token_iterator...
02628        * @param __a          [IN] The start of the text to search.
02629        * @param __b          [IN] One-past-the-end of the text to search.
02630        * @param __re         [IN] The regular expression to search for.
02631        * @param __submatches [IN] A list of subexpressions to return for each
02632        *                          regular expression match within the text.
02633        * @param __m          [IN] Policy flags for match rules.
02634        */
02635       regex_token_iterator(_Bi_iter __a, _Bi_iter __b,
02636                            const regex_type& __re,
02637                            initializer_list<int> __submatches,
02638                            regex_constants::match_flag_type __m
02639                              = regex_constants::match_default)
02640       : _M_position(__a, __b, __re, __m), _M_subs(__submatches), _M_n(0)
02641       { _M_init(__a, __b); }
02642 
02643       /**
02644        * Constructs a %regex_token_iterator...
02645        * @param __a          [IN] The start of the text to search.
02646        * @param __b          [IN] One-past-the-end of the text to search.
02647        * @param __re         [IN] The regular expression to search for.
02648        * @param __submatches [IN] A list of subexpressions to return for each
02649        *                          regular expression match within the text.
02650        * @param __m          [IN] Policy flags for match rules.
02651        */
02652       template<std::size_t _Nm>
02653         regex_token_iterator(_Bi_iter __a, _Bi_iter __b,
02654                              const regex_type& __re,
02655                              const int (&__submatches)[_Nm],
02656                              regex_constants::match_flag_type __m
02657                              = regex_constants::match_default)
02658       : _M_position(__a, __b, __re, __m),
02659       _M_subs(__submatches, __submatches + _Nm), _M_n(0)
02660       { _M_init(__a, __b); }
02661 
02662       // _GLIBCXX_RESOLVE_LIB_DEFECTS
02663       // 2332. regex_token_iterator should forbid temporary regexes
02664       regex_token_iterator(_Bi_iter, _Bi_iter, const regex_type&&, int = 0,
02665                            regex_constants::match_flag_type =
02666                            regex_constants::match_default) = delete;
02667       regex_token_iterator(_Bi_iter, _Bi_iter, const regex_type&&,
02668                            const std::vector<int>&,
02669                            regex_constants::match_flag_type =
02670                            regex_constants::match_default) = delete;
02671       regex_token_iterator(_Bi_iter, _Bi_iter, const regex_type&&,
02672                            initializer_list<int>,
02673                            regex_constants::match_flag_type =
02674                            regex_constants::match_default) = delete;
02675       template <std::size_t _Nm>
02676         regex_token_iterator(_Bi_iter, _Bi_iter, const regex_type&&,
02677                              const int (&)[_Nm],
02678                              regex_constants::match_flag_type =
02679                              regex_constants::match_default) = delete;
02680 
02681       /**
02682        * @brief Copy constructs a %regex_token_iterator.
02683        * @param __rhs [IN] A %regex_token_iterator to copy.
02684        */
02685       regex_token_iterator(const regex_token_iterator& __rhs)
02686       : _M_position(__rhs._M_position), _M_subs(__rhs._M_subs),
02687       _M_suffix(__rhs._M_suffix), _M_n(__rhs._M_n), _M_has_m1(__rhs._M_has_m1)
02688       { _M_normalize_result(); }
02689 
02690       /**
02691        * @brief Assigns a %regex_token_iterator to another.
02692        * @param __rhs [IN] A %regex_token_iterator to copy.
02693        */
02694       regex_token_iterator&
02695       operator=(const regex_token_iterator& __rhs);
02696 
02697       /**
02698        * @brief Compares a %regex_token_iterator to another for equality.
02699        */
02700       bool
02701       operator==(const regex_token_iterator& __rhs) const;
02702 
02703       /**
02704        * @brief Compares a %regex_token_iterator to another for inequality.
02705        */
02706       bool
02707       operator!=(const regex_token_iterator& __rhs) const
02708       { return !(*this == __rhs); }
02709 
02710       /**
02711        * @brief Dereferences a %regex_token_iterator.
02712        */
02713       const value_type&
02714       operator*() const
02715       { return *_M_result; }
02716 
02717       /**
02718        * @brief Selects a %regex_token_iterator member.
02719        */
02720       const value_type*
02721       operator->() const
02722       { return _M_result; }
02723 
02724       /**
02725        * @brief Increments a %regex_token_iterator.
02726        */
02727       regex_token_iterator&
02728       operator++();
02729 
02730       /**
02731        * @brief Postincrements a %regex_token_iterator.
02732        */
02733       regex_token_iterator
02734       operator++(int)
02735       {
02736         auto __tmp = *this;
02737         ++(*this);
02738         return __tmp;
02739       }
02740 
02741     private:
02742       typedef regex_iterator<_Bi_iter, _Ch_type, _Rx_traits> _Position;
02743 
02744       void
02745       _M_init(_Bi_iter __a, _Bi_iter __b);
02746 
02747       const value_type&
02748       _M_current_match() const
02749       {
02750         if (_M_subs[_M_n] == -1)
02751           return (*_M_position).prefix();
02752         else
02753           return (*_M_position)[_M_subs[_M_n]];
02754       }
02755 
02756       constexpr bool
02757       _M_end_of_seq() const
02758       { return _M_result == nullptr; }
02759 
02760       // [28.12.2.2.4]
02761       void
02762       _M_normalize_result()
02763       {
02764         if (_M_position != _Position())
02765           _M_result = &_M_current_match();
02766         else if (_M_has_m1)
02767           _M_result = &_M_suffix;
02768         else
02769           _M_result = nullptr;
02770       }
02771 
02772       _Position         _M_position;
02773       std::vector<int>  _M_subs;
02774       value_type        _M_suffix;
02775       std::size_t       _M_n;
02776       const value_type* _M_result;
02777 
02778       // Show whether _M_subs contains -1
02779       bool              _M_has_m1;
02780     };
02781 
02782   /** @brief Token iterator for C-style NULL-terminated strings. */
02783   typedef regex_token_iterator<const char*>             cregex_token_iterator;
02784 
02785   /** @brief Token iterator for standard strings. */
02786   typedef regex_token_iterator<string::const_iterator>  sregex_token_iterator;
02787 
02788 #ifdef _GLIBCXX_USE_WCHAR_T
02789   /** @brief Token iterator for C-style NULL-terminated wide strings. */
02790   typedef regex_token_iterator<const wchar_t*>          wcregex_token_iterator;
02791 
02792   /** @brief Token iterator for standard wide-character strings. */
02793   typedef regex_token_iterator<wstring::const_iterator> wsregex_token_iterator;
02794 #endif
02795 
02796   //@} // group regex
02797 
02798 _GLIBCXX_END_NAMESPACE_CXX11
02799 _GLIBCXX_END_NAMESPACE_VERSION
02800 } // namespace
02801 
02802 #include <bits/regex.tcc>