Home | History | Annotate | Download | only in bits
      1 // class template regex -*- C++ -*-
      2 
      3 // Copyright (C) 2010-2014 Free Software Foundation, Inc.
      4 //
      5 // This file is part of the GNU ISO C++ Library.  This library is free
      6 // software; you can redistribute it and/or modify it under the
      7 // terms of the GNU General Public License as published by the
      8 // Free Software Foundation; either version 3, or (at your option)
      9 // any later version.
     10 
     11 // This library is distributed in the hope that it will be useful,
     12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
     13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     14 // GNU General Public License for more details.
     15 
     16 // Under Section 7 of GPL version 3, you are granted additional
     17 // permissions described in the GCC Runtime Library Exception, version
     18 // 3.1, as published by the Free Software Foundation.
     19 
     20 // You should have received a copy of the GNU General Public License and
     21 // a copy of the GCC Runtime Library Exception along with this program;
     22 // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
     23 // <http://www.gnu.org/licenses/>.
     24 
     25 /**
     26  *  @file bits/regex.h
     27  *  This is an internal header file, included by other library headers.
     28  *  Do not attempt to use it directly. @headername{regex}
     29  */
     30 
     31 namespace std _GLIBCXX_VISIBILITY(default)
     32 {
     33 _GLIBCXX_BEGIN_NAMESPACE_VERSION
     34   template<typename, typename>
     35     class basic_regex;
     36 
     37   template<typename, typename>
     38     class match_results;
     39 
     40 _GLIBCXX_END_NAMESPACE_VERSION
     41 
     42 namespace __detail
     43 {
     44 _GLIBCXX_BEGIN_NAMESPACE_VERSION
     45 
     46   enum class _RegexExecutorPolicy : int
     47     { _S_auto, _S_alternate };
     48 
     49   template<typename _BiIter, typename _Alloc,
     50 	   typename _CharT, typename _TraitsT,
     51 	   _RegexExecutorPolicy __policy,
     52 	   bool __match_mode>
     53     bool
     54     __regex_algo_impl(_BiIter                              __s,
     55 		      _BiIter                              __e,
     56 		      match_results<_BiIter, _Alloc>&      __m,
     57 		      const basic_regex<_CharT, _TraitsT>& __re,
     58 		      regex_constants::match_flag_type     __flags);
     59 
     60   template<typename, typename, typename, bool>
     61     class _Executor;
     62 
     63   template<typename _TraitsT>
     64     inline std::shared_ptr<_NFA<_TraitsT>>
     65     __compile_nfa(const typename _TraitsT::char_type* __first,
     66 		  const typename _TraitsT::char_type* __last,
     67 		  const _TraitsT& __traits,
     68 		  regex_constants::syntax_option_type __flags);
     69 
     70 _GLIBCXX_END_NAMESPACE_VERSION
     71 }
     72 
     73 _GLIBCXX_BEGIN_NAMESPACE_VERSION
     74 
     75   /**
     76    * @addtogroup regex
     77    * @{
     78    */
     79 
     80   /**
     81    * @brief Describes aspects of a regular expression.
     82    *
     83    * A regular expression traits class that satisfies the requirements of
     84    * section [28.7].
     85    *
     86    * The class %regex is parameterized around a set of related types and
     87    * functions used to complete the definition of its semantics.  This class
     88    * satisfies the requirements of such a traits class.
     89    */
     90   template<typename _Ch_type>
     91     struct regex_traits
     92     {
     93     public:
     94       typedef _Ch_type                     	char_type;
     95       typedef std::basic_string<char_type> 	string_type;
     96       typedef std::locale                  	locale_type;
     97     private:
     98       struct _RegexMask
     99 	{
    100 	  typedef typename std::ctype<char_type>::mask _BaseType;
    101 	  _BaseType _M_base;
    102 	  unsigned char _M_extended;
    103 	  static constexpr unsigned char _S_under = 1 << 0;
    104 	  // FIXME: _S_blank should be removed in the future,
    105 	  // when locale's complete.
    106 	  static constexpr unsigned char _S_blank = 1 << 1;
    107 	  static constexpr unsigned char _S_valid_mask = 0x3;
    108 
    109 	  constexpr _RegexMask(_BaseType __base = 0,
    110 			       unsigned char __extended = 0)
    111 	  : _M_base(__base), _M_extended(__extended)
    112 	  { }
    113 
    114 	  constexpr _RegexMask
    115 	  operator&(_RegexMask __other) const
    116 	  {
    117 	    return _RegexMask(_M_base & __other._M_base,
    118 			      _M_extended & __other._M_extended);
    119 	  }
    120 
    121 	  constexpr _RegexMask
    122 	  operator|(_RegexMask __other) const
    123 	  {
    124 	    return _RegexMask(_M_base | __other._M_base,
    125 			      _M_extended | __other._M_extended);
    126 	  }
    127 
    128 	  constexpr _RegexMask
    129 	  operator^(_RegexMask __other) const
    130 	  {
    131 	    return _RegexMask(_M_base ^ __other._M_base,
    132 			      _M_extended ^ __other._M_extended);
    133 	  }
    134 
    135 	  constexpr _RegexMask
    136 	  operator~() const
    137 	  { return _RegexMask(~_M_base, ~_M_extended); }
    138 
    139 	  _RegexMask&
    140 	  operator&=(_RegexMask __other)
    141 	  { return *this = (*this) & __other; }
    142 
    143 	  _RegexMask&
    144 	  operator|=(_RegexMask __other)
    145 	  { return *this = (*this) | __other; }
    146 
    147 	  _RegexMask&
    148 	  operator^=(_RegexMask __other)
    149 	  { return *this = (*this) ^ __other; }
    150 
    151 	  constexpr bool
    152 	  operator==(_RegexMask __other) const
    153 	  {
    154 	    return (_M_extended & _S_valid_mask)
    155 		   == (__other._M_extended & _S_valid_mask)
    156 		     && _M_base == __other._M_base;
    157 	  }
    158 
    159 	  constexpr bool
    160 	  operator!=(_RegexMask __other) const
    161 	  { return !((*this) == __other); }
    162 
    163 	};
    164     public:
    165       typedef _RegexMask char_class_type;
    166 
    167     public:
    168       /**
    169        * @brief Constructs a default traits object.
    170        */
    171       regex_traits() { }
    172 
    173       /**
    174        * @brief Gives the length of a C-style string starting at @p __p.
    175        *
    176        * @param __p a pointer to the start of a character sequence.
    177        *
    178        * @returns the number of characters between @p *__p and the first
    179        * default-initialized value of type @p char_type.  In other words, uses
    180        * the C-string algorithm for determining the length of a sequence of
    181        * characters.
    182        */
    183       static std::size_t
    184       length(const char_type* __p)
    185       { return string_type::traits_type::length(__p); }
    186 
    187       /**
    188        * @brief Performs the identity translation.
    189        *
    190        * @param __c A character to the locale-specific character set.
    191        *
    192        * @returns __c.
    193        */
    194       char_type
    195       translate(char_type __c) const
    196       { return __c; }
    197 
    198       /**
    199        * @brief Translates a character into a case-insensitive equivalent.
    200        *
    201        * @param __c A character to the locale-specific character set.
    202        *
    203        * @returns the locale-specific lower-case equivalent of __c.
    204        * @throws std::bad_cast if the imbued locale does not support the ctype
    205        *         facet.
    206        */
    207       char_type
    208       translate_nocase(char_type __c) const
    209       {
    210 	typedef std::ctype<char_type> __ctype_type;
    211 	const __ctype_type& __fctyp(use_facet<__ctype_type>(_M_locale));
    212 	return __fctyp.tolower(__c);
    213       }
    214 
    215       /**
    216        * @brief Gets a sort key for a character sequence.
    217        *
    218        * @param __first beginning of the character sequence.
    219        * @param __last  one-past-the-end of the character sequence.
    220        *
    221        * Returns a sort key for the character sequence designated by the
    222        * iterator range [F1, F2) such that if the character sequence [G1, G2)
    223        * sorts before the character sequence [H1, H2) then
    224        * v.transform(G1, G2) < v.transform(H1, H2).
    225        *
    226        * What this really does is provide a more efficient way to compare a
    227        * string to multiple other strings in locales with fancy collation
    228        * rules and equivalence classes.
    229        *
    230        * @returns a locale-specific sort key equivalent to the input range.
    231        *
    232        * @throws std::bad_cast if the current locale does not have a collate
    233        *         facet.
    234        */
    235       template<typename _Fwd_iter>
    236 	string_type
    237 	transform(_Fwd_iter __first, _Fwd_iter __last) const
    238 	{
    239 	  typedef std::collate<char_type> __collate_type;
    240 	  const __collate_type& __fclt(use_facet<__collate_type>(_M_locale));
    241 	  string_type __s(__first, __last);
    242 	  return __fclt.transform(__s.data(), __s.data() + __s.size());
    243 	}
    244 
    245       /**
    246        * @brief Gets a sort key for a character sequence, independent of case.
    247        *
    248        * @param __first beginning of the character sequence.
    249        * @param __last  one-past-the-end of the character sequence.
    250        *
    251        * Effects: if typeid(use_facet<collate<_Ch_type> >) ==
    252        * typeid(collate_byname<_Ch_type>) and the form of the sort key
    253        * returned by collate_byname<_Ch_type>::transform(__first, __last)
    254        * is known and can be converted into a primary sort key
    255        * then returns that key, otherwise returns an empty string.
    256        *
    257        * @todo Implement this function correctly.
    258        */
    259       template<typename _Fwd_iter>
    260 	string_type
    261 	transform_primary(_Fwd_iter __first, _Fwd_iter __last) const
    262 	{
    263 	  // TODO : this is not entirely correct.
    264 	  // This function requires extra support from the platform.
    265 	  //
    266 	  // Read http://gcc.gnu.org/ml/libstdc++/2013-09/msg00117.html and
    267 	  // http://www.open-std.org/Jtc1/sc22/wg21/docs/papers/2003/n1429.htm
    268 	  // for details.
    269 	  typedef std::ctype<char_type> __ctype_type;
    270 	  const __ctype_type& __fctyp(use_facet<__ctype_type>(_M_locale));
    271 	  std::vector<char_type> __s(__first, __last);
    272 	  __fctyp.tolower(__s.data(), __s.data() + __s.size());
    273 	  return this->transform(__s.data(), __s.data() + __s.size());
    274 	}
    275 
    276       /**
    277        * @brief Gets a collation element by name.
    278        *
    279        * @param __first beginning of the collation element name.
    280        * @param __last  one-past-the-end of the collation element name.
    281        *
    282        * @returns a sequence of one or more characters that represents the
    283        * collating element consisting of the character sequence designated by
    284        * the iterator range [__first, __last). Returns an empty string if the
    285        * character sequence is not a valid collating element.
    286        */
    287       template<typename _Fwd_iter>
    288 	string_type
    289 	lookup_collatename(_Fwd_iter __first, _Fwd_iter __last) const;
    290 
    291       /**
    292        * @brief Maps one or more characters to a named character
    293        *        classification.
    294        *
    295        * @param __first beginning of the character sequence.
    296        * @param __last  one-past-the-end of the character sequence.
    297        * @param __icase ignores the case of the classification name.
    298        *
    299        * @returns an unspecified value that represents the character
    300        * classification named by the character sequence designated by
    301        * the iterator range [__first, __last). If @p icase is true,
    302        * the returned mask identifies the classification regardless of
    303        * the case of the characters to be matched (for example,
    304        * [[:lower:]] is the same as [[:alpha:]]), otherwise a
    305        * case-dependent classification is returned.  The value
    306        * returned shall be independent of the case of the characters
    307        * in the character sequence. If the name is not recognized then
    308        * returns a value that compares equal to 0.
    309        *
    310        * At least the following names (or their wide-character equivalent) are
    311        * supported.
    312        * - d
    313        * - w
    314        * - s
    315        * - alnum
    316        * - alpha
    317        * - blank
    318        * - cntrl
    319        * - digit
    320        * - graph
    321        * - lower
    322        * - print
    323        * - punct
    324        * - space
    325        * - upper
    326        * - xdigit
    327        */
    328       template<typename _Fwd_iter>
    329 	char_class_type
    330 	lookup_classname(_Fwd_iter __first, _Fwd_iter __last,
    331 			 bool __icase = false) const;
    332 
    333       /**
    334        * @brief Determines if @p c is a member of an identified class.
    335        *
    336        * @param __c a character.
    337        * @param __f a class type (as returned from lookup_classname).
    338        *
    339        * @returns true if the character @p __c is a member of the classification
    340        * represented by @p __f, false otherwise.
    341        *
    342        * @throws std::bad_cast if the current locale does not have a ctype
    343        *         facet.
    344        */
    345       bool
    346       isctype(_Ch_type __c, char_class_type __f) const;
    347 
    348       /**
    349        * @brief Converts a digit to an int.
    350        *
    351        * @param __ch    a character representing a digit.
    352        * @param __radix the radix if the numeric conversion (limited to 8, 10,
    353        *              or 16).
    354        *
    355        * @returns the value represented by the digit __ch in base radix if the
    356        * character __ch is a valid digit in base radix; otherwise returns -1.
    357        */
    358       int
    359       value(_Ch_type __ch, int __radix) const;
    360 
    361       /**
    362        * @brief Imbues the regex_traits object with a copy of a new locale.
    363        *
    364        * @param __loc A locale.
    365        *
    366        * @returns a copy of the previous locale in use by the regex_traits
    367        *          object.
    368        *
    369        * @note Calling imbue with a different locale than the one currently in
    370        *       use invalidates all cached data held by *this.
    371        */
    372       locale_type
    373       imbue(locale_type __loc)
    374       {
    375 	std::swap(_M_locale, __loc);
    376 	return __loc;
    377       }
    378 
    379       /**
    380        * @brief Gets a copy of the current locale in use by the regex_traits
    381        * object.
    382        */
    383       locale_type
    384       getloc() const
    385       { return _M_locale; }
    386 
    387     protected:
    388       locale_type _M_locale;
    389     };
    390 
    391   // [7.8] Class basic_regex
    392   /**
    393    * Objects of specializations of this class represent regular expressions
    394    * constructed from sequences of character type @p _Ch_type.
    395    *
    396    * Storage for the regular expression is allocated and deallocated as
    397    * necessary by the member functions of this class.
    398    */
    399   template<typename _Ch_type, typename _Rx_traits = regex_traits<_Ch_type>>
    400     class basic_regex
    401     {
    402     public:
    403       static_assert(is_same<_Ch_type, typename _Rx_traits::char_type>::value,
    404 		    "regex traits class must have the same char_type");
    405 
    406       // types:
    407       typedef _Ch_type                            value_type;
    408       typedef _Rx_traits                          traits_type;
    409       typedef typename traits_type::string_type   string_type;
    410       typedef regex_constants::syntax_option_type flag_type;
    411       typedef typename traits_type::locale_type   locale_type;
    412 
    413       /**
    414        * @name Constants
    415        * std [28.8.1](1)
    416        */
    417       //@{
    418       static constexpr flag_type icase = regex_constants::icase;
    419       static constexpr flag_type nosubs = regex_constants::nosubs;
    420       static constexpr flag_type optimize = regex_constants::optimize;
    421       static constexpr flag_type collate = regex_constants::collate;
    422       static constexpr flag_type ECMAScript = regex_constants::ECMAScript;
    423       static constexpr flag_type basic = regex_constants::basic;
    424       static constexpr flag_type extended = regex_constants::extended;
    425       static constexpr flag_type awk = regex_constants::awk;
    426       static constexpr flag_type grep = regex_constants::grep;
    427       static constexpr flag_type egrep = regex_constants::egrep;
    428       //@}
    429 
    430       // [7.8.2] construct/copy/destroy
    431       /**
    432        * Constructs a basic regular expression that does not match any
    433        * character sequence.
    434        */
    435       basic_regex()
    436       : _M_flags(ECMAScript), _M_automaton(nullptr)
    437       { }
    438 
    439       /**
    440        * @brief Constructs a basic regular expression from the
    441        * sequence [__p, __p + char_traits<_Ch_type>::length(__p))
    442        * interpreted according to the flags in @p __f.
    443        *
    444        * @param __p A pointer to the start of a C-style null-terminated string
    445        *          containing a regular expression.
    446        * @param __f Flags indicating the syntax rules and options.
    447        *
    448        * @throws regex_error if @p __p is not a valid regular expression.
    449        */
    450       explicit
    451       basic_regex(const _Ch_type* __p, flag_type __f = ECMAScript)
    452       : basic_regex(__p, __p + _Rx_traits::length(__p), __f)
    453       { }
    454 
    455       /**
    456        * @brief Constructs a basic regular expression from the sequence
    457        * [p, p + len) interpreted according to the flags in @p f.
    458        *
    459        * @param __p   A pointer to the start of a string containing a regular
    460        *              expression.
    461        * @param __len The length of the string containing the regular
    462        *              expression.
    463        * @param __f   Flags indicating the syntax rules and options.
    464        *
    465        * @throws regex_error if @p __p is not a valid regular expression.
    466        */
    467       basic_regex(const _Ch_type* __p, std::size_t __len,
    468 		  flag_type __f = ECMAScript)
    469       : basic_regex(__p, __p + __len, __f)
    470       { }
    471 
    472       /**
    473        * @brief Copy-constructs a basic regular expression.
    474        *
    475        * @param __rhs A @p regex object.
    476        */
    477       basic_regex(const basic_regex& __rhs) = default;
    478 
    479       /**
    480        * @brief Move-constructs a basic regular expression.
    481        *
    482        * @param __rhs A @p regex object.
    483        */
    484       basic_regex(const basic_regex&& __rhs) noexcept
    485       : _M_flags(__rhs._M_flags), _M_traits(__rhs._M_traits),
    486 	_M_automaton(std::move(__rhs._M_automaton))
    487       { }
    488 
    489       /**
    490        * @brief Constructs a basic regular expression from the string
    491        * @p s interpreted according to the flags in @p f.
    492        *
    493        * @param __s A string containing a regular expression.
    494        * @param __f Flags indicating the syntax rules and options.
    495        *
    496        * @throws regex_error if @p __s is not a valid regular expression.
    497        */
    498       template<typename _Ch_traits, typename _Ch_alloc>
    499 	explicit
    500 	basic_regex(const std::basic_string<_Ch_type, _Ch_traits,
    501 					    _Ch_alloc>& __s,
    502 		    flag_type __f = ECMAScript)
    503 	: basic_regex(__s.begin(), __s.end(), __f)
    504 	{ }
    505 
    506       /**
    507        * @brief Constructs a basic regular expression from the range
    508        * [first, last) interpreted according to the flags in @p f.
    509        *
    510        * @param __first The start of a range containing a valid regular
    511        *                expression.
    512        * @param __last  The end of a range containing a valid regular
    513        *                expression.
    514        * @param __f     The format flags of the regular expression.
    515        *
    516        * @throws regex_error if @p [__first, __last) is not a valid regular
    517        *         expression.
    518        */
    519       template<typename _FwdIter>
    520 	basic_regex(_FwdIter __first, _FwdIter __last,
    521 		    flag_type __f = ECMAScript)
    522 	: _M_flags(__f),
    523 	  _M_original_str(__first, __last),
    524 	  _M_automaton(__detail::__compile_nfa(_M_original_str.c_str(),
    525 					       _M_original_str.c_str()
    526 						 + _M_original_str.size(),
    527 					       _M_traits,
    528 					       _M_flags))
    529 	{ }
    530 
    531       /**
    532        * @brief Constructs a basic regular expression from an initializer list.
    533        *
    534        * @param __l  The initializer list.
    535        * @param __f  The format flags of the regular expression.
    536        *
    537        * @throws regex_error if @p __l is not a valid regular expression.
    538        */
    539       basic_regex(initializer_list<_Ch_type> __l, flag_type __f = ECMAScript)
    540       : basic_regex(__l.begin(), __l.end(), __f)
    541       { }
    542 
    543       /**
    544        * @brief Destroys a basic regular expression.
    545        */
    546       ~basic_regex()
    547       { }
    548 
    549       /**
    550        * @brief Assigns one regular expression to another.
    551        */
    552       basic_regex&
    553       operator=(const basic_regex& __rhs)
    554       { return this->assign(__rhs); }
    555 
    556       /**
    557        * @brief Move-assigns one regular expression to another.
    558        */
    559       basic_regex&
    560       operator=(basic_regex&& __rhs) noexcept
    561       { return this->assign(std::move(__rhs)); }
    562 
    563       /**
    564        * @brief Replaces a regular expression with a new one constructed from
    565        * a C-style null-terminated string.
    566        *
    567        * @param __p A pointer to the start of a null-terminated C-style string
    568        *        containing a regular expression.
    569        */
    570       basic_regex&
    571       operator=(const _Ch_type* __p)
    572       { return this->assign(__p, flags()); }
    573 
    574       /**
    575        * @brief Replaces a regular expression with a new one constructed from
    576        * a string.
    577        *
    578        * @param __s A pointer to a string containing a regular expression.
    579        */
    580       template<typename _Ch_typeraits, typename _Alloc>
    581 	basic_regex&
    582 	operator=(const basic_string<_Ch_type, _Ch_typeraits, _Alloc>& __s)
    583 	{ return this->assign(__s, flags()); }
    584 
    585       // [7.8.3] assign
    586       /**
    587        * @brief the real assignment operator.
    588        *
    589        * @param __rhs Another regular expression object.
    590        */
    591       basic_regex&
    592       assign(const basic_regex& __rhs)
    593       {
    594 	basic_regex __tmp(__rhs);
    595 	this->swap(__tmp);
    596 	return *this;
    597       }
    598 
    599       /**
    600        * @brief The move-assignment operator.
    601        *
    602        * @param __rhs Another regular expression object.
    603        */
    604       basic_regex&
    605       assign(basic_regex&& __rhs) noexcept
    606       {
    607 	basic_regex __tmp(std::move(__rhs));
    608 	this->swap(__tmp);
    609 	return *this;
    610       }
    611 
    612       /**
    613        * @brief Assigns a new regular expression to a regex object from a
    614        * C-style null-terminated string containing a regular expression
    615        * pattern.
    616        *
    617        * @param __p     A pointer to a C-style null-terminated string containing
    618        *              a regular expression pattern.
    619        * @param __flags Syntax option flags.
    620        *
    621        * @throws regex_error if __p does not contain a valid regular
    622        * expression pattern interpreted according to @p __flags.  If
    623        * regex_error is thrown, *this remains unchanged.
    624        */
    625       basic_regex&
    626       assign(const _Ch_type* __p, flag_type __flags = ECMAScript)
    627       { return this->assign(string_type(__p), __flags); }
    628 
    629       /**
    630        * @brief Assigns a new regular expression to a regex object from a
    631        * C-style string containing a regular expression pattern.
    632        *
    633        * @param __p     A pointer to a C-style string containing a
    634        *                regular expression pattern.
    635        * @param __len   The length of the regular expression pattern string.
    636        * @param __flags Syntax option flags.
    637        *
    638        * @throws regex_error if p does not contain a valid regular
    639        * expression pattern interpreted according to @p __flags.  If
    640        * regex_error is thrown, *this remains unchanged.
    641        */
    642       basic_regex&
    643       assign(const _Ch_type* __p, std::size_t __len, flag_type __flags)
    644       { return this->assign(string_type(__p, __len), __flags); }
    645 
    646       /**
    647        * @brief Assigns a new regular expression to a regex object from a
    648        * string containing a regular expression pattern.
    649        *
    650        * @param __s     A string containing a regular expression pattern.
    651        * @param __flags Syntax option flags.
    652        *
    653        * @throws regex_error if __s does not contain a valid regular
    654        * expression pattern interpreted according to @p __flags.  If
    655        * regex_error is thrown, *this remains unchanged.
    656        */
    657       template<typename _Ch_typeraits, typename _Alloc>
    658 	basic_regex&
    659 	assign(const basic_string<_Ch_type, _Ch_typeraits, _Alloc>& __s,
    660 	       flag_type __flags = ECMAScript)
    661 	{
    662 	  _M_flags = __flags;
    663 	  _M_original_str.assign(__s.begin(), __s.end());
    664 	  auto __p = _M_original_str.c_str();
    665 	  _M_automaton = __detail::__compile_nfa(__p,
    666 						 __p + _M_original_str.size(),
    667 						 _M_traits, _M_flags);
    668 	  return *this;
    669 	}
    670 
    671       /**
    672        * @brief Assigns a new regular expression to a regex object.
    673        *
    674        * @param __first The start of a range containing a valid regular
    675        *                expression.
    676        * @param __last  The end of a range containing a valid regular
    677        *                expression.
    678        * @param __flags Syntax option flags.
    679        *
    680        * @throws regex_error if p does not contain a valid regular
    681        * expression pattern interpreted according to @p __flags.  If
    682        * regex_error is thrown, the object remains unchanged.
    683        */
    684       template<typename _InputIterator>
    685 	basic_regex&
    686 	assign(_InputIterator __first, _InputIterator __last,
    687 	       flag_type __flags = ECMAScript)
    688 	{ return this->assign(string_type(__first, __last), __flags); }
    689 
    690       /**
    691        * @brief Assigns a new regular expression to a regex object.
    692        *
    693        * @param __l     An initializer list representing a regular expression.
    694        * @param __flags Syntax option flags.
    695        *
    696        * @throws regex_error if @p __l does not contain a valid
    697        * regular expression pattern interpreted according to @p
    698        * __flags.  If regex_error is thrown, the object remains
    699        * unchanged.
    700        */
    701       basic_regex&
    702       assign(initializer_list<_Ch_type> __l, flag_type __flags = ECMAScript)
    703       { return this->assign(__l.begin(), __l.end(), __flags); }
    704 
    705       // [7.8.4] const operations
    706       /**
    707        * @brief Gets the number of marked subexpressions within the regular
    708        * expression.
    709        */
    710       unsigned int
    711       mark_count() const
    712       { return _M_automaton->_M_sub_count() - 1; }
    713 
    714       /**
    715        * @brief Gets the flags used to construct the regular expression
    716        * or in the last call to assign().
    717        */
    718       flag_type
    719       flags() const
    720       { return _M_flags; }
    721 
    722       // [7.8.5] locale
    723       /**
    724        * @brief Imbues the regular expression object with the given locale.
    725        *
    726        * @param __loc A locale.
    727        */
    728       locale_type
    729       imbue(locale_type __loc)
    730       {
    731 	auto __ret = _M_traits.imbue(__loc);
    732 	this->assign(_M_original_str, _M_flags);
    733 	return __ret;
    734       }
    735 
    736       /**
    737        * @brief Gets the locale currently imbued in the regular expression
    738        *        object.
    739        */
    740       locale_type
    741       getloc() const
    742       { return _M_traits.getloc(); }
    743 
    744       // [7.8.6] swap
    745       /**
    746        * @brief Swaps the contents of two regular expression objects.
    747        *
    748        * @param __rhs Another regular expression object.
    749        */
    750       void
    751       swap(basic_regex& __rhs)
    752       {
    753 	std::swap(_M_flags, __rhs._M_flags);
    754 	std::swap(_M_traits, __rhs._M_traits);
    755 	std::swap(_M_automaton, __rhs._M_automaton);
    756       }
    757 
    758 #ifdef _GLIBCXX_DEBUG
    759       void
    760       _M_dot(std::ostream& __ostr)
    761       { _M_automaton->_M_dot(__ostr); }
    762 #endif
    763 
    764     protected:
    765       typedef std::shared_ptr<__detail::_NFA<_Rx_traits>> _AutomatonPtr;
    766 
    767       template<typename _Bp, typename _Ap, typename _Cp, typename _Rp,
    768 	__detail::_RegexExecutorPolicy, bool>
    769 	friend bool
    770 	__detail::__regex_algo_impl(_Bp, _Bp, match_results<_Bp, _Ap>&,
    771 				    const basic_regex<_Cp, _Rp>&,
    772 				    regex_constants::match_flag_type);
    773 
    774       template<typename, typename, typename, bool>
    775 	friend class __detail::_Executor;
    776 
    777       flag_type              _M_flags;
    778       _Rx_traits             _M_traits;
    779       basic_string<_Ch_type> _M_original_str;
    780       _AutomatonPtr          _M_automaton;
    781     };
    782 
    783   /** @brief Standard regular expressions. */
    784   typedef basic_regex<char>    regex;
    785 
    786 #ifdef _GLIBCXX_USE_WCHAR_T
    787   /** @brief Standard wide-character regular expressions. */
    788   typedef basic_regex<wchar_t> wregex;
    789 #endif
    790 
    791 
    792   // [7.8.6] basic_regex swap
    793   /**
    794    * @brief Swaps the contents of two regular expression objects.
    795    * @param __lhs First regular expression.
    796    * @param __rhs Second regular expression.
    797    */
    798   template<typename _Ch_type, typename _Rx_traits>
    799     inline void
    800     swap(basic_regex<_Ch_type, _Rx_traits>& __lhs,
    801 	 basic_regex<_Ch_type, _Rx_traits>& __rhs)
    802     { __lhs.swap(__rhs); }
    803 
    804 
    805   // [7.9] Class template sub_match
    806   /**
    807    * A sequence of characters matched by a particular marked sub-expression.
    808    *
    809    * An object of this class is essentially a pair of iterators marking a
    810    * matched subexpression within a regular expression pattern match. Such
    811    * objects can be converted to and compared with std::basic_string objects
    812    * of a similar base character type as the pattern matched by the regular
    813    * expression.
    814    *
    815    * The iterators that make up the pair are the usual half-open interval
    816    * referencing the actual original pattern matched.
    817    */
    818   template<typename _BiIter>
    819     class sub_match : public std::pair<_BiIter, _BiIter>
    820     {
    821       typedef iterator_traits<_BiIter>			__iter_traits;
    822 
    823     public:
    824       typedef typename __iter_traits::value_type      	value_type;
    825       typedef typename __iter_traits::difference_type 	difference_type;
    826       typedef _BiIter                                   iterator;
    827       typedef std::basic_string<value_type>             string_type;
    828 
    829       bool matched;
    830 
    831       constexpr sub_match() : matched() { }
    832 
    833       /**
    834        * Gets the length of the matching sequence.
    835        */
    836       difference_type
    837       length() const
    838       { return this->matched ? std::distance(this->first, this->second) : 0; }
    839 
    840       /**
    841        * @brief Gets the matching sequence as a string.
    842        *
    843        * @returns the matching sequence as a string.
    844        *
    845        * This is the implicit conversion operator.  It is identical to the
    846        * str() member function except that it will want to pop up in
    847        * unexpected places and cause a great deal of confusion and cursing
    848        * from the unwary.
    849        */
    850       operator string_type() const
    851       {
    852 	return this->matched
    853 	  ? string_type(this->first, this->second)
    854 	  : string_type();
    855       }
    856 
    857       /**
    858        * @brief Gets the matching sequence as a string.
    859        *
    860        * @returns the matching sequence as a string.
    861        */
    862       string_type
    863       str() const
    864       {
    865 	return this->matched
    866 	  ? string_type(this->first, this->second)
    867 	  : string_type();
    868       }
    869 
    870       /**
    871        * @brief Compares this and another matched sequence.
    872        *
    873        * @param __s Another matched sequence to compare to this one.
    874        *
    875        * @retval <0 this matched sequence will collate before @p __s.
    876        * @retval =0 this matched sequence is equivalent to @p __s.
    877        * @retval <0 this matched sequence will collate after @p __s.
    878        */
    879       int
    880       compare(const sub_match& __s) const
    881       { return this->str().compare(__s.str()); }
    882 
    883       /**
    884        * @brief Compares this sub_match to a string.
    885        *
    886        * @param __s A string to compare to this sub_match.
    887        *
    888        * @retval <0 this matched sequence will collate before @p __s.
    889        * @retval =0 this matched sequence is equivalent to @p __s.
    890        * @retval <0 this matched sequence will collate after @p __s.
    891        */
    892       int
    893       compare(const string_type& __s) const
    894       { return this->str().compare(__s); }
    895 
    896       /**
    897        * @brief Compares this sub_match to a C-style string.
    898        *
    899        * @param __s A C-style string to compare to this sub_match.
    900        *
    901        * @retval <0 this matched sequence will collate before @p __s.
    902        * @retval =0 this matched sequence is equivalent to @p __s.
    903        * @retval <0 this matched sequence will collate after @p __s.
    904        */
    905       int
    906       compare(const value_type* __s) const
    907       { return this->str().compare(__s); }
    908     };
    909 
    910 
    911   /** @brief Standard regex submatch over a C-style null-terminated string. */
    912   typedef sub_match<const char*>             csub_match;
    913 
    914   /** @brief Standard regex submatch over a standard string. */
    915   typedef sub_match<string::const_iterator>  ssub_match;
    916 
    917 #ifdef _GLIBCXX_USE_WCHAR_T
    918   /** @brief Regex submatch over a C-style null-terminated wide string. */
    919   typedef sub_match<const wchar_t*>          wcsub_match;
    920 
    921   /** @brief Regex submatch over a standard wide string. */
    922   typedef sub_match<wstring::const_iterator> wssub_match;
    923 #endif
    924 
    925   // [7.9.2] sub_match non-member operators
    926 
    927   /**
    928    * @brief Tests the equivalence of two regular expression submatches.
    929    * @param __lhs First regular expression submatch.
    930    * @param __rhs Second regular expression submatch.
    931    * @returns true if @a __lhs  is equivalent to @a __rhs, false otherwise.
    932    */
    933   template<typename _BiIter>
    934     inline bool
    935     operator==(const sub_match<_BiIter>& __lhs, const sub_match<_BiIter>& __rhs)
    936     { return __lhs.compare(__rhs) == 0; }
    937 
    938   /**
    939    * @brief Tests the inequivalence of two regular expression submatches.
    940    * @param __lhs First regular expression submatch.
    941    * @param __rhs Second regular expression submatch.
    942    * @returns true if @a __lhs  is not equivalent to @a __rhs, false otherwise.
    943    */
    944   template<typename _BiIter>
    945     inline bool
    946     operator!=(const sub_match<_BiIter>& __lhs, const sub_match<_BiIter>& __rhs)
    947     { return __lhs.compare(__rhs) != 0; }
    948 
    949   /**
    950    * @brief Tests the ordering of two regular expression submatches.
    951    * @param __lhs First regular expression submatch.
    952    * @param __rhs Second regular expression submatch.
    953    * @returns true if @a __lhs precedes @a __rhs, false otherwise.
    954    */
    955   template<typename _BiIter>
    956     inline bool
    957     operator<(const sub_match<_BiIter>& __lhs, const sub_match<_BiIter>& __rhs)
    958     { return __lhs.compare(__rhs) < 0; }
    959 
    960   /**
    961    * @brief Tests the ordering of two regular expression submatches.
    962    * @param __lhs First regular expression submatch.
    963    * @param __rhs Second regular expression submatch.
    964    * @returns true if @a __lhs does not succeed @a __rhs, false otherwise.
    965    */
    966   template<typename _BiIter>
    967     inline bool
    968     operator<=(const sub_match<_BiIter>& __lhs, const sub_match<_BiIter>& __rhs)
    969     { return __lhs.compare(__rhs) <= 0; }
    970 
    971   /**
    972    * @brief Tests the ordering of two regular expression submatches.
    973    * @param __lhs First regular expression submatch.
    974    * @param __rhs Second regular expression submatch.
    975    * @returns true if @a __lhs does not precede @a __rhs, false otherwise.
    976    */
    977   template<typename _BiIter>
    978     inline bool
    979     operator>=(const sub_match<_BiIter>& __lhs, const sub_match<_BiIter>& __rhs)
    980     { return __lhs.compare(__rhs) >= 0; }
    981 
    982   /**
    983    * @brief Tests the ordering of two regular expression submatches.
    984    * @param __lhs First regular expression submatch.
    985    * @param __rhs Second regular expression submatch.
    986    * @returns true if @a __lhs succeeds @a __rhs, false otherwise.
    987    */
    988   template<typename _BiIter>
    989     inline bool
    990     operator>(const sub_match<_BiIter>& __lhs, const sub_match<_BiIter>& __rhs)
    991     { return __lhs.compare(__rhs) > 0; }
    992 
    993   // Alias for sub_match'd string.
    994   template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
    995     using __sub_match_string = basic_string<
    996 			      typename iterator_traits<_Bi_iter>::value_type,
    997 			      _Ch_traits, _Ch_alloc>;
    998 
    999   /**
   1000    * @brief Tests the equivalence of a string and a regular expression
   1001    *        submatch.
   1002    * @param __lhs A string.
   1003    * @param __rhs A regular expression submatch.
   1004    * @returns true if @a __lhs  is equivalent to @a __rhs, false otherwise.
   1005    */
   1006   template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
   1007     inline bool
   1008     operator==(const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __lhs,
   1009 	       const sub_match<_Bi_iter>& __rhs)
   1010     { return __rhs.compare(__lhs.c_str()) == 0; }
   1011 
   1012   /**
   1013    * @brief Tests the inequivalence of a string and a regular expression
   1014    *        submatch.
   1015    * @param __lhs A string.
   1016    * @param __rhs A regular expression submatch.
   1017    * @returns true if @a __lhs  is not equivalent to @a __rhs, false otherwise.
   1018    */
   1019   template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
   1020     inline bool
   1021     operator!=(const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __lhs,
   1022 	       const sub_match<_Bi_iter>& __rhs)
   1023     { return !(__lhs == __rhs); }
   1024 
   1025   /**
   1026    * @brief Tests the ordering of a string and a regular expression submatch.
   1027    * @param __lhs A string.
   1028    * @param __rhs A regular expression submatch.
   1029    * @returns true if @a __lhs precedes @a __rhs, false otherwise.
   1030    */
   1031   template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
   1032     inline bool
   1033     operator<(const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __lhs,
   1034 	      const sub_match<_Bi_iter>& __rhs)
   1035      { return __rhs.compare(__lhs.c_str()) > 0; }
   1036 
   1037   /**
   1038    * @brief Tests the ordering of a string and a regular expression submatch.
   1039    * @param __lhs A string.
   1040    * @param __rhs A regular expression submatch.
   1041    * @returns true if @a __lhs succeeds @a __rhs, false otherwise.
   1042    */
   1043   template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
   1044     inline bool
   1045     operator>(const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __lhs,
   1046 	      const sub_match<_Bi_iter>& __rhs)
   1047     { return __rhs < __lhs; }
   1048 
   1049   /**
   1050    * @brief Tests the ordering of a string and a regular expression submatch.
   1051    * @param __lhs A string.
   1052    * @param __rhs A regular expression submatch.
   1053    * @returns true if @a __lhs does not precede @a __rhs, false otherwise.
   1054    */
   1055   template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
   1056     inline bool
   1057     operator>=(const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __lhs,
   1058 	       const sub_match<_Bi_iter>& __rhs)
   1059     { return !(__lhs < __rhs); }
   1060 
   1061   /**
   1062    * @brief Tests the ordering of a string and a regular expression submatch.
   1063    * @param __lhs A string.
   1064    * @param __rhs A regular expression submatch.
   1065    * @returns true if @a __lhs does not succeed @a __rhs, false otherwise.
   1066    */
   1067   template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
   1068     inline bool
   1069     operator<=(const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __lhs,
   1070 	       const sub_match<_Bi_iter>& __rhs)
   1071     { return !(__rhs < __lhs); }
   1072 
   1073   /**
   1074    * @brief Tests the equivalence of a regular expression submatch and a
   1075    *        string.
   1076    * @param __lhs A regular expression submatch.
   1077    * @param __rhs A string.
   1078    * @returns true if @a __lhs is equivalent to @a __rhs, false otherwise.
   1079    */
   1080   template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
   1081     inline bool
   1082     operator==(const sub_match<_Bi_iter>& __lhs,
   1083 	       const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __rhs)
   1084     { return __lhs.compare(__rhs.c_str()) == 0; }
   1085 
   1086   /**
   1087    * @brief Tests the inequivalence of a regular expression submatch and a
   1088    *        string.
   1089    * @param __lhs A regular expression submatch.
   1090    * @param __rhs A string.
   1091    * @returns true if @a __lhs is not equivalent to @a __rhs, false otherwise.
   1092    */
   1093   template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
   1094     inline bool
   1095     operator!=(const sub_match<_Bi_iter>& __lhs,
   1096 	       const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __rhs)
   1097     { return !(__lhs == __rhs); }
   1098 
   1099   /**
   1100    * @brief Tests the ordering of a regular expression submatch and a string.
   1101    * @param __lhs A regular expression submatch.
   1102    * @param __rhs A string.
   1103    * @returns true if @a __lhs precedes @a __rhs, false otherwise.
   1104    */
   1105   template<typename _Bi_iter, class _Ch_traits, class _Ch_alloc>
   1106     inline bool
   1107     operator<(const sub_match<_Bi_iter>& __lhs,
   1108 	      const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __rhs)
   1109     { return __lhs.compare(__rhs.c_str()) < 0; }
   1110 
   1111   /**
   1112    * @brief Tests the ordering of a regular expression submatch and a string.
   1113    * @param __lhs A regular expression submatch.
   1114    * @param __rhs A string.
   1115    * @returns true if @a __lhs succeeds @a __rhs, false otherwise.
   1116    */
   1117   template<typename _Bi_iter, class _Ch_traits, class _Ch_alloc>
   1118     inline bool
   1119     operator>(const sub_match<_Bi_iter>& __lhs,
   1120 	      const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __rhs)
   1121     { return __rhs < __lhs; }
   1122 
   1123   /**
   1124    * @brief Tests the ordering of a regular expression submatch and a string.
   1125    * @param __lhs A regular expression submatch.
   1126    * @param __rhs A string.
   1127    * @returns true if @a __lhs does not precede @a __rhs, false otherwise.
   1128    */
   1129   template<typename _Bi_iter, class _Ch_traits, class _Ch_alloc>
   1130     inline bool
   1131     operator>=(const sub_match<_Bi_iter>& __lhs,
   1132 	       const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __rhs)
   1133     { return !(__lhs < __rhs); }
   1134 
   1135   /**
   1136    * @brief Tests the ordering of a regular expression submatch and a string.
   1137    * @param __lhs A regular expression submatch.
   1138    * @param __rhs A string.
   1139    * @returns true if @a __lhs does not succeed @a __rhs, false otherwise.
   1140    */
   1141   template<typename _Bi_iter, class _Ch_traits, class _Ch_alloc>
   1142     inline bool
   1143     operator<=(const sub_match<_Bi_iter>& __lhs,
   1144 	       const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __rhs)
   1145     { return !(__rhs < __lhs); }
   1146 
   1147   /**
   1148    * @brief Tests the equivalence of a C string and a regular expression
   1149    *        submatch.
   1150    * @param __lhs A C string.
   1151    * @param __rhs A regular expression submatch.
   1152    * @returns true if @a __lhs  is equivalent to @a __rhs, false otherwise.
   1153    */
   1154   template<typename _Bi_iter>
   1155     inline bool
   1156     operator==(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
   1157 	       const sub_match<_Bi_iter>& __rhs)
   1158     { return __rhs.compare(__lhs) == 0; }
   1159 
   1160   /**
   1161    * @brief Tests the inequivalence of an iterator value and a regular
   1162    *        expression submatch.
   1163    * @param __lhs A regular expression submatch.
   1164    * @param __rhs A string.
   1165    * @returns true if @a __lhs is not equivalent to @a __rhs, false otherwise.
   1166    */
   1167   template<typename _Bi_iter>
   1168     inline bool
   1169     operator!=(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
   1170 	       const sub_match<_Bi_iter>& __rhs)
   1171     { return !(__lhs == __rhs); }
   1172 
   1173   /**
   1174    * @brief Tests the ordering of a string and a regular expression submatch.
   1175    * @param __lhs A string.
   1176    * @param __rhs A regular expression submatch.
   1177    * @returns true if @a __lhs precedes @a __rhs, false otherwise.
   1178    */
   1179   template<typename _Bi_iter>
   1180     inline bool
   1181     operator<(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
   1182 	      const sub_match<_Bi_iter>& __rhs)
   1183     { return __rhs.compare(__lhs) > 0; }
   1184 
   1185   /**
   1186    * @brief Tests the ordering of a string and a regular expression submatch.
   1187    * @param __lhs A string.
   1188    * @param __rhs A regular expression submatch.
   1189    * @returns true if @a __lhs succeeds @a __rhs, false otherwise.
   1190    */
   1191   template<typename _Bi_iter>
   1192     inline bool
   1193     operator>(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
   1194 	      const sub_match<_Bi_iter>& __rhs)
   1195     { return __rhs < __lhs; }
   1196 
   1197   /**
   1198    * @brief Tests the ordering of a string and a regular expression submatch.
   1199    * @param __lhs A string.
   1200    * @param __rhs A regular expression submatch.
   1201    * @returns true if @a __lhs does not precede @a __rhs, false otherwise.
   1202    */
   1203   template<typename _Bi_iter>
   1204     inline bool
   1205     operator>=(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
   1206 	       const sub_match<_Bi_iter>& __rhs)
   1207     { return !(__lhs < __rhs); }
   1208 
   1209   /**
   1210    * @brief Tests the ordering of a string and a regular expression submatch.
   1211    * @param __lhs A string.
   1212    * @param __rhs A regular expression submatch.
   1213    * @returns true if @a __lhs does not succeed @a __rhs, false otherwise.
   1214    */
   1215   template<typename _Bi_iter>
   1216     inline bool
   1217     operator<=(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
   1218 	       const sub_match<_Bi_iter>& __rhs)
   1219     { return !(__rhs < __lhs); }
   1220 
   1221   /**
   1222    * @brief Tests the equivalence of a regular expression submatch and a
   1223    *        string.
   1224    * @param __lhs A regular expression submatch.
   1225    * @param __rhs A pointer to a string?
   1226    * @returns true if @a __lhs  is equivalent to @a __rhs, false otherwise.
   1227    */
   1228   template<typename _Bi_iter>
   1229     inline bool
   1230     operator==(const sub_match<_Bi_iter>& __lhs,
   1231 	       typename iterator_traits<_Bi_iter>::value_type const* __rhs)
   1232     { return __lhs.compare(__rhs) == 0; }
   1233 
   1234   /**
   1235    * @brief Tests the inequivalence of a regular expression submatch and a
   1236    *        string.
   1237    * @param __lhs A regular expression submatch.
   1238    * @param __rhs A pointer to a string.
   1239    * @returns true if @a __lhs is not equivalent to @a __rhs, false otherwise.
   1240    */
   1241   template<typename _Bi_iter>
   1242     inline bool
   1243     operator!=(const sub_match<_Bi_iter>& __lhs,
   1244 	       typename iterator_traits<_Bi_iter>::value_type const* __rhs)
   1245     { return !(__lhs == __rhs); }
   1246 
   1247   /**
   1248    * @brief Tests the ordering of a regular expression submatch and a string.
   1249    * @param __lhs A regular expression submatch.
   1250    * @param __rhs A string.
   1251    * @returns true if @a __lhs precedes @a __rhs, false otherwise.
   1252    */
   1253   template<typename _Bi_iter>
   1254     inline bool
   1255     operator<(const sub_match<_Bi_iter>& __lhs,
   1256 	      typename iterator_traits<_Bi_iter>::value_type const* __rhs)
   1257     { return __lhs.compare(__rhs) < 0; }
   1258 
   1259   /**
   1260    * @brief Tests the ordering of a regular expression submatch and a string.
   1261    * @param __lhs A regular expression submatch.
   1262    * @param __rhs A string.
   1263    * @returns true if @a __lhs succeeds @a __rhs, false otherwise.
   1264    */
   1265   template<typename _Bi_iter>
   1266     inline bool
   1267     operator>(const sub_match<_Bi_iter>& __lhs,
   1268 	      typename iterator_traits<_Bi_iter>::value_type const* __rhs)
   1269     { return __rhs < __lhs; }
   1270 
   1271   /**
   1272    * @brief Tests the ordering of a regular expression submatch and a string.
   1273    * @param __lhs A regular expression submatch.
   1274    * @param __rhs A string.
   1275    * @returns true if @a __lhs does not precede @a __rhs, false otherwise.
   1276    */
   1277   template<typename _Bi_iter>
   1278     inline bool
   1279     operator>=(const sub_match<_Bi_iter>& __lhs,
   1280 	       typename iterator_traits<_Bi_iter>::value_type const* __rhs)
   1281     { return !(__lhs < __rhs); }
   1282 
   1283   /**
   1284    * @brief Tests the ordering of a regular expression submatch and a string.
   1285    * @param __lhs A regular expression submatch.
   1286    * @param __rhs A string.
   1287    * @returns true if @a __lhs does not succeed @a __rhs, false otherwise.
   1288    */
   1289   template<typename _Bi_iter>
   1290     inline bool
   1291     operator<=(const sub_match<_Bi_iter>& __lhs,
   1292 	       typename iterator_traits<_Bi_iter>::value_type const* __rhs)
   1293     { return !(__rhs < __lhs); }
   1294 
   1295   /**
   1296    * @brief Tests the equivalence of a string and a regular expression
   1297    *        submatch.
   1298    * @param __lhs A string.
   1299    * @param __rhs A regular expression submatch.
   1300    * @returns true if @a __lhs is equivalent to @a __rhs, false otherwise.
   1301    */
   1302   template<typename _Bi_iter>
   1303     inline bool
   1304     operator==(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
   1305 	       const sub_match<_Bi_iter>& __rhs)
   1306     {
   1307       typedef typename sub_match<_Bi_iter>::string_type string_type;
   1308       return __rhs.compare(string_type(1, __lhs)) == 0;
   1309     }
   1310 
   1311   /**
   1312    * @brief Tests the inequivalence of a string and a regular expression
   1313    *        submatch.
   1314    * @param __lhs A string.
   1315    * @param __rhs A regular expression submatch.
   1316    * @returns true if @a __lhs is not equivalent to @a __rhs, false otherwise.
   1317    */
   1318   template<typename _Bi_iter>
   1319     inline bool
   1320     operator!=(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
   1321 	       const sub_match<_Bi_iter>& __rhs)
   1322     { return !(__lhs == __rhs); }
   1323 
   1324   /**
   1325    * @brief Tests the ordering of a string and a regular expression submatch.
   1326    * @param __lhs A string.
   1327    * @param __rhs A regular expression submatch.
   1328    * @returns true if @a __lhs precedes @a __rhs, false otherwise.
   1329    */
   1330   template<typename _Bi_iter>
   1331     inline bool
   1332     operator<(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
   1333 	      const sub_match<_Bi_iter>& __rhs)
   1334     {
   1335       typedef typename sub_match<_Bi_iter>::string_type string_type;
   1336       return __rhs.compare(string_type(1, __lhs)) > 0;
   1337     }
   1338 
   1339   /**
   1340    * @brief Tests the ordering of a string and a regular expression submatch.
   1341    * @param __lhs A string.
   1342    * @param __rhs A regular expression submatch.
   1343    * @returns true if @a __lhs succeeds @a __rhs, false otherwise.
   1344    */
   1345   template<typename _Bi_iter>
   1346     inline bool
   1347     operator>(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
   1348 	      const sub_match<_Bi_iter>& __rhs)
   1349     { return __rhs < __lhs; }
   1350 
   1351   /**
   1352    * @brief Tests the ordering of a string and a regular expression submatch.
   1353    * @param __lhs A string.
   1354    * @param __rhs A regular expression submatch.
   1355    * @returns true if @a __lhs does not precede @a __rhs, false otherwise.
   1356    */
   1357   template<typename _Bi_iter>
   1358     inline bool
   1359     operator>=(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
   1360 	       const sub_match<_Bi_iter>& __rhs)
   1361     { return !(__lhs < __rhs); }
   1362 
   1363   /**
   1364    * @brief Tests the ordering of a string and a regular expression submatch.
   1365    * @param __lhs A string.
   1366    * @param __rhs A regular expression submatch.
   1367    * @returns true if @a __lhs does not succeed @a __rhs, false otherwise.
   1368    */
   1369   template<typename _Bi_iter>
   1370     inline bool
   1371     operator<=(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
   1372 	       const sub_match<_Bi_iter>& __rhs)
   1373     { return !(__rhs < __lhs); }
   1374 
   1375   /**
   1376    * @brief Tests the equivalence of a regular expression submatch and a
   1377    *        string.
   1378    * @param __lhs A regular expression submatch.
   1379    * @param __rhs A const string reference.
   1380    * @returns true if @a __lhs  is equivalent to @a __rhs, false otherwise.
   1381    */
   1382   template<typename _Bi_iter>
   1383     inline bool
   1384     operator==(const sub_match<_Bi_iter>& __lhs,
   1385 	       typename iterator_traits<_Bi_iter>::value_type const& __rhs)
   1386     {
   1387       typedef typename sub_match<_Bi_iter>::string_type string_type;
   1388       return __lhs.compare(string_type(1, __rhs)) == 0;
   1389     }
   1390 
   1391   /**
   1392    * @brief Tests the inequivalence of a regular expression submatch and a
   1393    *        string.
   1394    * @param __lhs A regular expression submatch.
   1395    * @param __rhs A const string reference.
   1396    * @returns true if @a __lhs is not equivalent to @a __rhs, false otherwise.
   1397    */
   1398   template<typename _Bi_iter>
   1399     inline bool
   1400     operator!=(const sub_match<_Bi_iter>& __lhs,
   1401 	       typename iterator_traits<_Bi_iter>::value_type const& __rhs)
   1402     { return !(__lhs == __rhs); }
   1403 
   1404   /**
   1405    * @brief Tests the ordering of a regular expression submatch and a string.
   1406    * @param __lhs A regular expression submatch.
   1407    * @param __rhs A const string reference.
   1408    * @returns true if @a __lhs precedes @a __rhs, false otherwise.
   1409    */
   1410   template<typename _Bi_iter>
   1411     inline bool
   1412     operator<(const sub_match<_Bi_iter>& __lhs,
   1413 	      typename iterator_traits<_Bi_iter>::value_type const& __rhs)
   1414     {
   1415       typedef typename sub_match<_Bi_iter>::string_type string_type;
   1416       return __lhs.compare(string_type(1, __rhs)) < 0;
   1417     }
   1418 
   1419   /**
   1420    * @brief Tests the ordering of a regular expression submatch and a string.
   1421    * @param __lhs A regular expression submatch.
   1422    * @param __rhs A const string reference.
   1423    * @returns true if @a __lhs succeeds @a __rhs, false otherwise.
   1424    */
   1425   template<typename _Bi_iter>
   1426     inline bool
   1427     operator>(const sub_match<_Bi_iter>& __lhs,
   1428 	      typename iterator_traits<_Bi_iter>::value_type const& __rhs)
   1429     { return __rhs < __lhs; }
   1430 
   1431   /**
   1432    * @brief Tests the ordering of a regular expression submatch and a string.
   1433    * @param __lhs A regular expression submatch.
   1434    * @param __rhs A const string reference.
   1435    * @returns true if @a __lhs does not precede @a __rhs, false otherwise.
   1436    */
   1437   template<typename _Bi_iter>
   1438     inline bool
   1439     operator>=(const sub_match<_Bi_iter>& __lhs,
   1440 	       typename iterator_traits<_Bi_iter>::value_type const& __rhs)
   1441     { return !(__lhs < __rhs); }
   1442 
   1443   /**
   1444    * @brief Tests the ordering of a regular expression submatch and a string.
   1445    * @param __lhs A regular expression submatch.
   1446    * @param __rhs A const string reference.
   1447    * @returns true if @a __lhs does not succeed @a __rhs, false otherwise.
   1448    */
   1449   template<typename _Bi_iter>
   1450     inline bool
   1451     operator<=(const sub_match<_Bi_iter>& __lhs,
   1452 	       typename iterator_traits<_Bi_iter>::value_type const& __rhs)
   1453     { return !(__rhs < __lhs); }
   1454 
   1455   /**
   1456    * @brief Inserts a matched string into an output stream.
   1457    *
   1458    * @param __os The output stream.
   1459    * @param __m  A submatch string.
   1460    *
   1461    * @returns the output stream with the submatch string inserted.
   1462    */
   1463   template<typename _Ch_type, typename _Ch_traits, typename _Bi_iter>
   1464     inline
   1465     basic_ostream<_Ch_type, _Ch_traits>&
   1466     operator<<(basic_ostream<_Ch_type, _Ch_traits>& __os,
   1467 	       const sub_match<_Bi_iter>& __m)
   1468     { return __os << __m.str(); }
   1469 
   1470   // [7.10] Class template match_results
   1471 
   1472   /*
   1473    * Special sub_match object representing an unmatched sub-expression.
   1474    */
   1475   template<typename _Bi_iter>
   1476     inline const sub_match<_Bi_iter>&
   1477     __unmatched_sub()
   1478     {
   1479       static const sub_match<_Bi_iter> __unmatched = sub_match<_Bi_iter>();
   1480       return __unmatched;
   1481     }
   1482 
   1483   /**
   1484    * @brief The results of a match or search operation.
   1485    *
   1486    * A collection of character sequences representing the result of a regular
   1487    * expression match.  Storage for the collection is allocated and freed as
   1488    * necessary by the member functions of class template match_results.
   1489    *
   1490    * This class satisfies the Sequence requirements, with the exception that
   1491    * only the operations defined for a const-qualified Sequence are supported.
   1492    *
   1493    * The sub_match object stored at index 0 represents sub-expression 0, i.e.
   1494    * the whole match. In this case the %sub_match member matched is always true.
   1495    * The sub_match object stored at index n denotes what matched the marked
   1496    * sub-expression n within the matched expression. If the sub-expression n
   1497    * participated in a regular expression match then the %sub_match member
   1498    * matched evaluates to true, and members first and second denote the range
   1499    * of characters [first, second) which formed that match. Otherwise matched
   1500    * is false, and members first and second point to the end of the sequence
   1501    * that was searched.
   1502    *
   1503    * @nosubgrouping
   1504    */
   1505   template<typename _Bi_iter,
   1506 	   typename _Alloc = allocator<sub_match<_Bi_iter> > >
   1507     class match_results
   1508     : private std::vector<sub_match<_Bi_iter>, _Alloc>
   1509     {
   1510     private:
   1511       /*
   1512        * The vector base is empty if this does not represent a successful match.
   1513        * Otherwise it contains n+3 elements where n is the number of marked
   1514        * sub-expressions:
   1515        * [0] entire match
   1516        * [1] 1st marked subexpression
   1517        * ...
   1518        * [n] nth marked subexpression
   1519        * [n+1] prefix
   1520        * [n+2] suffix
   1521        */
   1522       typedef std::vector<sub_match<_Bi_iter>, _Alloc>     _Base_type;
   1523       typedef std::iterator_traits<_Bi_iter>   	   	   __iter_traits;
   1524       typedef regex_constants::match_flag_type		   match_flag_type;
   1525 
   1526     public:
   1527       /**
   1528        * @name 10.? Public Types
   1529        */
   1530       //@{
   1531       typedef sub_match<_Bi_iter>                          value_type;
   1532       typedef const value_type&                            const_reference;
   1533       typedef const_reference                              reference;
   1534       typedef typename _Base_type::const_iterator          const_iterator;
   1535       typedef const_iterator                               iterator;
   1536       typedef typename __iter_traits::difference_type	   difference_type;
   1537       typedef typename allocator_traits<_Alloc>::size_type size_type;
   1538       typedef _Alloc                                       allocator_type;
   1539       typedef typename __iter_traits::value_type 	   char_type;
   1540       typedef std::basic_string<char_type>                 string_type;
   1541       //@}
   1542 
   1543     public:
   1544       /**
   1545        * @name 28.10.1 Construction, Copying, and Destruction
   1546        */
   1547       //@{
   1548 
   1549       /**
   1550        * @brief Constructs a default %match_results container.
   1551        * @post size() returns 0 and str() returns an empty string.
   1552        */
   1553       explicit
   1554       match_results(const _Alloc& __a = _Alloc())
   1555       : _Base_type(__a), _M_in_iterator(false)
   1556       { }
   1557 
   1558       /**
   1559        * @brief Copy constructs a %match_results.
   1560        */
   1561       match_results(const match_results& __rhs)
   1562       : _Base_type(__rhs), _M_in_iterator(false)
   1563       { }
   1564 
   1565       /**
   1566        * @brief Move constructs a %match_results.
   1567        */
   1568       match_results(match_results&& __rhs) noexcept
   1569       : _Base_type(std::move(__rhs)), _M_in_iterator(false)
   1570       { }
   1571 
   1572       /**
   1573        * @brief Assigns rhs to *this.
   1574        */
   1575       match_results&
   1576       operator=(const match_results& __rhs)
   1577       {
   1578 	match_results(__rhs).swap(*this);
   1579 	return *this;
   1580       }
   1581 
   1582       /**
   1583        * @brief Move-assigns rhs to *this.
   1584        */
   1585       match_results&
   1586       operator=(match_results&& __rhs)
   1587       {
   1588 	match_results(std::move(__rhs)).swap(*this);
   1589 	return *this;
   1590       }
   1591 
   1592       /**
   1593        * @brief Destroys a %match_results object.
   1594        */
   1595       ~match_results()
   1596       { }
   1597 
   1598       //@}
   1599 
   1600       // 28.10.2, state:
   1601       /**
   1602        * @brief Indicates if the %match_results is ready.
   1603        * @retval true   The object has a fully-established result state.
   1604        * @retval false  The object is not ready.
   1605        */
   1606       bool ready() const { return !_Base_type::empty(); }
   1607 
   1608       /**
   1609        * @name 28.10.2 Size
   1610        */
   1611       //@{
   1612 
   1613       /**
   1614        * @brief Gets the number of matches and submatches.
   1615        *
   1616        * The number of matches for a given regular expression will be either 0
   1617        * if there was no match or mark_count() + 1 if a match was successful.
   1618        * Some matches may be empty.
   1619        *
   1620        * @returns the number of matches found.
   1621        */
   1622       size_type
   1623       size() const
   1624       {
   1625       	size_type __size = _Base_type::size();
   1626       	return (__size && _Base_type::operator[](0).matched) ? __size - 2 : 0;
   1627       }
   1628 
   1629       size_type
   1630       max_size() const
   1631       { return _Base_type::max_size(); }
   1632 
   1633       /**
   1634        * @brief Indicates if the %match_results contains no results.
   1635        * @retval true The %match_results object is empty.
   1636        * @retval false The %match_results object is not empty.
   1637        */
   1638       bool
   1639       empty() const
   1640       { return size() == 0; }
   1641 
   1642       //@}
   1643 
   1644       /**
   1645        * @name 10.3 Element Access
   1646        */
   1647       //@{
   1648 
   1649       /**
   1650        * @brief Gets the length of the indicated submatch.
   1651        * @param __sub indicates the submatch.
   1652        * @pre   ready() == true
   1653        *
   1654        * This function returns the length of the indicated submatch, or the
   1655        * length of the entire match if @p __sub is zero (the default).
   1656        */
   1657       difference_type
   1658       length(size_type __sub = 0) const
   1659       { return (*this)[__sub].length(); }
   1660 
   1661       /**
   1662        * @brief Gets the offset of the beginning of the indicated submatch.
   1663        * @param __sub indicates the submatch.
   1664        * @pre   ready() == true
   1665        *
   1666        * This function returns the offset from the beginning of the target
   1667        * sequence to the beginning of the submatch, unless the value of @p __sub
   1668        * is zero (the default), in which case this function returns the offset
   1669        * from the beginning of the target sequence to the beginning of the
   1670        * match.
   1671        *
   1672        * Returns -1 if @p __sub is out of range.
   1673        */
   1674       difference_type
   1675       position(size_type __sub = 0) const
   1676       {
   1677 	// [28.12.1.4.5]
   1678 	if (_M_in_iterator)
   1679 	  return __sub < size() ? std::distance(_M_begin,
   1680 						(*this)[__sub].first) : -1;
   1681 	else
   1682 	  return __sub < size() ? std::distance(this->prefix().first,
   1683 						(*this)[__sub].first) : -1;
   1684       }
   1685 
   1686       /**
   1687        * @brief Gets the match or submatch converted to a string type.
   1688        * @param __sub indicates the submatch.
   1689        * @pre   ready() == true
   1690        *
   1691        * This function gets the submatch (or match, if @p __sub is
   1692        * zero) extracted from the target range and converted to the
   1693        * associated string type.
   1694        */
   1695       string_type
   1696       str(size_type __sub = 0) const
   1697       { return (*this)[__sub].str(); }
   1698 
   1699       /**
   1700        * @brief Gets a %sub_match reference for the match or submatch.
   1701        * @param __sub indicates the submatch.
   1702        * @pre   ready() == true
   1703        *
   1704        * This function gets a reference to the indicated submatch, or
   1705        * the entire match if @p __sub is zero.
   1706        *
   1707        * If @p __sub >= size() then this function returns a %sub_match with a
   1708        * special value indicating no submatch.
   1709        */
   1710       const_reference
   1711       operator[](size_type __sub) const
   1712       {
   1713       	_GLIBCXX_DEBUG_ASSERT( ready() );
   1714       	return __sub < size()
   1715 	       ?  _Base_type::operator[](__sub)
   1716 	       : __unmatched_sub<_Bi_iter>();
   1717       }
   1718 
   1719       /**
   1720        * @brief Gets a %sub_match representing the match prefix.
   1721        * @pre   ready() == true
   1722        *
   1723        * This function gets a reference to a %sub_match object representing the
   1724        * part of the target range between the start of the target range and the
   1725        * start of the match.
   1726        */
   1727       const_reference
   1728       prefix() const
   1729       {
   1730       	_GLIBCXX_DEBUG_ASSERT( ready() );
   1731       	return !empty()
   1732       	       ? _Base_type::operator[](_Base_type::size() - 2)
   1733 	       : __unmatched_sub<_Bi_iter>();
   1734       }
   1735 
   1736       /**
   1737        * @brief Gets a %sub_match representing the match suffix.
   1738        * @pre   ready() == true
   1739        *
   1740        * This function gets a reference to a %sub_match object representing the
   1741        * part of the target range between the end of the match and the end of
   1742        * the target range.
   1743        */
   1744       const_reference
   1745       suffix() const
   1746       {
   1747 	_GLIBCXX_DEBUG_ASSERT( ready() );
   1748 	return !empty()
   1749 	       ? _Base_type::operator[](_Base_type::size() - 1)
   1750 	       : __unmatched_sub<_Bi_iter>();
   1751       }
   1752 
   1753       /**
   1754        * @brief Gets an iterator to the start of the %sub_match collection.
   1755        */
   1756       const_iterator
   1757       begin() const
   1758       { return _Base_type::begin(); }
   1759 
   1760       /**
   1761        * @brief Gets an iterator to the start of the %sub_match collection.
   1762        */
   1763       const_iterator
   1764       cbegin() const
   1765       { return _Base_type::cbegin() + 2; }
   1766 
   1767       /**
   1768        * @brief Gets an iterator to one-past-the-end of the collection.
   1769        */
   1770       const_iterator
   1771       end() const
   1772       { return _Base_type::end() - 2; }
   1773 
   1774       /**
   1775        * @brief Gets an iterator to one-past-the-end of the collection.
   1776        */
   1777       const_iterator
   1778       cend() const
   1779       { return _Base_type::cend(); }
   1780 
   1781       //@}
   1782 
   1783       /**
   1784        * @name 10.4 Formatting
   1785        *
   1786        * These functions perform formatted substitution of the matched
   1787        * character sequences into their target.  The format specifiers and
   1788        * escape sequences accepted by these functions are determined by
   1789        * their @p flags parameter as documented above.
   1790        */
   1791        //@{
   1792 
   1793       /**
   1794        * @pre   ready() == true
   1795        */
   1796       template<typename _Out_iter>
   1797 	_Out_iter
   1798 	format(_Out_iter __out, const char_type* __fmt_first,
   1799 	       const char_type* __fmt_last,
   1800 	       match_flag_type __flags = regex_constants::format_default) const;
   1801 
   1802       /**
   1803        * @pre   ready() == true
   1804        */
   1805       template<typename _Out_iter, typename _St, typename _Sa>
   1806 	_Out_iter
   1807 	format(_Out_iter __out, const basic_string<char_type, _St, _Sa>& __fmt,
   1808 	       match_flag_type __flags = regex_constants::format_default) const
   1809 	{
   1810 	  return format(__out, __fmt.data(), __fmt.data() + __fmt.size(),
   1811 			__flags);
   1812 	}
   1813 
   1814       /**
   1815        * @pre   ready() == true
   1816        */
   1817       template<typename _Out_iter, typename _St, typename _Sa>
   1818 	basic_string<char_type, _St, _Sa>
   1819 	format(const basic_string<char_type, _St, _Sa>& __fmt,
   1820 	       match_flag_type __flags = regex_constants::format_default) const
   1821 	{
   1822 	  basic_string<char_type, _St, _Sa> __result;
   1823 	  format(std::back_inserter(__result), __fmt, __flags);
   1824 	  return __result;
   1825 	}
   1826 
   1827       /**
   1828        * @pre   ready() == true
   1829        */
   1830       string_type
   1831       format(const char_type* __fmt,
   1832 	     match_flag_type __flags = regex_constants::format_default) const
   1833       {
   1834 	string_type __result;
   1835 	format(std::back_inserter(__result),
   1836 	       __fmt,
   1837 	       __fmt + char_traits<char_type>::length(__fmt),
   1838 	       __flags);
   1839 	return __result;
   1840       }
   1841 
   1842       //@}
   1843 
   1844       /**
   1845        * @name 10.5 Allocator
   1846        */
   1847       //@{
   1848 
   1849       /**
   1850        * @brief Gets a copy of the allocator.
   1851        */
   1852       allocator_type
   1853       get_allocator() const
   1854       { return _Base_type::get_allocator(); }
   1855 
   1856       //@}
   1857 
   1858       /**
   1859        * @name 10.6 Swap
   1860        */
   1861        //@{
   1862 
   1863       /**
   1864        * @brief Swaps the contents of two match_results.
   1865        */
   1866       void
   1867       swap(match_results& __that)
   1868       { _Base_type::swap(__that); }
   1869       //@}
   1870 
   1871     private:
   1872       template<typename, typename, typename, bool>
   1873 	friend class __detail::_Executor;
   1874 
   1875       template<typename, typename, typename>
   1876 	friend class regex_iterator;
   1877 
   1878       template<typename _Bp, typename _Ap, typename _Cp, typename _Rp,
   1879 	__detail::_RegexExecutorPolicy, bool>
   1880 	friend bool
   1881 	__detail::__regex_algo_impl(_Bp, _Bp, match_results<_Bp, _Ap>&,
   1882 				    const basic_regex<_Cp, _Rp>&,
   1883 				    regex_constants::match_flag_type);
   1884 
   1885       _Bi_iter _M_begin;
   1886       bool     _M_in_iterator;
   1887     };
   1888 
   1889   typedef match_results<const char*>             cmatch;
   1890   typedef match_results<string::const_iterator>  smatch;
   1891 #ifdef _GLIBCXX_USE_WCHAR_T
   1892   typedef match_results<const wchar_t*>          wcmatch;
   1893   typedef match_results<wstring::const_iterator> wsmatch;
   1894 #endif
   1895 
   1896   // match_results comparisons
   1897   /**
   1898    * @brief Compares two match_results for equality.
   1899    * @returns true if the two objects refer to the same match,
   1900    * false otherwise.
   1901    */
   1902   template<typename _Bi_iter, typename _Alloc>
   1903     inline bool
   1904     operator==(const match_results<_Bi_iter, _Alloc>& __m1,
   1905 	       const match_results<_Bi_iter, _Alloc>& __m2)
   1906     {
   1907       if (__m1.ready() != __m2.ready())
   1908 	return false;
   1909       if (!__m1.ready())  // both are not ready
   1910 	return true;
   1911       if (__m1.empty() != __m2.empty())
   1912 	return false;
   1913       if (__m1.empty())   // both are empty
   1914 	return true;
   1915       return __m1.prefix() == __m2.prefix()
   1916 	&& __m1.size() == __m2.size()
   1917 	&& std::equal(__m1.begin(), __m1.end(), __m2.begin())
   1918 	&& __m1.suffix() == __m2.suffix();
   1919     }
   1920 
   1921   /**
   1922    * @brief Compares two match_results for inequality.
   1923    * @returns true if the two objects do not refer to the same match,
   1924    * false otherwise.
   1925    */
   1926   template<typename _Bi_iter, class _Alloc>
   1927     inline bool
   1928     operator!=(const match_results<_Bi_iter, _Alloc>& __m1,
   1929 	       const match_results<_Bi_iter, _Alloc>& __m2)
   1930     { return !(__m1 == __m2); }
   1931 
   1932   // [7.10.6] match_results swap
   1933   /**
   1934    * @brief Swaps two match results.
   1935    * @param __lhs A match result.
   1936    * @param __rhs A match result.
   1937    *
   1938    * The contents of the two match_results objects are swapped.
   1939    */
   1940   template<typename _Bi_iter, typename _Alloc>
   1941     inline void
   1942     swap(match_results<_Bi_iter, _Alloc>& __lhs,
   1943 	 match_results<_Bi_iter, _Alloc>& __rhs)
   1944     { __lhs.swap(__rhs); }
   1945 
   1946   // [7.11.2] Function template regex_match
   1947   /**
   1948    * @name Matching, Searching, and Replacing
   1949    */
   1950   //@{
   1951 
   1952   /**
   1953    * @brief Determines if there is a match between the regular expression @p e
   1954    * and all of the character sequence [first, last).
   1955    *
   1956    * @param __s     Start of the character sequence to match.
   1957    * @param __e     One-past-the-end of the character sequence to match.
   1958    * @param __m     The match results.
   1959    * @param __re    The regular expression.
   1960    * @param __flags Controls how the regular expression is matched.
   1961    *
   1962    * @retval true  A match exists.
   1963    * @retval false Otherwise.
   1964    *
   1965    * @throws an exception of type regex_error.
   1966    */
   1967   template<typename _Bi_iter, typename _Alloc,
   1968 	   typename _Ch_type, typename _Rx_traits>
   1969     inline bool
   1970     regex_match(_Bi_iter                                 __s,
   1971 		_Bi_iter                                 __e,
   1972 		match_results<_Bi_iter, _Alloc>&         __m,
   1973 		const basic_regex<_Ch_type, _Rx_traits>& __re,
   1974 		regex_constants::match_flag_type         __flags
   1975 			       = regex_constants::match_default)
   1976     {
   1977       return __detail::__regex_algo_impl<_Bi_iter, _Alloc, _Ch_type, _Rx_traits,
   1978 	__detail::_RegexExecutorPolicy::_S_auto, true>
   1979 	  (__s, __e, __m, __re, __flags);
   1980     }
   1981 
   1982   /**
   1983    * @brief Indicates if there is a match between the regular expression @p e
   1984    * and all of the character sequence [first, last).
   1985    *
   1986    * @param __first Beginning of the character sequence to match.
   1987    * @param __last  One-past-the-end of the character sequence to match.
   1988    * @param __re    The regular expression.
   1989    * @param __flags Controls how the regular expression is matched.
   1990    *
   1991    * @retval true  A match exists.
   1992    * @retval false Otherwise.
   1993    *
   1994    * @throws an exception of type regex_error.
   1995    */
   1996   template<typename _Bi_iter, typename _Ch_type, typename _Rx_traits>
   1997     inline bool
   1998     regex_match(_Bi_iter __first, _Bi_iter __last,
   1999 		const basic_regex<_Ch_type, _Rx_traits>& __re,
   2000 		regex_constants::match_flag_type __flags
   2001 		= regex_constants::match_default)
   2002     {
   2003       match_results<_Bi_iter> __what;
   2004       return regex_match(__first, __last, __what, __re, __flags);
   2005     }
   2006 
   2007   /**
   2008    * @brief Determines if there is a match between the regular expression @p e
   2009    * and a C-style null-terminated string.
   2010    *
   2011    * @param __s  The C-style null-terminated string to match.
   2012    * @param __m  The match results.
   2013    * @param __re The regular expression.
   2014    * @param __f  Controls how the regular expression is matched.
   2015    *
   2016    * @retval true  A match exists.
   2017    * @retval false Otherwise.
   2018    *
   2019    * @throws an exception of type regex_error.
   2020    */
   2021   template<typename _Ch_type, typename _Alloc, typename _Rx_traits>
   2022     inline bool
   2023     regex_match(const _Ch_type* __s,
   2024 		match_results<const _Ch_type*, _Alloc>& __m,
   2025 		const basic_regex<_Ch_type, _Rx_traits>& __re,
   2026 		regex_constants::match_flag_type __f
   2027 		= regex_constants::match_default)
   2028     { return regex_match(__s, __s + _Rx_traits::length(__s), __m, __re, __f); }
   2029 
   2030   /**
   2031    * @brief Determines if there is a match between the regular expression @p e
   2032    * and a string.
   2033    *
   2034    * @param __s     The string to match.
   2035    * @param __m     The match results.
   2036    * @param __re    The regular expression.
   2037    * @param __flags Controls how the regular expression is matched.
   2038    *
   2039    * @retval true  A match exists.
   2040    * @retval false Otherwise.
   2041    *
   2042    * @throws an exception of type regex_error.
   2043    */
   2044   template<typename _Ch_traits, typename _Ch_alloc,
   2045 	   typename _Alloc, typename _Ch_type, typename _Rx_traits>
   2046     inline bool
   2047     regex_match(const basic_string<_Ch_type, _Ch_traits, _Ch_alloc>& __s,
   2048 		match_results<typename basic_string<_Ch_type,
   2049 		_Ch_traits, _Ch_alloc>::const_iterator, _Alloc>& __m,
   2050 		const basic_regex<_Ch_type, _Rx_traits>& __re,
   2051 		regex_constants::match_flag_type __flags
   2052 		= regex_constants::match_default)
   2053     { return regex_match(__s.begin(), __s.end(), __m, __re, __flags); }
   2054 
   2055   /**
   2056    * @brief Indicates if there is a match between the regular expression @p e
   2057    * and a C-style null-terminated string.
   2058    *
   2059    * @param __s  The C-style null-terminated string to match.
   2060    * @param __re The regular expression.
   2061    * @param __f  Controls how the regular expression is matched.
   2062    *
   2063    * @retval true  A match exists.
   2064    * @retval false Otherwise.
   2065    *
   2066    * @throws an exception of type regex_error.
   2067    */
   2068   template<typename _Ch_type, class _Rx_traits>
   2069     inline bool
   2070     regex_match(const _Ch_type* __s,
   2071 		const basic_regex<_Ch_type, _Rx_traits>& __re,
   2072 		regex_constants::match_flag_type __f
   2073 		= regex_constants::match_default)
   2074     { return regex_match(__s, __s + _Rx_traits::length(__s), __re, __f); }
   2075 
   2076   /**
   2077    * @brief Indicates if there is a match between the regular expression @p e
   2078    * and a string.
   2079    *
   2080    * @param __s     [IN] The string to match.
   2081    * @param __re    [IN] The regular expression.
   2082    * @param __flags [IN] Controls how the regular expression is matched.
   2083    *
   2084    * @retval true  A match exists.
   2085    * @retval false Otherwise.
   2086    *
   2087    * @throws an exception of type regex_error.
   2088    */
   2089   template<typename _Ch_traits, typename _Str_allocator,
   2090 	   typename _Ch_type, typename _Rx_traits>
   2091     inline bool
   2092     regex_match(const basic_string<_Ch_type, _Ch_traits, _Str_allocator>& __s,
   2093 		const basic_regex<_Ch_type, _Rx_traits>& __re,
   2094 		regex_constants::match_flag_type __flags
   2095 		= regex_constants::match_default)
   2096     { return regex_match(__s.begin(), __s.end(), __re, __flags); }
   2097 
   2098   // [7.11.3] Function template regex_search
   2099   /**
   2100    * Searches for a regular expression within a range.
   2101    * @param __s     [IN]  The start of the string to search.
   2102    * @param __e     [IN]  One-past-the-end of the string to search.
   2103    * @param __m     [OUT] The match results.
   2104    * @param __re    [IN]  The regular expression to search for.
   2105    * @param __flags [IN]  Search policy flags.
   2106    * @retval true  A match was found within the string.
   2107    * @retval false No match was found within the string, the content of %m is
   2108    *               undefined.
   2109    *
   2110    * @throws an exception of type regex_error.
   2111    */
   2112   template<typename _Bi_iter, typename _Alloc,
   2113 	   typename _Ch_type, typename _Rx_traits>
   2114     inline bool
   2115     regex_search(_Bi_iter __s, _Bi_iter __e,
   2116 		 match_results<_Bi_iter, _Alloc>& __m,
   2117 		 const basic_regex<_Ch_type, _Rx_traits>& __re,
   2118 		 regex_constants::match_flag_type __flags
   2119 		 = regex_constants::match_default)
   2120     {
   2121       return __detail::__regex_algo_impl<_Bi_iter, _Alloc, _Ch_type, _Rx_traits,
   2122 	__detail::_RegexExecutorPolicy::_S_auto, false>
   2123 	  (__s, __e, __m, __re, __flags);
   2124     }
   2125 
   2126   /**
   2127    * Searches for a regular expression within a range.
   2128    * @param __first [IN]  The start of the string to search.
   2129    * @param __last  [IN]  One-past-the-end of the string to search.
   2130    * @param __re    [IN]  The regular expression to search for.
   2131    * @param __flags [IN]  Search policy flags.
   2132    * @retval true  A match was found within the string.
   2133    * @retval false No match was found within the string.
   2134    *
   2135    * @throws an exception of type regex_error.
   2136    */
   2137   template<typename _Bi_iter, typename _Ch_type, typename _Rx_traits>
   2138     inline bool
   2139     regex_search(_Bi_iter __first, _Bi_iter __last,
   2140 		 const basic_regex<_Ch_type, _Rx_traits>& __re,
   2141 		 regex_constants::match_flag_type __flags
   2142 		 = regex_constants::match_default)
   2143     {
   2144       match_results<_Bi_iter> __what;
   2145       return regex_search(__first, __last, __what, __re, __flags);
   2146     }
   2147 
   2148   /**
   2149    * @brief Searches for a regular expression within a C-string.
   2150    * @param __s [IN]  A C-string to search for the regex.
   2151    * @param __m [OUT] The set of regex matches.
   2152    * @param __e [IN]  The regex to search for in @p s.
   2153    * @param __f [IN]  The search flags.
   2154    * @retval true  A match was found within the string.
   2155    * @retval false No match was found within the string, the content of %m is
   2156    *               undefined.
   2157    *
   2158    * @throws an exception of type regex_error.
   2159    */
   2160   template<typename _Ch_type, class _Alloc, class _Rx_traits>
   2161     inline bool
   2162     regex_search(const _Ch_type* __s,
   2163 		 match_results<const _Ch_type*, _Alloc>& __m,
   2164 		 const basic_regex<_Ch_type, _Rx_traits>& __e,
   2165 		 regex_constants::match_flag_type __f
   2166 		 = regex_constants::match_default)
   2167     { return regex_search(__s, __s + _Rx_traits::length(__s), __m, __e, __f); }
   2168 
   2169   /**
   2170    * @brief Searches for a regular expression within a C-string.
   2171    * @param __s [IN]  The C-string to search.
   2172    * @param __e [IN]  The regular expression to search for.
   2173    * @param __f [IN]  Search policy flags.
   2174    * @retval true  A match was found within the string.
   2175    * @retval false No match was found within the string.
   2176    *
   2177    * @throws an exception of type regex_error.
   2178    */
   2179   template<typename _Ch_type, typename _Rx_traits>
   2180     inline bool
   2181     regex_search(const _Ch_type* __s,
   2182 		 const basic_regex<_Ch_type, _Rx_traits>& __e,
   2183 		 regex_constants::match_flag_type __f
   2184 		 = regex_constants::match_default)
   2185     { return regex_search(__s, __s + _Rx_traits::length(__s), __e, __f); }
   2186 
   2187   /**
   2188    * @brief Searches for a regular expression within a string.
   2189    * @param __s     [IN]  The string to search.
   2190    * @param __e     [IN]  The regular expression to search for.
   2191    * @param __flags [IN]  Search policy flags.
   2192    * @retval true  A match was found within the string.
   2193    * @retval false No match was found within the string.
   2194    *
   2195    * @throws an exception of type regex_error.
   2196    */
   2197   template<typename _Ch_traits, typename _String_allocator,
   2198 	   typename _Ch_type, typename _Rx_traits>
   2199     inline bool
   2200     regex_search(const basic_string<_Ch_type, _Ch_traits,
   2201 		 _String_allocator>& __s,
   2202 		 const basic_regex<_Ch_type, _Rx_traits>& __e,
   2203 		 regex_constants::match_flag_type __flags
   2204 		 = regex_constants::match_default)
   2205     { return regex_search(__s.begin(), __s.end(), __e, __flags); }
   2206 
   2207   /**
   2208    * @brief Searches for a regular expression within a string.
   2209    * @param __s [IN]  A C++ string to search for the regex.
   2210    * @param __m [OUT] The set of regex matches.
   2211    * @param __e [IN]  The regex to search for in @p s.
   2212    * @param __f [IN]  The search flags.
   2213    * @retval true  A match was found within the string.
   2214    * @retval false No match was found within the string, the content of %m is
   2215    *               undefined.
   2216    *
   2217    * @throws an exception of type regex_error.
   2218    */
   2219   template<typename _Ch_traits, typename _Ch_alloc,
   2220 	   typename _Alloc, typename _Ch_type,
   2221 	   typename _Rx_traits>
   2222     inline bool
   2223     regex_search(const basic_string<_Ch_type, _Ch_traits, _Ch_alloc>& __s,
   2224 		 match_results<typename basic_string<_Ch_type,
   2225 		 _Ch_traits, _Ch_alloc>::const_iterator, _Alloc>& __m,
   2226 		 const basic_regex<_Ch_type, _Rx_traits>& __e,
   2227 		 regex_constants::match_flag_type __f
   2228 		 = regex_constants::match_default)
   2229     { return regex_search(__s.begin(), __s.end(), __m, __e, __f); }
   2230 
   2231   // std [28.11.4] Function template regex_replace
   2232   /**
   2233    * @brief Search for a regular expression within a range for multiple times,
   2234    and replace the matched parts through filling a format string.
   2235    * @param __out   [OUT] The output iterator.
   2236    * @param __first [IN]  The start of the string to search.
   2237    * @param __last  [IN]  One-past-the-end of the string to search.
   2238    * @param __e     [IN]  The regular expression to search for.
   2239    * @param __fmt   [IN]  The format string.
   2240    * @param __flags [IN]  Search and replace policy flags.
   2241    *
   2242    * @returns __out
   2243    * @throws an exception of type regex_error.
   2244    */
   2245   template<typename _Out_iter, typename _Bi_iter,
   2246 	   typename _Rx_traits, typename _Ch_type,
   2247 	   typename _St, typename _Sa>
   2248     inline _Out_iter
   2249     regex_replace(_Out_iter __out, _Bi_iter __first, _Bi_iter __last,
   2250 		  const basic_regex<_Ch_type, _Rx_traits>& __e,
   2251 		  const basic_string<_Ch_type, _St, _Sa>& __fmt,
   2252 		  regex_constants::match_flag_type __flags
   2253 		  = regex_constants::match_default)
   2254     {
   2255       return regex_replace(__out, __first, __last, __e, __fmt.c_str(), __flags);
   2256     }
   2257 
   2258   /**
   2259    * @brief Search for a regular expression within a range for multiple times,
   2260    and replace the matched parts through filling a format C-string.
   2261    * @param __out   [OUT] The output iterator.
   2262    * @param __first [IN]  The start of the string to search.
   2263    * @param __last  [IN]  One-past-the-end of the string to search.
   2264    * @param __e     [IN]  The regular expression to search for.
   2265    * @param __fmt   [IN]  The format C-string.
   2266    * @param __flags [IN]  Search and replace policy flags.
   2267    *
   2268    * @returns __out
   2269    * @throws an exception of type regex_error.
   2270    */
   2271   template<typename _Out_iter, typename _Bi_iter,
   2272 	   typename _Rx_traits, typename _Ch_type>
   2273     _Out_iter
   2274     regex_replace(_Out_iter __out, _Bi_iter __first, _Bi_iter __last,
   2275 		  const basic_regex<_Ch_type, _Rx_traits>& __e,
   2276 		  const _Ch_type* __fmt,
   2277 		  regex_constants::match_flag_type __flags
   2278 		  = regex_constants::match_default);
   2279 
   2280   /**
   2281    * @brief Search for a regular expression within a string for multiple times,
   2282    and replace the matched parts through filling a format string.
   2283    * @param __s     [IN] The string to search and replace.
   2284    * @param __e     [IN] The regular expression to search for.
   2285    * @param __fmt   [IN] The format string.
   2286    * @param __flags [IN] Search and replace policy flags.
   2287    *
   2288    * @returns The string after replacing.
   2289    * @throws an exception of type regex_error.
   2290    */
   2291   template<typename _Rx_traits, typename _Ch_type,
   2292 	   typename _St, typename _Sa, typename _Fst, typename _Fsa>
   2293     inline basic_string<_Ch_type, _St, _Sa>
   2294     regex_replace(const basic_string<_Ch_type, _St, _Sa>& __s,
   2295 		  const basic_regex<_Ch_type, _Rx_traits>& __e,
   2296 		  const basic_string<_Ch_type, _Fst, _Fsa>& __fmt,
   2297 		  regex_constants::match_flag_type __flags
   2298 		  = regex_constants::match_default)
   2299     {
   2300       basic_string<_Ch_type, _St, _Sa> __result;
   2301       regex_replace(std::back_inserter(__result),
   2302 		    __s.begin(), __s.end(), __e, __fmt, __flags);
   2303       return __result;
   2304     }
   2305 
   2306   /**
   2307    * @brief Search for a regular expression within a string for multiple times,
   2308    and replace the matched parts through filling a format C-string.
   2309    * @param __s     [IN] The string to search and replace.
   2310    * @param __e     [IN] The regular expression to search for.
   2311    * @param __fmt   [IN] The format C-string.
   2312    * @param __flags [IN] Search and replace policy flags.
   2313    *
   2314    * @returns The string after replacing.
   2315    * @throws an exception of type regex_error.
   2316    */
   2317   template<typename _Rx_traits, typename _Ch_type,
   2318 	   typename _St, typename _Sa>
   2319     inline basic_string<_Ch_type, _St, _Sa>
   2320     regex_replace(const basic_string<_Ch_type, _St, _Sa>& __s,
   2321 		  const basic_regex<_Ch_type, _Rx_traits>& __e,
   2322 		  const _Ch_type* __fmt,
   2323 		  regex_constants::match_flag_type __flags
   2324 		  = regex_constants::match_default)
   2325     {
   2326       basic_string<_Ch_type, _St, _Sa> __result;
   2327       regex_replace(std::back_inserter(__result),
   2328 		    __s.begin(), __s.end(), __e, __fmt, __flags);
   2329       return __result;
   2330     }
   2331 
   2332   /**
   2333    * @brief Search for a regular expression within a C-string for multiple
   2334    times, and replace the matched parts through filling a format string.
   2335    * @param __s     [IN] The C-string to search and replace.
   2336    * @param __e     [IN] The regular expression to search for.
   2337    * @param __fmt   [IN] The format string.
   2338    * @param __flags [IN] Search and replace policy flags.
   2339    *
   2340    * @returns The string after replacing.
   2341    * @throws an exception of type regex_error.
   2342    */
   2343   template<typename _Rx_traits, typename _Ch_type,
   2344 	   typename _St, typename _Sa>
   2345     inline basic_string<_Ch_type>
   2346     regex_replace(const _Ch_type* __s,
   2347 		  const basic_regex<_Ch_type, _Rx_traits>& __e,
   2348 		  const basic_string<_Ch_type, _St, _Sa>& __fmt,
   2349 		  regex_constants::match_flag_type __flags
   2350 		  = regex_constants::match_default)
   2351     {
   2352       basic_string<_Ch_type> __result;
   2353       regex_replace(std::back_inserter(__result), __s,
   2354 		    __s + char_traits<_Ch_type>::length(__s),
   2355 		    __e, __fmt, __flags);
   2356       return __result;
   2357     }
   2358 
   2359   /**
   2360    * @brief Search for a regular expression within a C-string for multiple
   2361    times, and replace the matched parts through filling a format C-string.
   2362    * @param __s     [IN] The C-string to search and replace.
   2363    * @param __e     [IN] The regular expression to search for.
   2364    * @param __fmt   [IN] The format C-string.
   2365    * @param __flags [IN] Search and replace policy flags.
   2366    *
   2367    * @returns The string after replacing.
   2368    * @throws an exception of type regex_error.
   2369    */
   2370   template<typename _Rx_traits, typename _Ch_type>
   2371     inline basic_string<_Ch_type>
   2372     regex_replace(const _Ch_type* __s,
   2373 		  const basic_regex<_Ch_type, _Rx_traits>& __e,
   2374 		  const _Ch_type* __fmt,
   2375 		  regex_constants::match_flag_type __flags
   2376 		  = regex_constants::match_default)
   2377     {
   2378       basic_string<_Ch_type> __result;
   2379       regex_replace(std::back_inserter(__result), __s,
   2380 		    __s + char_traits<_Ch_type>::length(__s),
   2381 		    __e, __fmt, __flags);
   2382       return __result;
   2383     }
   2384 
   2385   //@}
   2386 
   2387   // std [28.12] Class template regex_iterator
   2388   /**
   2389    * An iterator adaptor that will provide repeated calls of regex_search over
   2390    * a range until no more matches remain.
   2391    */
   2392   template<typename _Bi_iter,
   2393 	   typename _Ch_type = typename iterator_traits<_Bi_iter>::value_type,
   2394 	   typename _Rx_traits = regex_traits<_Ch_type> >
   2395     class regex_iterator
   2396     {
   2397     public:
   2398       typedef basic_regex<_Ch_type, _Rx_traits>  regex_type;
   2399       typedef match_results<_Bi_iter>            value_type;
   2400       typedef std::ptrdiff_t                     difference_type;
   2401       typedef const value_type*                  pointer;
   2402       typedef const value_type&                  reference;
   2403       typedef std::forward_iterator_tag          iterator_category;
   2404 
   2405       /**
   2406        * @brief Provides a singular iterator, useful for indicating
   2407        * one-past-the-end of a range.
   2408        */
   2409       regex_iterator()
   2410       : _M_match()
   2411       { }
   2412 
   2413       /**
   2414        * Constructs a %regex_iterator...
   2415        * @param __a  [IN] The start of a text range to search.
   2416        * @param __b  [IN] One-past-the-end of the text range to search.
   2417        * @param __re [IN] The regular expression to match.
   2418        * @param __m  [IN] Policy flags for match rules.
   2419        */
   2420       regex_iterator(_Bi_iter __a, _Bi_iter __b, const regex_type& __re,
   2421 		     regex_constants::match_flag_type __m
   2422 		     = regex_constants::match_default)
   2423       : _M_begin(__a), _M_end(__b), _M_pregex(&__re), _M_flags(__m), _M_match()
   2424       {
   2425 	if (!regex_search(_M_begin, _M_end, _M_match, *_M_pregex, _M_flags))
   2426 	  *this = regex_iterator();
   2427       }
   2428 
   2429       /**
   2430        * Copy constructs a %regex_iterator.
   2431        */
   2432       regex_iterator(const regex_iterator& __rhs) = default;
   2433 
   2434       /**
   2435        * @brief Assigns one %regex_iterator to another.
   2436        */
   2437       regex_iterator&
   2438       operator=(const regex_iterator& __rhs) = default;
   2439 
   2440       /**
   2441        * @brief Tests the equivalence of two regex iterators.
   2442        */
   2443       bool
   2444       operator==(const regex_iterator& __rhs) const;
   2445 
   2446       /**
   2447        * @brief Tests the inequivalence of two regex iterators.
   2448        */
   2449       bool
   2450       operator!=(const regex_iterator& __rhs) const
   2451       { return !(*this == __rhs); }
   2452 
   2453       /**
   2454        * @brief Dereferences a %regex_iterator.
   2455        */
   2456       const value_type&
   2457       operator*() const
   2458       { return _M_match; }
   2459 
   2460       /**
   2461        * @brief Selects a %regex_iterator member.
   2462        */
   2463       const value_type*
   2464       operator->() const
   2465       { return &_M_match; }
   2466 
   2467       /**
   2468        * @brief Increments a %regex_iterator.
   2469        */
   2470       regex_iterator&
   2471       operator++();
   2472 
   2473       /**
   2474        * @brief Postincrements a %regex_iterator.
   2475        */
   2476       regex_iterator
   2477       operator++(int)
   2478       {
   2479 	auto __tmp = *this;
   2480 	++(*this);
   2481 	return __tmp;
   2482       }
   2483 
   2484     private:
   2485       _Bi_iter                         _M_begin;
   2486       _Bi_iter                         _M_end;
   2487       const regex_type*                _M_pregex;
   2488       regex_constants::match_flag_type _M_flags;
   2489       match_results<_Bi_iter>          _M_match;
   2490     };
   2491 
   2492   typedef regex_iterator<const char*>             cregex_iterator;
   2493   typedef regex_iterator<string::const_iterator>  sregex_iterator;
   2494 #ifdef _GLIBCXX_USE_WCHAR_T
   2495   typedef regex_iterator<const wchar_t*>          wcregex_iterator;
   2496   typedef regex_iterator<wstring::const_iterator> wsregex_iterator;
   2497 #endif
   2498 
   2499   // [7.12.2] Class template regex_token_iterator
   2500   /**
   2501    * Iterates over submatches in a range (or @a splits a text string).
   2502    *
   2503    * The purpose of this iterator is to enumerate all, or all specified,
   2504    * matches of a regular expression within a text range.  The dereferenced
   2505    * value of an iterator of this class is a std::sub_match object.
   2506    */
   2507   template<typename _Bi_iter,
   2508 	   typename _Ch_type = typename iterator_traits<_Bi_iter>::value_type,
   2509 	   typename _Rx_traits = regex_traits<_Ch_type> >
   2510     class regex_token_iterator
   2511     {
   2512     public:
   2513       typedef basic_regex<_Ch_type, _Rx_traits> regex_type;
   2514       typedef sub_match<_Bi_iter>               value_type;
   2515       typedef std::ptrdiff_t                    difference_type;
   2516       typedef const value_type*                 pointer;
   2517       typedef const value_type&                 reference;
   2518       typedef std::forward_iterator_tag         iterator_category;
   2519 
   2520     public:
   2521       /**
   2522        * @brief Default constructs a %regex_token_iterator.
   2523        *
   2524        * A default-constructed %regex_token_iterator is a singular iterator
   2525        * that will compare equal to the one-past-the-end value for any
   2526        * iterator of the same type.
   2527        */
   2528       regex_token_iterator()
   2529       : _M_position(), _M_subs(), _M_suffix(), _M_n(0), _M_result(nullptr),
   2530       _M_has_m1(false)
   2531       { }
   2532 
   2533       /**
   2534        * Constructs a %regex_token_iterator...
   2535        * @param __a          [IN] The start of the text to search.
   2536        * @param __b          [IN] One-past-the-end of the text to search.
   2537        * @param __re         [IN] The regular expression to search for.
   2538        * @param __submatch   [IN] Which submatch to return.  There are some
   2539        *                        special values for this parameter:
   2540        *                        - -1 each enumerated subexpression does NOT
   2541        *                          match the regular expression (aka field
   2542        *                          splitting)
   2543        *                        - 0 the entire string matching the
   2544        *                          subexpression is returned for each match
   2545        *                          within the text.
   2546        *                        - >0 enumerates only the indicated
   2547        *                          subexpression from a match within the text.
   2548        * @param __m          [IN] Policy flags for match rules.
   2549        */
   2550       regex_token_iterator(_Bi_iter __a, _Bi_iter __b, const regex_type& __re,
   2551 			   int __submatch = 0,
   2552 			   regex_constants::match_flag_type __m
   2553 			   = regex_constants::match_default)
   2554       : _M_position(__a, __b, __re, __m), _M_subs(1, __submatch), _M_n(0)
   2555       { _M_init(__a, __b); }
   2556 
   2557       /**
   2558        * Constructs a %regex_token_iterator...
   2559        * @param __a          [IN] The start of the text to search.
   2560        * @param __b          [IN] One-past-the-end of the text to search.
   2561        * @param __re         [IN] The regular expression to search for.
   2562        * @param __submatches [IN] A list of subexpressions to return for each
   2563        *                          regular expression match within the text.
   2564        * @param __m          [IN] Policy flags for match rules.
   2565        */
   2566       regex_token_iterator(_Bi_iter __a, _Bi_iter __b,
   2567 			   const regex_type& __re,
   2568 			   const std::vector<int>& __submatches,
   2569 			   regex_constants::match_flag_type __m
   2570 			     = regex_constants::match_default)
   2571       : _M_position(__a, __b, __re, __m), _M_subs(__submatches), _M_n(0)
   2572       { _M_init(__a, __b); }
   2573 
   2574       /**
   2575        * Constructs a %regex_token_iterator...
   2576        * @param __a          [IN] The start of the text to search.
   2577        * @param __b          [IN] One-past-the-end of the text to search.
   2578        * @param __re         [IN] The regular expression to search for.
   2579        * @param __submatches [IN] A list of subexpressions to return for each
   2580        *                          regular expression match within the text.
   2581        * @param __m          [IN] Policy flags for match rules.
   2582        */
   2583       regex_token_iterator(_Bi_iter __a, _Bi_iter __b,
   2584 			   const regex_type& __re,
   2585 			   initializer_list<int> __submatches,
   2586 			   regex_constants::match_flag_type __m
   2587 			     = regex_constants::match_default)
   2588       : _M_position(__a, __b, __re, __m), _M_subs(__submatches), _M_n(0)
   2589       { _M_init(__a, __b); }
   2590 
   2591       /**
   2592        * Constructs a %regex_token_iterator...
   2593        * @param __a          [IN] The start of the text to search.
   2594        * @param __b          [IN] One-past-the-end of the text to search.
   2595        * @param __re         [IN] The regular expression to search for.
   2596        * @param __submatches [IN] A list of subexpressions to return for each
   2597        *                          regular expression match within the text.
   2598        * @param __m          [IN] Policy flags for match rules.
   2599        */
   2600       template<std::size_t _Nm>
   2601 	regex_token_iterator(_Bi_iter __a, _Bi_iter __b,
   2602 			     const regex_type& __re,
   2603 			     const int (&__submatches)[_Nm],
   2604 			     regex_constants::match_flag_type __m
   2605 			     = regex_constants::match_default)
   2606       : _M_position(__a, __b, __re, __m),
   2607       _M_subs(__submatches, *(&__submatches+1)), _M_n(0)
   2608       { _M_init(__a, __b); }
   2609 
   2610       /**
   2611        * @brief Copy constructs a %regex_token_iterator.
   2612        * @param __rhs [IN] A %regex_token_iterator to copy.
   2613        */
   2614       regex_token_iterator(const regex_token_iterator& __rhs)
   2615       : _M_position(__rhs._M_position), _M_subs(__rhs._M_subs),
   2616       _M_suffix(__rhs._M_suffix), _M_n(__rhs._M_n), _M_result(__rhs._M_result),
   2617       _M_has_m1(__rhs._M_has_m1)
   2618       {
   2619 	if (__rhs._M_result == &__rhs._M_suffix)
   2620 	  _M_result = &_M_suffix;
   2621       }
   2622 
   2623       /**
   2624        * @brief Assigns a %regex_token_iterator to another.
   2625        * @param __rhs [IN] A %regex_token_iterator to copy.
   2626        */
   2627       regex_token_iterator&
   2628       operator=(const regex_token_iterator& __rhs);
   2629 
   2630       /**
   2631        * @brief Compares a %regex_token_iterator to another for equality.
   2632        */
   2633       bool
   2634       operator==(const regex_token_iterator& __rhs) const;
   2635 
   2636       /**
   2637        * @brief Compares a %regex_token_iterator to another for inequality.
   2638        */
   2639       bool
   2640       operator!=(const regex_token_iterator& __rhs) const
   2641       { return !(*this == __rhs); }
   2642 
   2643       /**
   2644        * @brief Dereferences a %regex_token_iterator.
   2645        */
   2646       const value_type&
   2647       operator*() const
   2648       { return *_M_result; }
   2649 
   2650       /**
   2651        * @brief Selects a %regex_token_iterator member.
   2652        */
   2653       const value_type*
   2654       operator->() const
   2655       { return _M_result; }
   2656 
   2657       /**
   2658        * @brief Increments a %regex_token_iterator.
   2659        */
   2660       regex_token_iterator&
   2661       operator++();
   2662 
   2663       /**
   2664        * @brief Postincrements a %regex_token_iterator.
   2665        */
   2666       regex_token_iterator
   2667       operator++(int)
   2668       {
   2669 	auto __tmp = *this;
   2670 	++(*this);
   2671 	return __tmp;
   2672       }
   2673 
   2674     private:
   2675       typedef regex_iterator<_Bi_iter, _Ch_type, _Rx_traits> _Position;
   2676 
   2677       void
   2678       _M_init(_Bi_iter __a, _Bi_iter __b);
   2679 
   2680       const value_type&
   2681       _M_current_match() const
   2682       {
   2683 	if (_M_subs[_M_n] == -1)
   2684 	  return (*_M_position).prefix();
   2685 	else
   2686 	  return (*_M_position)[_M_subs[_M_n]];
   2687       }
   2688 
   2689       constexpr bool
   2690       _M_end_of_seq()
   2691       { return _M_result == nullptr; }
   2692 
   2693       _Position         _M_position;
   2694       std::vector<int>  _M_subs;
   2695       value_type        _M_suffix;
   2696       std::size_t       _M_n;
   2697       const value_type* _M_result;
   2698 
   2699       // Show whether _M_subs contains -1
   2700       bool              _M_has_m1;
   2701     };
   2702 
   2703   /** @brief Token iterator for C-style NULL-terminated strings. */
   2704   typedef regex_token_iterator<const char*>             cregex_token_iterator;
   2705 
   2706   /** @brief Token iterator for standard strings. */
   2707   typedef regex_token_iterator<string::const_iterator>  sregex_token_iterator;
   2708 
   2709 #ifdef _GLIBCXX_USE_WCHAR_T
   2710   /** @brief Token iterator for C-style NULL-terminated wide strings. */
   2711   typedef regex_token_iterator<const wchar_t*>          wcregex_token_iterator;
   2712 
   2713   /** @brief Token iterator for standard wide-character strings. */
   2714   typedef regex_token_iterator<wstring::const_iterator> wsregex_token_iterator;
   2715 #endif
   2716 
   2717   //@} // group regex
   2718 _GLIBCXX_END_NAMESPACE_VERSION
   2719 } // namespace
   2720 
   2721 #include <bits/regex.tcc>
   2722