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