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