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