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