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