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