libstdc++

regex.h

Go to the documentation of this file.
00001 // class template regex -*- C++ -*-
00002 
00003 // Copyright (C) 2010, 2011 Free Software Foundation, Inc.
00004 //
00005 // This file is part of the GNU ISO C++ Library.  This library is free
00006 // software; you can redistribute it and/or modify it under the
00007 // terms of the GNU General Public License as published by the
00008 // Free Software Foundation; either version 3, or (at your option)
00009 // any later version.
00010 
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 // GNU General Public License for more details.
00015 
00016 // Under Section 7 of GPL version 3, you are granted additional
00017 // permissions described in the GCC Runtime Library Exception, version
00018 // 3.1, as published by the Free Software Foundation.
00019 
00020 // You should have received a copy of the GNU General Public License and
00021 // a copy of the GCC Runtime Library Exception along with this program;
00022 // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
00023 // <http://www.gnu.org/licenses/>.
00024 
00025 /**
00026  *  @file bits/regex.h
00027  *  This is an internal header file, included by other library headers.
00028  *  Do not attempt to use it directly. @headername{regex}
00029  */
00030 
00031 namespace std _GLIBCXX_VISIBILITY(default)
00032 {
00033 _GLIBCXX_BEGIN_NAMESPACE_VERSION
00034 
00035 /**
00036  * @defgroup regex Regular Expressions
00037  * A facility for performing regular expression pattern matching.
00038  */
00039  //@{
00040 
00041   // [7.7] Class regex_traits
00042   /**
00043    * @brief Describes aspects of a regular expression.
00044    *
00045    * A regular expression traits class that satisfies the requirements of 
00046    * section [28.7].
00047    *
00048    * The class %regex is parameterized around a set of related types and
00049    * functions used to complete the definition of its semantics.  This class
00050    * satisfies the requirements of such a traits class.
00051    */
00052   template<typename _Ch_type>
00053     struct regex_traits
00054     {
00055     public:
00056       typedef _Ch_type                     char_type;
00057       typedef std::basic_string<char_type> string_type;
00058       typedef std::locale                  locale_type;
00059       typedef std::ctype_base::mask        char_class_type;
00060 
00061     public:
00062       /**
00063        * @brief Constructs a default traits object.
00064        */
00065       regex_traits()
00066       { }
00067       
00068       /**
00069        * @brief Gives the length of a C-style string starting at @p __p.
00070        *
00071        * @param __p a pointer to the start of a character sequence.
00072        *
00073        * @returns the number of characters between @p *__p and the first
00074        * default-initialized value of type @p char_type.  In other words, uses
00075        * the C-string algorithm for determining the length of a sequence of
00076        * characters.
00077        */
00078       static std::size_t
00079       length(const char_type* __p)
00080       { return string_type::traits_type::length(__p); }
00081 
00082       /**
00083        * @brief Performs the identity translation.
00084        *
00085        * @param c A character to the locale-specific character set.
00086        *
00087        * @returns c.
00088        */
00089       char_type
00090       translate(char_type __c) const
00091       { return __c; }
00092       
00093       /**
00094        * @brief Translates a character into a case-insensitive equivalent.
00095        *
00096        * @param c A character to the locale-specific character set.
00097        *
00098        * @returns the locale-specific lower-case equivalent of c.
00099        * @throws std::bad_cast if the imbued locale does not support the ctype
00100        *         facet.
00101        */
00102       char_type
00103       translate_nocase(char_type __c) const
00104       {
00105     using std::ctype;
00106     using std::use_facet;
00107     return use_facet<ctype<char_type> >(_M_locale).tolower(__c);
00108       }
00109       
00110       /**
00111        * @brief Gets a sort key for a character sequence.
00112        *
00113        * @param first beginning of the character sequence.
00114        * @param last  one-past-the-end of the character sequence.
00115        *
00116        * Returns a sort key for the character sequence designated by the
00117        * iterator range [F1, F2) such that if the character sequence [G1, G2)
00118        * sorts before the character sequence [H1, H2) then
00119        * v.transform(G1, G2) < v.transform(H1, H2).
00120        *
00121        * What this really does is provide a more efficient way to compare a
00122        * string to multiple other strings in locales with fancy collation
00123        * rules and equivalence classes.
00124        *
00125        * @returns a locale-specific sort key equivalent to the input range.
00126        *
00127        * @throws std::bad_cast if the current locale does not have a collate
00128        *         facet.
00129        */
00130       template<typename _Fwd_iter>
00131         string_type
00132         transform(_Fwd_iter __first, _Fwd_iter __last) const
00133         {
00134       using std::collate;
00135       using std::use_facet;
00136       const collate<_Ch_type>& __c(use_facet<
00137                        collate<_Ch_type> >(_M_locale));
00138       string_type __s(__first, __last);
00139       return __c.transform(__s.data(), __s.data() + __s.size());
00140     }
00141 
00142       /**
00143        * @brief Gets a sort key for a character sequence, independant of case.
00144        *
00145        * @param first beginning of the character sequence.
00146        * @param last  one-past-the-end of the character sequence.
00147        *
00148        * Effects: if typeid(use_facet<collate<_Ch_type> >) ==
00149        * typeid(collate_byname<_Ch_type>) and the form of the sort key
00150        * returned by collate_byname<_Ch_type>::transform(first, last) is known
00151        * and can be converted into a primary sort key then returns that key,
00152        * otherwise returns an empty string.
00153        *
00154        * @todo Implement this function.
00155        */
00156       template<typename _Fwd_iter>
00157         string_type
00158         transform_primary(_Fwd_iter __first, _Fwd_iter __last) const
00159         { return string_type(); }
00160 
00161       /**
00162        * @brief Gets a collation element by name.
00163        *
00164        * @param first beginning of the collation element name.
00165        * @param last  one-past-the-end of the collation element name.
00166        * 
00167        * @returns a sequence of one or more characters that represents the
00168        * collating element consisting of the character sequence designated by
00169        * the iterator range [first, last). Returns an empty string if the
00170        * character sequence is not a valid collating element.
00171        *
00172        * @todo Implement this function.
00173        */
00174       template<typename _Fwd_iter>
00175         string_type
00176         lookup_collatename(_Fwd_iter __first, _Fwd_iter __last) const
00177         { return string_type(); }
00178 
00179       /**
00180        * @brief Maps one or more characters to a named character
00181        *        classification.
00182        *
00183        * @param first beginning of the character sequence.
00184        * @param last  one-past-the-end of the character sequence.
00185        * @param icase ignores the case of the classification name.
00186        *
00187        * @returns an unspecified value that represents the character
00188        * classification named by the character sequence designated by the
00189        * iterator range [first, last). If @p icase is true, the returned mask
00190        * identifies the classification regardless of the case of the characters
00191        * to be matched (for example, [[:lower:]] is the same as [[:alpha:]]),
00192        * otherwise a case-dependant classification is returned.  The value
00193        * returned shall be independent of the case of the characters in the
00194        * character sequence. If the name is not recognized then returns a value
00195        * that compares equal to 0.
00196        *
00197        * At least the following names (or their wide-character equivalent) are
00198        * supported.
00199        * - d
00200        * - w
00201        * - s
00202        * - alnum
00203        * - alpha
00204        * - blank
00205        * - cntrl
00206        * - digit
00207        * - graph
00208        * - lower
00209        * - print
00210        * - punct
00211        * - space
00212        * - upper
00213        * - xdigit
00214        *
00215        * @todo Implement this function.
00216        */
00217       template<typename _Fwd_iter>
00218         char_class_type
00219         lookup_classname(_Fwd_iter __first, _Fwd_iter __last,
00220                      bool __icase = false) const
00221     { return 0; }
00222 
00223       /**
00224        * @brief Determines if @p c is a member of an identified class.
00225        *
00226        * @param c a character.
00227        * @param f a class type (as returned from lookup_classname).
00228        *
00229        * @returns true if the character @p c is a member of the classification
00230        * represented by @p f, false otherwise.
00231        *
00232        * @throws std::bad_cast if the current locale does not have a ctype
00233        *         facet.
00234        */
00235       bool
00236       isctype(_Ch_type __c, char_class_type __f) const;
00237 
00238       /**
00239        * @brief Converts a digit to an int.
00240        *
00241        * @param ch    a character representing a digit.
00242        * @param radix the radix if the numeric conversion (limited to 8, 10,
00243        *              or 16).
00244        * 
00245        * @returns the value represented by the digit ch in base radix if the
00246        * character ch is a valid digit in base radix; otherwise returns -1.
00247        */
00248       int
00249       value(_Ch_type __ch, int __radix) const;
00250       
00251       /**
00252        * @brief Imbues the regex_traits object with a copy of a new locale.
00253        *
00254        * @param loc A locale.
00255        *
00256        * @returns a copy of the previous locale in use by the regex_traits
00257        *          object.
00258        *
00259        * @note Calling imbue with a different locale than the one currently in
00260        *       use invalidates all cached data held by *this.
00261        */
00262       locale_type
00263       imbue(locale_type __loc)
00264       {
00265     std::swap(_M_locale, __loc);
00266     return __loc;
00267       }
00268       
00269       /**
00270        * @brief Gets a copy of the current locale in use by the regex_traits
00271        * object.
00272        */
00273       locale_type
00274       getloc() const
00275       { return _M_locale; }
00276       
00277     protected:
00278       locale_type _M_locale;
00279     };
00280 
00281   template<typename _Ch_type>
00282     bool
00283     regex_traits<_Ch_type>::
00284     isctype(_Ch_type __c, char_class_type __f) const
00285     {
00286       using std::ctype;
00287       using std::use_facet;
00288       const ctype<_Ch_type>& __ctype(use_facet<
00289                      ctype<_Ch_type> >(_M_locale));
00290       
00291       if (__ctype.is(__f, __c))
00292     return true;
00293       
00294       // special case of underscore in [[:w:]]
00295       if (__c == __ctype.widen('_'))
00296     {
00297       const char __wb[] = "w";
00298       char_class_type __wt = this->lookup_classname(__wb,
00299                             __wb + sizeof(__wb));
00300       if (__f | __wt)
00301         return true;
00302     }
00303     
00304       // special case of [[:space:]] in [[:blank:]]
00305       if (__ctype.is(std::ctype_base::space, __c))
00306     {
00307       const char __bb[] = "blank";
00308       char_class_type __bt = this->lookup_classname(__bb,
00309                             __bb + sizeof(__bb));
00310       if (__f | __bt)
00311         return true;
00312     }
00313       
00314       return false;
00315     }
00316 
00317   template<typename _Ch_type>
00318     int
00319     regex_traits<_Ch_type>::
00320     value(_Ch_type __ch, int __radix) const
00321     {
00322       std::basic_istringstream<_Ch_type> __is(string_type(1, __ch));
00323       int __v;
00324       if (__radix == 8)
00325     __is >> std::oct;
00326       else if (__radix == 16)
00327     __is >> std::hex;
00328       __is >> __v;
00329       return __is.fail() ? -1 : __v;
00330     }
00331 
00332   // [7.8] Class basic_regex
00333   /**
00334    * Objects of specializations of this class represent regular expressions
00335    * constructed from sequences of character type @p _Ch_type.
00336    *
00337    * Storage for the regular expression is allocated and deallocated as
00338    * necessary by the member functions of this class.
00339    */
00340   template<typename _Ch_type, typename _Rx_traits = regex_traits<_Ch_type> >
00341     class basic_regex
00342     {
00343     public:
00344       // types:
00345       typedef _Ch_type                            value_type;
00346       typedef _Rx_traits                          traits_type;
00347       typedef typename traits_type::string_type   string_type;
00348       typedef regex_constants::syntax_option_type flag_type;
00349       typedef typename traits_type::locale_type   locale_type;
00350 
00351       /**
00352        * @name Constants
00353        * std [28.8.1](1)
00354        */
00355       //@{
00356       static constexpr regex_constants::syntax_option_type icase
00357         = regex_constants::icase;
00358       static constexpr regex_constants::syntax_option_type nosubs
00359         = regex_constants::nosubs;
00360       static constexpr regex_constants::syntax_option_type optimize
00361         = regex_constants::optimize;
00362       static constexpr regex_constants::syntax_option_type collate
00363         = regex_constants::collate;
00364       static constexpr regex_constants::syntax_option_type ECMAScript
00365         = regex_constants::ECMAScript;
00366       static constexpr regex_constants::syntax_option_type basic
00367         = regex_constants::basic;
00368       static constexpr regex_constants::syntax_option_type extended
00369         = regex_constants::extended;
00370       static constexpr regex_constants::syntax_option_type awk
00371         = regex_constants::awk;
00372       static constexpr regex_constants::syntax_option_type grep
00373         = regex_constants::grep;
00374       static constexpr regex_constants::syntax_option_type egrep
00375         = regex_constants::egrep;
00376       //@}
00377 
00378       // [7.8.2] construct/copy/destroy
00379       /**
00380        * Constructs a basic regular expression that does not match any
00381        * character sequence.
00382        */
00383       basic_regex()
00384       : _M_flags(regex_constants::ECMAScript),
00385         _M_automaton(__regex::__compile<const _Ch_type*, _Rx_traits>(0, 0,
00386                      _M_traits, _M_flags))
00387       { }
00388 
00389       /**
00390        * @brief Constructs a basic regular expression from the sequence
00391        * [p, p + char_traits<_Ch_type>::length(p)) interpreted according to the
00392        * flags in @p f.
00393        *
00394        * @param p A pointer to the start of a C-style null-terminated string
00395        *          containing a regular expression.
00396        * @param f Flags indicating the syntax rules and options.
00397        *
00398        * @throws regex_error if @p p is not a valid regular expression.
00399        */
00400       explicit
00401       basic_regex(const _Ch_type* __p,
00402           flag_type __f = regex_constants::ECMAScript)
00403       : _M_flags(__f),
00404         _M_automaton(__regex::__compile(__p, __p + _Rx_traits::length(__p),
00405                         _M_traits, _M_flags))
00406       { }
00407 
00408       /**
00409        * @brief Constructs a basic regular expression from the sequence
00410        * [p, p + len) interpreted according to the flags in @p f.
00411        *
00412        * @param p   A pointer to the start of a string containing a regular
00413        *            expression.
00414        * @param len The length of the string containing the regular expression.
00415        * @param f   Flags indicating the syntax rules and options.
00416        *
00417        * @throws regex_error if @p p is not a valid regular expression.
00418        */
00419       basic_regex(const _Ch_type* __p, std::size_t __len, flag_type __f)
00420       : _M_flags(__f),
00421         _M_automaton(__regex::__compile(__p, __p + __len, _M_traits, _M_flags))
00422       { }
00423 
00424       /**
00425        * @brief Copy-constructs a basic regular expression.
00426        *
00427        * @param rhs A @p regex object.
00428        */
00429       basic_regex(const basic_regex& __rhs)
00430       : _M_flags(__rhs._M_flags), _M_traits(__rhs._M_traits),
00431         _M_automaton(__rhs._M_automaton)
00432       { }
00433 
00434       /**
00435        * @brief Move-constructs a basic regular expression.
00436        *
00437        * @param rhs A @p regex object.
00438        */
00439       basic_regex(const basic_regex&& __rhs) noexcept
00440       : _M_flags(__rhs._M_flags), _M_traits(__rhs._M_traits),
00441         _M_automaton(std::move(__rhs._M_automaton))
00442       { }
00443 
00444       /**
00445        * @brief Constructs a basic regular expression from the string
00446        * @p s interpreted according to the flags in @p f.
00447        *
00448        * @param s A string containing a regular expression.
00449        * @param f Flags indicating the syntax rules and options.
00450        *
00451        * @throws regex_error if @p s is not a valid regular expression.
00452        */
00453       template<typename _Ch_traits, typename _Ch_alloc>
00454         explicit
00455         basic_regex(const std::basic_string<_Ch_type, _Ch_traits,
00456             _Ch_alloc>& __s,
00457             flag_type __f = regex_constants::ECMAScript)
00458     : _M_flags(__f),
00459       _M_automaton(__regex::__compile(__s.begin(), __s.end(),
00460                       _M_traits, _M_flags))
00461         { }
00462 
00463       /**
00464        * @brief Constructs a basic regular expression from the range
00465        * [first, last) interpreted according to the flags in @p f.
00466        *
00467        * @param first The start of a range containing a valid regular
00468        *              expression.
00469        * @param last  The end of a range containing a valid regular
00470        *              expression.
00471        * @param f     The format flags of the regular expression.
00472        *
00473        * @throws regex_error if @p [first, last) is not a valid regular
00474        *         expression.
00475        */
00476       template<typename _InputIterator>
00477         basic_regex(_InputIterator __first, _InputIterator __last, 
00478             flag_type __f = regex_constants::ECMAScript)
00479     : _M_flags(__f),
00480       _M_automaton(__regex::__compile(__first, __last, _M_traits, _M_flags))
00481         { }
00482 
00483       /**
00484        * @brief Constructs a basic regular expression from an initializer list.
00485        *
00486        * @param l  The initializer list.
00487        * @param f  The format flags of the regular expression.
00488        *
00489        * @throws regex_error if @p l is not a valid regular expression.
00490        */
00491       basic_regex(initializer_list<_Ch_type> __l,
00492           flag_type __f = regex_constants::ECMAScript)
00493       : _M_flags(__f),
00494         _M_automaton(__regex::__compile(__l.begin(), __l.end(),
00495                         _M_traits, _M_flags))
00496       { }
00497 
00498       /**
00499        * @brief Destroys a basic regular expression.
00500        */
00501       ~basic_regex()
00502       { }
00503       
00504       /**
00505        * @brief Assigns one regular expression to another.
00506        */
00507       basic_regex&
00508       operator=(const basic_regex& __rhs)
00509       { return this->assign(__rhs); }
00510 
00511       /**
00512        * @brief Move-assigns one regular expression to another.
00513        */
00514       basic_regex&
00515       operator=(basic_regex&& __rhs) noexcept
00516       { return this->assign(std::move(__rhs)); }
00517 
00518       /**
00519        * @brief Replaces a regular expression with a new one constructed from
00520        * a C-style null-terminated string.
00521        *
00522        * @param A pointer to the start of a null-terminated C-style string
00523        *        containing a regular expression.
00524        */
00525       basic_regex&
00526       operator=(const _Ch_type* __p)
00527       { return this->assign(__p, flags()); }
00528       
00529       /**
00530        * @brief Replaces a regular expression with a new one constructed from
00531        * a string.
00532        *
00533        * @param A pointer to a string containing a regular expression.
00534        */
00535       template<typename _Ch_typeraits, typename _Allocator>
00536         basic_regex&
00537         operator=(const basic_string<_Ch_type, _Ch_typeraits, _Allocator>& __s)
00538         { return this->assign(__s, flags()); }
00539 
00540       // [7.8.3] assign
00541       /**
00542        * @brief the real assignment operator.
00543        *
00544        * @param rhs Another regular expression object.
00545        */
00546       basic_regex&
00547       assign(const basic_regex& __rhs)
00548       {
00549     basic_regex __tmp(__rhs);
00550     this->swap(__tmp);
00551     return *this;
00552       }
00553       
00554       /**
00555        * @brief The move-assignment operator.
00556        *
00557        * @param rhs Another regular expression object.
00558        */
00559       basic_regex&
00560       assign(basic_regex&& __rhs) noexcept
00561       {
00562     basic_regex __tmp(std::move(__rhs));
00563     this->swap(__tmp);
00564     return *this;
00565       }
00566 
00567       /**
00568        * @brief Assigns a new regular expression to a regex object from a
00569        * C-style null-terminated string containing a regular expression
00570        * pattern.
00571        *
00572        * @param p     A pointer to a C-style null-terminated string containing
00573        *              a regular expression pattern.
00574        * @param flags Syntax option flags.
00575        *
00576        * @throws regex_error if p does not contain a valid regular expression
00577        * pattern interpreted according to @p flags.  If regex_error is thrown,
00578        * *this remains unchanged.
00579        */
00580       basic_regex&
00581       assign(const _Ch_type* __p,
00582          flag_type __flags = regex_constants::ECMAScript)
00583       { return this->assign(string_type(__p), __flags); }
00584 
00585       /**
00586        * @brief Assigns a new regular expression to a regex object from a
00587        * C-style string containing a regular expression pattern.
00588        *
00589        * @param p     A pointer to a C-style string containing a
00590        *              regular expression pattern.
00591        * @param len   The length of the regular expression pattern string.
00592        * @param flags Syntax option flags.
00593        *
00594        * @throws regex_error if p does not contain a valid regular expression
00595        * pattern interpreted according to @p flags.  If regex_error is thrown,
00596        * *this remains unchanged.
00597        */
00598       basic_regex&
00599       assign(const _Ch_type* __p, std::size_t __len, flag_type __flags)
00600       { return this->assign(string_type(__p, __len), __flags); }
00601 
00602       /**
00603        * @brief Assigns a new regular expression to a regex object from a 
00604        * string containing a regular expression pattern.
00605        *
00606        * @param s     A string containing a regular expression pattern.
00607        * @param flags Syntax option flags.
00608        *
00609        * @throws regex_error if p does not contain a valid regular expression
00610        * pattern interpreted according to @p flags.  If regex_error is thrown,
00611        * *this remains unchanged.
00612        */
00613       template<typename _Ch_typeraits, typename _Allocator>
00614         basic_regex&
00615         assign(const basic_string<_Ch_type, _Ch_typeraits, _Allocator>& __s,
00616            flag_type __f = regex_constants::ECMAScript)
00617         { 
00618       basic_regex __tmp(__s, __f);
00619       this->swap(__tmp);
00620       return *this;
00621     }
00622 
00623       /**
00624        * @brief Assigns a new regular expression to a regex object.
00625        *
00626        * @param first The start of a range containing a valid regular
00627        *              expression.
00628        * @param last  The end of a range containing a valid regular
00629        *              expression.
00630        * @param flags Syntax option flags.
00631        *
00632        * @throws regex_error if p does not contain a valid regular expression
00633        * pattern interpreted according to @p flags.  If regex_error is thrown,
00634        * the object remains unchanged.
00635        */
00636       template<typename _InputIterator>
00637         basic_regex&
00638         assign(_InputIterator __first, _InputIterator __last,
00639            flag_type __flags = regex_constants::ECMAScript)
00640         { return this->assign(string_type(__first, __last), __flags); }
00641 
00642       /**
00643        * @brief Assigns a new regular expression to a regex object.
00644        *
00645        * @param l     An initializer list representing a regular expression.
00646        * @param flags Syntax option flags.
00647        *
00648        * @throws regex_error if @p l does not contain a valid regular
00649        * expression pattern interpreted according to @p flags.  If regex_error
00650        * is thrown, the object remains unchanged.
00651        */
00652       basic_regex&
00653       assign(initializer_list<_Ch_type> __l,
00654          flag_type __f = regex_constants::ECMAScript)
00655       { return this->assign(__l.begin(), __l.end(), __f); }
00656 
00657       // [7.8.4] const operations
00658       /**
00659        * @brief Gets the number of marked subexpressions within the regular
00660        * expression.
00661        */
00662       unsigned int
00663       mark_count() const
00664       { return _M_automaton->_M_sub_count() - 1; }
00665       
00666       /**
00667        * @brief Gets the flags used to construct the regular expression
00668        * or in the last call to assign().
00669        */
00670       flag_type
00671       flags() const
00672       { return _M_flags; }
00673       
00674       // [7.8.5] locale
00675       /**
00676        * @brief Imbues the regular expression object with the given locale.
00677        *
00678        * @param loc A locale.
00679        */
00680       locale_type
00681       imbue(locale_type __loc)
00682       { return _M_traits.imbue(__loc); }
00683       
00684       /**
00685        * @brief Gets the locale currently imbued in the regular expression
00686        *        object.
00687        */
00688       locale_type
00689       getloc() const
00690       { return _M_traits.getloc(); }
00691       
00692       // [7.8.6] swap
00693       /**
00694        * @brief Swaps the contents of two regular expression objects.
00695        *
00696        * @param rhs Another regular expression object.
00697        */
00698       void
00699       swap(basic_regex& __rhs)
00700       {
00701     std::swap(_M_flags,     __rhs._M_flags);
00702     std::swap(_M_traits,    __rhs._M_traits);
00703     std::swap(_M_automaton, __rhs._M_automaton);
00704       }
00705 
00706 #ifdef _GLIBCXX_DEBUG
00707       void
00708       _M_dot(std::ostream& __ostr)
00709       { _M_automaton->_M_dot(__ostr); }
00710 #endif
00711       
00712       const __regex::_AutomatonPtr&
00713       _M_get_automaton() const
00714       { return _M_automaton; }
00715 
00716     protected:
00717       flag_type              _M_flags;
00718       _Rx_traits             _M_traits;
00719       __regex::_AutomatonPtr _M_automaton;
00720     };
00721   
00722   /** @brief Standard regular expressions. */
00723   typedef basic_regex<char>    regex;
00724 #ifdef _GLIBCXX_USE_WCHAR_T
00725   /** @brief Standard wide-character regular expressions. */
00726   typedef basic_regex<wchar_t> wregex;
00727 #endif
00728 
00729 
00730   // [7.8.6] basic_regex swap
00731   /**
00732    * @brief Swaps the contents of two regular expression objects.
00733    * @param lhs First regular expression.
00734    * @param rhs Second regular expression.
00735    */
00736   template<typename _Ch_type, typename _Rx_traits>
00737     inline void
00738     swap(basic_regex<_Ch_type, _Rx_traits>& __lhs,
00739      basic_regex<_Ch_type, _Rx_traits>& __rhs)
00740     { __lhs.swap(__rhs); }
00741 
00742 
00743   // [7.9] Class template sub_match
00744   /**
00745    * A sequence of characters matched by a particular marked sub-expression.
00746    *
00747    * An object of this class is essentially a pair of iterators marking a
00748    * matched subexpression within a regular expression pattern match. Such
00749    * objects can be converted to and compared with std::basic_string objects
00750    * of a similar base character type as the pattern matched by the regular
00751    * expression.
00752    *
00753    * The iterators that make up the pair are the usual half-open interval
00754    * referencing the actual original pattern matched.
00755    */
00756   template<typename _BiIter>
00757     class sub_match : public std::pair<_BiIter, _BiIter>
00758     {
00759     public:
00760       typedef typename iterator_traits<_BiIter>::value_type      value_type;
00761       typedef typename iterator_traits<_BiIter>::difference_type
00762                                                             difference_type;
00763       typedef _BiIter                                              iterator;
00764       typedef std::basic_string<value_type>                     string_type;
00765 
00766     public:
00767       bool matched;
00768       
00769       constexpr sub_match() : matched() { }
00770 
00771       /**
00772        * Gets the length of the matching sequence.
00773        */
00774       difference_type
00775       length() const
00776       { return this->matched ? std::distance(this->first, this->second) : 0; }
00777 
00778       /**
00779        * @brief Gets the matching sequence as a string.
00780        *
00781        * @returns the matching sequence as a string.
00782        *
00783        * This is the implicit conversion operator.  It is identical to the
00784        * str() member function except that it will want to pop up in
00785        * unexpected places and cause a great deal of confusion and cursing
00786        * from the unwary.
00787        */
00788       operator string_type() const
00789       {
00790     return this->matched
00791       ? string_type(this->first, this->second)
00792       : string_type();
00793       }
00794       
00795       /**
00796        * @brief Gets the matching sequence as a string.
00797        *
00798        * @returns the matching sequence as a string.
00799        */
00800       string_type
00801       str() const
00802       {
00803     return this->matched
00804       ? string_type(this->first, this->second)
00805       : string_type();
00806       }
00807       
00808       /**
00809        * @brief Compares this and another matched sequence.
00810        *
00811        * @param s Another matched sequence to compare to this one.
00812        *
00813        * @retval <0 this matched sequence will collate before @p s.
00814        * @retval =0 this matched sequence is equivalent to @p s.
00815        * @retval <0 this matched sequence will collate after @p s.
00816        */
00817       int
00818       compare(const sub_match& __s) const
00819       { return this->str().compare(__s.str()); }
00820 
00821       /**
00822        * @brief Compares this sub_match to a string.
00823        *
00824        * @param s A string to compare to this sub_match.
00825        *
00826        * @retval <0 this matched sequence will collate before @p s.
00827        * @retval =0 this matched sequence is equivalent to @p s.
00828        * @retval <0 this matched sequence will collate after @p s.
00829        */
00830       int
00831       compare(const string_type& __s) const
00832       { return this->str().compare(__s); }
00833       
00834       /**
00835        * @brief Compares this sub_match to a C-style string.
00836        *
00837        * @param s A C-style string to compare to this sub_match.
00838        *
00839        * @retval <0 this matched sequence will collate before @p s.
00840        * @retval =0 this matched sequence is equivalent to @p s.
00841        * @retval <0 this matched sequence will collate after @p s.
00842        */
00843       int
00844       compare(const value_type* __s) const
00845       { return this->str().compare(__s); }
00846     };
00847   
00848   
00849   /** @brief Standard regex submatch over a C-style null-terminated string. */
00850   typedef sub_match<const char*>             csub_match;
00851   /** @brief Standard regex submatch over a standard string. */
00852   typedef sub_match<string::const_iterator>  ssub_match;
00853 #ifdef _GLIBCXX_USE_WCHAR_T
00854   /** @brief Regex submatch over a C-style null-terminated wide string. */
00855   typedef sub_match<const wchar_t*>          wcsub_match;
00856   /** @brief Regex submatch over a standard wide string. */
00857   typedef sub_match<wstring::const_iterator> wssub_match;
00858 #endif
00859 
00860   // [7.9.2] sub_match non-member operators
00861   
00862   /**
00863    * @brief Tests the equivalence of two regular expression submatches.
00864    * @param lhs First regular expression submatch.
00865    * @param rhs Second regular expression submatch.
00866    * @returns true if @a lhs  is equivalent to @a rhs, false otherwise.
00867    */
00868   template<typename _BiIter>
00869     inline bool
00870     operator==(const sub_match<_BiIter>& __lhs,
00871            const sub_match<_BiIter>& __rhs)
00872     { return __lhs.compare(__rhs) == 0; }
00873 
00874   /**
00875    * @brief Tests the inequivalence of two regular expression submatches.
00876    * @param lhs First regular expression submatch.
00877    * @param rhs Second regular expression submatch.
00878    * @returns true if @a lhs  is not equivalent to @a rhs, false otherwise.
00879    */
00880   template<typename _BiIter>
00881     inline bool
00882     operator!=(const sub_match<_BiIter>& __lhs,
00883            const sub_match<_BiIter>& __rhs)
00884     { return __lhs.compare(__rhs) != 0; }
00885 
00886   /**
00887    * @brief Tests the ordering of two regular expression submatches.
00888    * @param lhs First regular expression submatch.
00889    * @param rhs Second regular expression submatch.
00890    * @returns true if @a lhs precedes @a rhs, false otherwise.
00891    */
00892   template<typename _BiIter>
00893     inline bool
00894     operator<(const sub_match<_BiIter>& __lhs,
00895           const sub_match<_BiIter>& __rhs)
00896     { return __lhs.compare(__rhs) < 0; }
00897 
00898   /**
00899    * @brief Tests the ordering of two regular expression submatches.
00900    * @param lhs First regular expression submatch.
00901    * @param rhs Second regular expression submatch.
00902    * @returns true if @a lhs does not succeed @a rhs, false otherwise.
00903    */
00904   template<typename _BiIter>
00905     inline bool
00906     operator<=(const sub_match<_BiIter>& __lhs,
00907            const sub_match<_BiIter>& __rhs)
00908     { return __lhs.compare(__rhs) <= 0; }
00909 
00910   /**
00911    * @brief Tests the ordering of two regular expression submatches.
00912    * @param lhs First regular expression submatch.
00913    * @param rhs Second regular expression submatch.
00914    * @returns true if @a lhs does not precede @a rhs, false otherwise.
00915    */
00916   template<typename _BiIter>
00917     inline bool
00918     operator>=(const sub_match<_BiIter>& __lhs,
00919            const sub_match<_BiIter>& __rhs)
00920     { return __lhs.compare(__rhs) >= 0; }
00921 
00922   /**
00923    * @brief Tests the ordering of two regular expression submatches.
00924    * @param lhs First regular expression submatch.
00925    * @param rhs Second regular expression submatch.
00926    * @returns true if @a lhs succeeds @a rhs, false otherwise.
00927    */
00928   template<typename _BiIter>
00929     inline bool
00930     operator>(const sub_match<_BiIter>& __lhs,
00931           const sub_match<_BiIter>& __rhs)
00932     { return __lhs.compare(__rhs) > 0; }
00933 
00934   /**
00935    * @brief Tests the equivalence of a string and a regular expression
00936    *        submatch.
00937    * @param lhs A string.
00938    * @param rhs A regular expression submatch.
00939    * @returns true if @a lhs  is equivalent to @a rhs, false otherwise.
00940    */
00941   template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
00942     inline bool
00943     operator==(const basic_string<
00944            typename iterator_traits<_Bi_iter>::value_type,
00945            _Ch_traits, _Ch_alloc>& __lhs,
00946            const sub_match<_Bi_iter>& __rhs)
00947     { return __rhs.compare(__lhs.c_str()) == 0; }
00948 
00949   /**
00950    * @brief Tests the inequivalence of a string and a regular expression
00951    *        submatch.
00952    * @param lhs A string.
00953    * @param rhs A regular expression submatch.
00954    * @returns true if @a lhs  is not equivalent to @a rhs, false otherwise.
00955    */
00956   template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
00957     inline bool
00958     operator!=(const basic_string<
00959            typename iterator_traits<_Bi_iter>::value_type,
00960            _Ch_traits, _Ch_alloc>& __lhs, const sub_match<_Bi_iter>& __rhs)
00961     { return !(__lhs == __rhs); }
00962 
00963   /**
00964    * @brief Tests the ordering of a string and a regular expression submatch.
00965    * @param lhs A string.
00966    * @param rhs A regular expression submatch.
00967    * @returns true if @a lhs precedes @a rhs, false otherwise.
00968    */
00969   template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
00970     inline bool
00971     operator<(const basic_string<
00972           typename iterator_traits<_Bi_iter>::value_type,
00973           _Ch_traits, _Ch_alloc>& __lhs, const sub_match<_Bi_iter>& __rhs)
00974      { return __rhs.compare(__lhs.c_str()) > 0; }
00975 
00976   /**
00977    * @brief Tests the ordering of a string and a regular expression submatch.
00978    * @param lhs A string.
00979    * @param rhs A regular expression submatch.
00980    * @returns true if @a lhs succeeds @a rhs, false otherwise.
00981    */
00982   template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
00983     inline bool
00984     operator>(const basic_string<
00985           typename iterator_traits<_Bi_iter>::value_type, 
00986           _Ch_traits, _Ch_alloc>& __lhs, const sub_match<_Bi_iter>& __rhs)
00987     { return __rhs < __lhs; }
00988 
00989   /**
00990    * @brief Tests the ordering of a string and a regular expression submatch.
00991    * @param lhs A string.
00992    * @param rhs A regular expression submatch.
00993    * @returns true if @a lhs does not precede @a rhs, false otherwise.
00994    */
00995   template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
00996     inline bool
00997     operator>=(const basic_string<
00998            typename iterator_traits<_Bi_iter>::value_type,
00999            _Ch_traits, _Ch_alloc>& __lhs, const sub_match<_Bi_iter>& __rhs)
01000     { return !(__lhs < __rhs); }
01001 
01002   /**
01003    * @brief Tests the ordering of a string and a regular expression submatch.
01004    * @param lhs A string.
01005    * @param rhs A regular expression submatch.
01006    * @returns true if @a lhs does not succeed @a rhs, false otherwise.
01007    */
01008   template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
01009     inline bool
01010     operator<=(const basic_string<
01011            typename iterator_traits<_Bi_iter>::value_type,
01012            _Ch_traits, _Ch_alloc>& __lhs, const sub_match<_Bi_iter>& __rhs)
01013     { return !(__rhs < __lhs); }
01014 
01015   /**
01016    * @brief Tests the equivalence of a regular expression submatch and a
01017    *        string.
01018    * @param lhs A regular expression submatch.
01019    * @param rhs A string.
01020    * @returns true if @a lhs is equivalent to @a rhs, false otherwise.
01021    */
01022   template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
01023     inline bool
01024     operator==(const sub_match<_Bi_iter>& __lhs,
01025            const basic_string<
01026            typename iterator_traits<_Bi_iter>::value_type,
01027            _Ch_traits, _Ch_alloc>& __rhs)
01028     { return __lhs.compare(__rhs.c_str()) == 0; }
01029 
01030   /**
01031    * @brief Tests the inequivalence of a regular expression submatch and a
01032    *        string.
01033    * @param lhs A regular expression submatch.
01034    * @param rhs A string.
01035    * @returns true if @a lhs is not equivalent to @a rhs, false otherwise.
01036    */
01037   template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
01038     inline bool
01039     operator!=(const sub_match<_Bi_iter>& __lhs,
01040            const basic_string<
01041            typename iterator_traits<_Bi_iter>::value_type,
01042            _Ch_traits, _Ch_alloc>& __rhs)
01043     { return !(__lhs == __rhs); }
01044 
01045   /**
01046    * @brief Tests the ordering of a regular expression submatch and a string.
01047    * @param lhs A regular expression submatch.
01048    * @param rhs A string.
01049    * @returns true if @a lhs precedes @a rhs, false otherwise.
01050    */
01051   template<typename _Bi_iter, class _Ch_traits, class _Ch_alloc>
01052     inline bool
01053     operator<(const sub_match<_Bi_iter>& __lhs,
01054           const basic_string<
01055           typename iterator_traits<_Bi_iter>::value_type,
01056           _Ch_traits, _Ch_alloc>& __rhs)
01057     { return __lhs.compare(__rhs.c_str()) < 0; }
01058 
01059   /**
01060    * @brief Tests the ordering of a regular expression submatch and a string.
01061    * @param lhs A regular expression submatch.
01062    * @param rhs A string.
01063    * @returns true if @a lhs succeeds @a rhs, false otherwise.
01064    */
01065   template<typename _Bi_iter, class _Ch_traits, class _Ch_alloc>
01066     inline bool
01067     operator>(const sub_match<_Bi_iter>& __lhs,
01068           const basic_string<
01069           typename iterator_traits<_Bi_iter>::value_type,
01070           _Ch_traits, _Ch_alloc>& __rhs)
01071     { return __rhs < __lhs; }
01072 
01073   /**
01074    * @brief Tests the ordering of a regular expression submatch and a string.
01075    * @param lhs A regular expression submatch.
01076    * @param rhs A string.
01077    * @returns true if @a lhs does not precede @a rhs, false otherwise.
01078    */
01079   template<typename _Bi_iter, class _Ch_traits, class _Ch_alloc>
01080     inline bool
01081     operator>=(const sub_match<_Bi_iter>& __lhs,
01082            const basic_string<
01083            typename iterator_traits<_Bi_iter>::value_type,
01084            _Ch_traits, _Ch_alloc>& __rhs)
01085     { return !(__lhs < __rhs); }
01086 
01087   /**
01088    * @brief Tests the ordering of a regular expression submatch and a string.
01089    * @param lhs A regular expression submatch.
01090    * @param rhs A string.
01091    * @returns true if @a lhs does not succeed @a rhs, false otherwise.
01092    */
01093   template<typename _Bi_iter, class _Ch_traits, class _Ch_alloc>
01094     inline bool
01095     operator<=(const sub_match<_Bi_iter>& __lhs,
01096            const basic_string<
01097            typename iterator_traits<_Bi_iter>::value_type,
01098            _Ch_traits, _Ch_alloc>& __rhs)
01099     { return !(__rhs < __lhs); }
01100 
01101   /**
01102    * @brief Tests the equivalence of a C string and a regular expression
01103    *        submatch.
01104    * @param lhs A C string.
01105    * @param rhs A regular expression submatch.
01106    * @returns true if @a lhs  is equivalent to @a rhs, false otherwise.
01107    */
01108   template<typename _Bi_iter>
01109     inline bool
01110     operator==(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
01111            const sub_match<_Bi_iter>& __rhs)
01112     { return __rhs.compare(__lhs) == 0; }
01113 
01114   /**
01115    * @brief Tests the inequivalence of an iterator value and a regular
01116    *        expression submatch.
01117    * @param lhs A regular expression submatch.
01118    * @param rhs A string.
01119    * @returns true if @a lhs is not equivalent to @a rhs, false otherwise.
01120    */
01121   template<typename _Bi_iter>
01122     inline bool
01123     operator!=(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
01124            const sub_match<_Bi_iter>& __rhs)
01125     { return !(__lhs == __rhs); }
01126 
01127   /**
01128    * @brief Tests the ordering of a string and a regular expression submatch.
01129    * @param lhs A string.
01130    * @param rhs A regular expression submatch.
01131    * @returns true if @a lhs precedes @a rhs, false otherwise.
01132    */
01133   template<typename _Bi_iter>
01134     inline bool
01135     operator<(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
01136           const sub_match<_Bi_iter>& __rhs)
01137     { return __rhs.compare(__lhs) > 0; }
01138 
01139   /**
01140    * @brief Tests the ordering of a string and a regular expression submatch.
01141    * @param lhs A string.
01142    * @param rhs A regular expression submatch.
01143    * @returns true if @a lhs succeeds @a rhs, false otherwise.
01144    */
01145   template<typename _Bi_iter>
01146     inline bool
01147     operator>(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
01148           const sub_match<_Bi_iter>& __rhs)
01149     { return __rhs < __lhs; }
01150 
01151   /**
01152    * @brief Tests the ordering of a string and a regular expression submatch.
01153    * @param lhs A string.
01154    * @param rhs A regular expression submatch.
01155    * @returns true if @a lhs does not precede @a rhs, false otherwise.
01156    */
01157   template<typename _Bi_iter>
01158     inline bool
01159     operator>=(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
01160            const sub_match<_Bi_iter>& __rhs)
01161     { return !(__lhs < __rhs); }
01162 
01163   /**
01164    * @brief Tests the ordering of a string and a regular expression submatch.
01165    * @param lhs A string.
01166    * @param rhs A regular expression submatch.
01167    * @returns true if @a lhs does not succeed @a rhs, false otherwise.
01168    */
01169   template<typename _Bi_iter>
01170     inline bool
01171     operator<=(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
01172            const sub_match<_Bi_iter>& __rhs)
01173     { return !(__rhs < __lhs); }
01174 
01175   /**
01176    * @brief Tests the equivalence of a regular expression submatch and a
01177    *        string.
01178    * @param lhs A regular expression submatch.
01179    * @param rhs A pointer to a string?
01180    * @returns true if @a lhs  is equivalent to @a rhs, false otherwise.
01181    */
01182   template<typename _Bi_iter>
01183     inline bool
01184     operator==(const sub_match<_Bi_iter>& __lhs,
01185            typename iterator_traits<_Bi_iter>::value_type const* __rhs)
01186     { return __lhs.compare(__rhs) == 0; }
01187 
01188   /**
01189    * @brief Tests the inequivalence of a regular expression submatch and a
01190    *        string.
01191    * @param lhs A regular expression submatch.
01192    * @param rhs A pointer to a string.
01193    * @returns true if @a lhs is not equivalent to @a rhs, false otherwise.
01194    */
01195   template<typename _Bi_iter>
01196     inline bool
01197     operator!=(const sub_match<_Bi_iter>& __lhs,
01198            typename iterator_traits<_Bi_iter>::value_type const* __rhs)
01199     { return !(__lhs == __rhs); }
01200 
01201   /**
01202    * @brief Tests the ordering of a regular expression submatch and a string.
01203    * @param lhs A regular expression submatch.
01204    * @param rhs A string.
01205    * @returns true if @a lhs precedes @a rhs, false otherwise.
01206    */
01207   template<typename _Bi_iter>
01208     inline bool
01209     operator<(const sub_match<_Bi_iter>& __lhs,
01210           typename iterator_traits<_Bi_iter>::value_type const* __rhs)
01211     { return __lhs.compare(__rhs) < 0; }
01212 
01213   /**
01214    * @brief Tests the ordering of a regular expression submatch and a string.
01215    * @param lhs A regular expression submatch.
01216    * @param rhs A string.
01217    * @returns true if @a lhs succeeds @a rhs, false otherwise.
01218    */
01219   template<typename _Bi_iter>
01220     inline bool
01221     operator>(const sub_match<_Bi_iter>& __lhs,
01222           typename iterator_traits<_Bi_iter>::value_type const* __rhs)
01223     { return __rhs < __lhs; }
01224 
01225   /**
01226    * @brief Tests the ordering of a regular expression submatch and a string.
01227    * @param lhs A regular expression submatch.
01228    * @param rhs A string.
01229    * @returns true if @a lhs does not precede @a rhs, false otherwise.
01230    */
01231   template<typename _Bi_iter>
01232     inline bool
01233     operator>=(const sub_match<_Bi_iter>& __lhs,
01234            typename iterator_traits<_Bi_iter>::value_type const* __rhs)
01235     { return !(__lhs < __rhs); }
01236 
01237   /**
01238    * @brief Tests the ordering of a regular expression submatch and a string.
01239    * @param lhs A regular expression submatch.
01240    * @param rhs A string.
01241    * @returns true if @a lhs does not succeed @a rhs, false otherwise.
01242    */
01243   template<typename _Bi_iter>
01244     inline bool
01245     operator<=(const sub_match<_Bi_iter>& __lhs,
01246            typename iterator_traits<_Bi_iter>::value_type const* __rhs)
01247     { return !(__rhs < __lhs); }
01248 
01249   /**
01250    * @brief Tests the equivalence of a string and a regular expression
01251    *        submatch.
01252    * @param lhs A string.
01253    * @param rhs A regular expression submatch.
01254    * @returns true if @a lhs is equivalent to @a rhs, false otherwise.
01255    */
01256   template<typename _Bi_iter>
01257     inline bool
01258     operator==(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
01259            const sub_match<_Bi_iter>& __rhs)
01260     {
01261       return __rhs.compare(typename sub_match<_Bi_iter>::string_type(1, __lhs))
01262              == 0;
01263     }
01264 
01265   /**
01266    * @brief Tests the inequivalence of a string and a regular expression
01267    *        submatch.
01268    * @param lhs A string.
01269    * @param rhs A regular expression submatch.
01270    * @returns true if @a lhs is not equivalent to @a rhs, false otherwise.
01271    */
01272   template<typename _Bi_iter>
01273     inline bool
01274     operator!=(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
01275            const sub_match<_Bi_iter>& __rhs)
01276     { return !(__lhs == __rhs); }
01277 
01278   /**
01279    * @brief Tests the ordering of a string and a regular expression submatch.
01280    * @param lhs A string.
01281    * @param rhs A regular expression submatch.
01282    * @returns true if @a lhs precedes @a rhs, false otherwise.
01283    */
01284   template<typename _Bi_iter>
01285     inline bool
01286     operator<(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
01287           const sub_match<_Bi_iter>& __rhs)
01288     {
01289       return __rhs.compare(typename sub_match<_Bi_iter>::string_type(1, __lhs))
01290              > 0;
01291     }
01292 
01293   /**
01294    * @brief Tests the ordering of a string and a regular expression submatch.
01295    * @param lhs A string.
01296    * @param rhs A regular expression submatch.
01297    * @returns true if @a lhs succeeds @a rhs, false otherwise.
01298    */
01299   template<typename _Bi_iter>
01300     inline bool
01301     operator>(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
01302           const sub_match<_Bi_iter>& __rhs)
01303     { return __rhs < __lhs; }
01304 
01305   /**
01306    * @brief Tests the ordering of a string and a regular expression submatch.
01307    * @param lhs A string.
01308    * @param rhs A regular expression submatch.
01309    * @returns true if @a lhs does not precede @a rhs, false otherwise.
01310    */
01311   template<typename _Bi_iter>
01312     inline bool
01313     operator>=(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
01314            const sub_match<_Bi_iter>& __rhs)
01315     { return !(__lhs < __rhs); }
01316 
01317   /**
01318    * @brief Tests the ordering of a string and a regular expression submatch.
01319    * @param lhs A string.
01320    * @param rhs A regular expression submatch.
01321    * @returns true if @a lhs does not succeed @a rhs, false otherwise.
01322    */
01323   template<typename _Bi_iter>
01324     inline bool
01325     operator<=(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
01326            const sub_match<_Bi_iter>& __rhs)
01327     { return !(__rhs < __lhs); }
01328 
01329   /**
01330    * @brief Tests the equivalence of a regular expression submatch and a
01331    *        string.
01332    * @param lhs A regular expression submatch.
01333    * @param rhs A const string reference.
01334    * @returns true if @a lhs  is equivalent to @a rhs, false otherwise.
01335    */
01336   template<typename _Bi_iter>
01337     inline bool
01338     operator==(const sub_match<_Bi_iter>& __lhs,
01339            typename iterator_traits<_Bi_iter>::value_type const& __rhs)
01340     {
01341       return __lhs.compare(typename sub_match<_Bi_iter>::string_type(1, __rhs))
01342              == 0;
01343     }
01344 
01345   /**
01346    * @brief Tests the inequivalence of a regular expression submatch and a
01347    *        string.
01348    * @param lhs A regular expression submatch.
01349    * @param rhs A const string reference.
01350    * @returns true if @a lhs is not equivalent to @a rhs, false otherwise.
01351    */
01352   template<typename _Bi_iter>
01353     inline bool
01354     operator!=(const sub_match<_Bi_iter>& __lhs,
01355            typename iterator_traits<_Bi_iter>::value_type const& __rhs)
01356     { return !(__lhs == __rhs); }
01357 
01358   /**
01359    * @brief Tests the ordering of a regular expression submatch and a string.
01360    * @param lhs A regular expression submatch.
01361    * @param rhs A const string reference.
01362    * @returns true if @a lhs precedes @a rhs, false otherwise.
01363    */
01364   template<typename _Bi_iter>
01365     inline bool
01366     operator<(const sub_match<_Bi_iter>& __lhs,
01367           typename iterator_traits<_Bi_iter>::value_type const& __rhs)
01368     {
01369       return __lhs.compare(typename sub_match<_Bi_iter>::string_type(1, __rhs))
01370              < 0;
01371     }
01372 
01373   /**
01374    * @brief Tests the ordering of a regular expression submatch and a string.
01375    * @param lhs A regular expression submatch.
01376    * @param rhs A const string reference.
01377    * @returns true if @a lhs succeeds @a rhs, false otherwise.
01378    */
01379   template<typename _Bi_iter>
01380     inline bool
01381     operator>(const sub_match<_Bi_iter>& __lhs,
01382           typename iterator_traits<_Bi_iter>::value_type const& __rhs)
01383     { return __rhs < __lhs; }
01384 
01385   /**
01386    * @brief Tests the ordering of a regular expression submatch and a string.
01387    * @param lhs A regular expression submatch.
01388    * @param rhs A const string reference.
01389    * @returns true if @a lhs does not precede @a rhs, false otherwise.
01390    */
01391   template<typename _Bi_iter>
01392     inline bool
01393     operator>=(const sub_match<_Bi_iter>& __lhs,
01394            typename iterator_traits<_Bi_iter>::value_type const& __rhs)
01395     { return !(__lhs < __rhs); }
01396 
01397   /**
01398    * @brief Tests the ordering of a regular expression submatch and a string.
01399    * @param lhs A regular expression submatch.
01400    * @param rhs A const string reference.
01401    * @returns true if @a lhs does not succeed @a rhs, false otherwise.
01402    */
01403   template<typename _Bi_iter>
01404     inline bool
01405     operator<=(const sub_match<_Bi_iter>& __lhs,
01406            typename iterator_traits<_Bi_iter>::value_type const& __rhs)
01407     { return !(__rhs < __lhs); }
01408 
01409   /**
01410    * @brief Inserts a matched string into an output stream.
01411    *
01412    * @param os The output stream.
01413    * @param m  A submatch string.
01414    *
01415    * @returns the output stream with the submatch string inserted.
01416    */
01417   template<typename _Ch_type, typename _Ch_traits, typename _Bi_iter>
01418     inline
01419     basic_ostream<_Ch_type, _Ch_traits>&
01420     operator<<(basic_ostream<_Ch_type, _Ch_traits>& __os,
01421            const sub_match<_Bi_iter>& __m)
01422     { return __os << __m.str(); }
01423 
01424   // [7.10] Class template match_results
01425 
01426   /*
01427    * Special sub_match object representing an unmatched sub-expression.
01428    */
01429   template<typename _Bi_iter>
01430     inline const sub_match<_Bi_iter>&
01431     __unmatched_sub()
01432     {
01433       static const sub_match<_Bi_iter> __unmatched = sub_match<_Bi_iter>();
01434       return __unmatched;
01435     }
01436 
01437   /**
01438    * @brief The results of a match or search operation.
01439    *
01440    * A collection of character sequences representing the result of a regular
01441    * expression match.  Storage for the collection is allocated and freed as
01442    * necessary by the member functions of class template match_results.
01443    *
01444    * This class satisfies the Sequence requirements, with the exception that
01445    * only the operations defined for a const-qualified Sequence are supported.
01446    *
01447    * The sub_match object stored at index 0 represents sub-expression 0, i.e.
01448    * the whole match. In this case the %sub_match member matched is always true.
01449    * The sub_match object stored at index n denotes what matched the marked
01450    * sub-expression n within the matched expression. If the sub-expression n
01451    * participated in a regular expression match then the %sub_match member
01452    * matched evaluates to true, and members first and second denote the range
01453    * of characters [first, second) which formed that match. Otherwise matched
01454    * is false, and members first and second point to the end of the sequence
01455    * that was searched.
01456    *
01457    * @nosubgrouping
01458    */
01459   template<typename _Bi_iter,
01460        typename _Allocator = allocator<sub_match<_Bi_iter> > >
01461     class match_results
01462     : private std::vector<std::sub_match<_Bi_iter>, _Allocator>
01463     {
01464     private:
01465       /*
01466        * The vector base is empty if this does not represent a successful match.
01467        * Otherwise it contains n+3 elements where n is the number of marked
01468        * sub-expressions:
01469        * [0] entire match
01470        * [1] 1st marked subexpression
01471        * ...
01472        * [n] nth marked subexpression
01473        * [n+1] prefix
01474        * [n+2] suffix
01475        */
01476       typedef std::vector<std::sub_match<_Bi_iter>, _Allocator>
01477                                                               _Base_type;
01478 
01479     public:
01480       /**
01481        * @name 10.? Public Types
01482        */
01483       //@{
01484       typedef sub_match<_Bi_iter>                             value_type;
01485       typedef const value_type&                               const_reference;
01486       typedef const_reference                                 reference;
01487       typedef typename _Base_type::const_iterator             const_iterator;
01488       typedef const_iterator                                  iterator;
01489       typedef typename std::iterator_traits<_Bi_iter>::difference_type
01490                                                               difference_type;
01491       /* TODO: needs allocator_traits */
01492       typedef typename _Allocator::size_type                  size_type;
01493       typedef _Allocator                                      allocator_type;
01494       typedef typename std::iterator_traits<_Bi_iter>::value_type
01495                                                               char_type;
01496       typedef std::basic_string<char_type>                    string_type;
01497       //@}
01498   
01499     public:
01500       /**
01501        * @name 28.10.1 Construction, Copying, and Destruction
01502        */
01503       //@{
01504 
01505       /**
01506        * @brief Constructs a default %match_results container.
01507        * @post size() returns 0 and str() returns an empty string.
01508        */
01509       explicit
01510       match_results(const _Allocator& __a = _Allocator())
01511       : _Base_type(__a)
01512       { }
01513 
01514       /**
01515        * @brief Copy constructs a %match_results.
01516        */
01517       match_results(const match_results& __rhs)
01518       : _Base_type(__rhs)
01519       { }
01520 
01521       /**
01522        * @brief Move constructs a %match_results.
01523        */
01524       match_results(match_results&& __rhs) noexcept
01525       : _Base_type(std::move(__rhs))
01526       { }
01527 
01528       /**
01529        * @brief Assigns rhs to *this.
01530        */
01531       match_results&
01532       operator=(const match_results& __rhs)
01533       {
01534     match_results(__rhs).swap(*this);
01535     return *this;
01536       }
01537 
01538       /**
01539        * @brief Move-assigns rhs to *this.
01540        */
01541       match_results&
01542       operator=(match_results&& __rhs)
01543       {
01544     match_results(std::move(__rhs)).swap(*this);
01545     return *this;
01546       }
01547 
01548       /**
01549        * @brief Destroys a %match_results object.
01550        */
01551       ~match_results()
01552       { }
01553       
01554       //@}
01555 
01556       // 28.10.2, state:
01557       /**
01558        * @brief Indicates if the %match_results is ready.
01559        * @retval true   The object has a fully-established result state.
01560        * @retval false  The object is not ready.
01561        */
01562       bool ready() const { return !_Base_type::empty(); }
01563 
01564       /**
01565        * @name 28.10.2 Size
01566        */
01567       //@{
01568 
01569       /**
01570        * @brief Gets the number of matches and submatches.
01571        *
01572        * The number of matches for a given regular expression will be either 0
01573        * if there was no match or mark_count() + 1 if a match was successful.
01574        * Some matches may be empty.
01575        *
01576        * @returns the number of matches found.
01577        */
01578       size_type
01579       size() const
01580       {
01581         size_type __size = _Base_type::size();
01582         return (__size && _Base_type::operator[](0).matched) ? __size - 2 : 0;
01583       }
01584       
01585       size_type
01586       max_size() const
01587       { return _Base_type::max_size(); }
01588 
01589       /**
01590        * @brief Indicates if the %match_results contains no results.
01591        * @retval true The %match_results object is empty.
01592        * @retval false The %match_results object is not empty.
01593        */
01594       bool
01595       empty() const
01596       { return size() == 0; }
01597       
01598       //@}
01599 
01600       /**
01601        * @name 10.3 Element Access
01602        */
01603       //@{
01604 
01605       /**
01606        * @brief Gets the length of the indicated submatch.
01607        * @param sub indicates the submatch.
01608        * @pre   ready() == true
01609        *
01610        * This function returns the length of the indicated submatch, or the
01611        * length of the entire match if @p sub is zero (the default).
01612        */
01613       difference_type
01614       length(size_type __sub = 0) const
01615       { return (*this)[__sub].length(); }
01616 
01617       /**
01618        * @brief Gets the offset of the beginning of the indicated submatch.
01619        * @param sub indicates the submatch.
01620        * @pre   ready() == true
01621        *
01622        * This function returns the offset from the beginning of the target
01623        * sequence to the beginning of the submatch, unless the value of @p sub
01624        * is zero (the default), in which case this function returns the offset
01625        * from the beginning of the target sequence to the beginning of the
01626        * match.
01627        *
01628        * Returns -1 if @p sub is out of range.
01629        */
01630       difference_type
01631       position(size_type __sub = 0) const
01632       {
01633     return __sub < size() ? std::distance(this->prefix().first,
01634                           (*this)[__sub].first) : -1;
01635       }
01636 
01637       /**
01638        * @brief Gets the match or submatch converted to a string type.
01639        * @param sub indicates the submatch.
01640        * @pre   ready() == true
01641        *
01642        * This function gets the submatch (or match, if @p sub is zero) extracted
01643        * from the target range and converted to the associated string type.
01644        */
01645       string_type
01646       str(size_type __sub = 0) const
01647       { return (*this)[__sub].str(); }
01648       
01649       /**
01650        * @brief Gets a %sub_match reference for the match or submatch.
01651        * @param sub indicates the submatch.
01652        * @pre   ready() == true
01653        *
01654        * This function gets a reference to the indicated submatch, or the entire
01655        * match if @p sub is zero.
01656        *
01657        * If @p sub >= size() then this function returns a %sub_match with a
01658        * special value indicating no submatch.
01659        */
01660       const_reference
01661       operator[](size_type __sub) const
01662       { 
01663         _GLIBCXX_DEBUG_ASSERT( ready() );
01664         return __sub < size()
01665            ?  _Base_type::operator[](__sub)
01666            : __unmatched_sub<_Bi_iter>();
01667       }
01668 
01669       /**
01670        * @brief Gets a %sub_match representing the match prefix.
01671        * @pre   ready() == true
01672        *
01673        * This function gets a reference to a %sub_match object representing the
01674        * part of the target range between the start of the target range and the
01675        * start of the match.
01676        */
01677       const_reference
01678       prefix() const
01679       {
01680         _GLIBCXX_DEBUG_ASSERT( ready() );
01681         return !empty()
01682                ? _Base_type::operator[](_Base_type::size() - 2)
01683            : __unmatched_sub<_Bi_iter>();
01684       }
01685 
01686       /**
01687        * @brief Gets a %sub_match representing the match suffix.
01688        * @pre   ready() == true
01689        *
01690        * This function gets a reference to a %sub_match object representing the
01691        * part of the target range between the end of the match and the end of
01692        * the target range.
01693        */
01694       const_reference
01695       suffix() const
01696       {
01697     _GLIBCXX_DEBUG_ASSERT( ready() );
01698     return !empty()
01699            ? _Base_type::operator[](_Base_type::size() - 1)
01700            : __unmatched_sub<_Bi_iter>();
01701       }
01702 
01703       /**
01704        * @brief Gets an iterator to the start of the %sub_match collection.
01705        */
01706       const_iterator
01707       begin() const
01708       { return _Base_type::begin(); }
01709       
01710       /**
01711        * @brief Gets an iterator to the start of the %sub_match collection.
01712        */
01713       const_iterator
01714       cbegin() const
01715       { return _Base_type::cbegin(); }
01716 
01717       /**
01718        * @brief Gets an iterator to one-past-the-end of the collection.
01719        */
01720       const_iterator
01721       end() const
01722       { return !empty() ? _Base_type::end() - 2 : _Base_type::end(); }
01723       
01724       /**
01725        * @brief Gets an iterator to one-past-the-end of the collection.
01726        */
01727       const_iterator
01728       cend() const
01729       { return end(); }
01730 
01731       //@}
01732 
01733       /**
01734        * @name 10.4 Formatting
01735        *
01736        * These functions perform formatted substitution of the matched
01737        * character sequences into their target.  The format specifiers and
01738        * escape sequences accepted by these functions are determined by
01739        * their @p flags parameter as documented above.
01740        */
01741        //@{
01742 
01743       /**
01744        * @pre   ready() == true
01745        * @todo Implement this function.
01746        */
01747       template<typename _Out_iter>
01748         _Out_iter
01749         format(_Out_iter __out, const char_type* __fmt_first,
01750            const char_type* __fmt_last,
01751            regex_constants::match_flag_type __flags
01752            = regex_constants::format_default) const
01753         { return __out; }
01754 
01755       /**
01756        * @pre   ready() == true
01757        */
01758       template<typename _Out_iter, typename _St, typename _Sa>
01759         _Out_iter
01760         format(_Out_iter __out, const basic_string<char_type, _St, _Sa>& __fmt,
01761            regex_constants::match_flag_type __flags
01762            = regex_constants::format_default) const
01763         {
01764           return format(__out, __fmt.data(), __fmt.data() + __fmt.size(),
01765                         __flags);
01766         }
01767 
01768       /**
01769        * @pre   ready() == true
01770        */
01771       template<typename _Out_iter, typename _St, typename _Sa>
01772         basic_string<char_type, _St, _Sa>
01773         format(const basic_string<char_type, _St, _Sa>& __fmt,
01774            regex_constants::match_flag_type __flags
01775            = regex_constants::format_default) const
01776         {
01777           basic_string<char_type, _St, _Sa> __result;
01778           format(std::back_inserter(__result), __fmt, __flags);
01779           return __result;
01780         }
01781 
01782       /**
01783        * @pre   ready() == true
01784        */
01785       string_type
01786       format(const char_type* __fmt,
01787          regex_constants::match_flag_type __flags
01788          = regex_constants::format_default) const
01789       {
01790         string_type __result;
01791         format(std::back_inserter(__result),
01792                __fmt + char_traits<char_type>::length(__fmt),
01793                __flags);
01794         return __result;
01795       }
01796 
01797       //@} 
01798 
01799       /**
01800        * @name 10.5 Allocator
01801        */
01802       //@{ 
01803 
01804       /**
01805        * @brief Gets a copy of the allocator.
01806        */
01807       allocator_type
01808       get_allocator() const
01809       { return _Base_type::get_allocator(); }
01810       
01811       //@} 
01812 
01813       /**
01814        * @name 10.6 Swap
01815        */
01816        //@{ 
01817 
01818       /**
01819        * @brief Swaps the contents of two match_results.
01820        */
01821       void
01822       swap(match_results& __that)
01823       { _Base_type::swap(__that); }
01824       //@} 
01825       
01826     private:
01827       friend class __regex::_SpecializedResults<_Bi_iter, _Allocator>;
01828     };
01829   
01830   typedef match_results<const char*>             cmatch;
01831   typedef match_results<string::const_iterator>  smatch;
01832 #ifdef _GLIBCXX_USE_WCHAR_T
01833   typedef match_results<const wchar_t*>          wcmatch;
01834   typedef match_results<wstring::const_iterator> wsmatch;
01835 #endif
01836 
01837   // match_results comparisons
01838   /**
01839    * @brief Compares two match_results for equality.
01840    * @returns true if the two objects refer to the same match,
01841    * false otherwise.
01842    */
01843   template<typename _Bi_iter, typename _Allocator>
01844     inline bool
01845     operator==(const match_results<_Bi_iter, _Allocator>& __m1,
01846            const match_results<_Bi_iter, _Allocator>& __m2)
01847     {
01848       if (__m1.ready() != __m2.ready())
01849         return false;
01850       if (!__m1.ready())  // both are not ready
01851         return true;
01852       if (__m1.empty() != __m2.empty())
01853         return false;
01854       if (__m1.empty())   // both are empty
01855         return true;
01856       return __m1.prefix() == __m2.prefix()
01857         && __m1.size() == __m2.size()
01858         && std::equal(__m1.begin(), __m1.end(), __m2.begin())
01859         && __m1.suffix() == __m2.suffix();
01860     }
01861 
01862   /**
01863    * @brief Compares two match_results for inequality.
01864    * @returns true if the two objects do not refer to the same match,
01865    * false otherwise.
01866    */
01867   template<typename _Bi_iter, class _Allocator>
01868     inline bool
01869     operator!=(const match_results<_Bi_iter, _Allocator>& __m1,
01870            const match_results<_Bi_iter, _Allocator>& __m2)
01871     { return !(__m1 == __m2); }
01872 
01873   // [7.10.6] match_results swap
01874   /**
01875    * @brief Swaps two match results.
01876    * @param lhs A match result.
01877    * @param rhs A match result.
01878    *
01879    * The contents of the two match_results objects are swapped.
01880    */
01881   template<typename _Bi_iter, typename _Allocator>
01882     inline void
01883     swap(match_results<_Bi_iter, _Allocator>& __lhs,
01884      match_results<_Bi_iter, _Allocator>& __rhs)
01885     { __lhs.swap(__rhs); }
01886 
01887   // [7.11.2] Function template regex_match
01888   /**
01889    * @name Matching, Searching, and Replacing
01890    */
01891   //@{
01892 
01893   /**
01894    * @brief Determines if there is a match between the regular expression @p e
01895    * and all of the character sequence [first, last).
01896    *
01897    * @param s     Start of the character sequence to match.
01898    * @param e     One-past-the-end of the character sequence to match.
01899    * @param m     The match results.
01900    * @param re    The regular expression.
01901    * @param flags Controls how the regular expression is matched.
01902    *
01903    * @retval true  A match exists.
01904    * @retval false Otherwise.
01905    *
01906    * @throws an exception of type regex_error.
01907    *
01908    * @todo Implement this function.
01909    */
01910   template<typename _Bi_iter, typename _Allocator,
01911        typename _Ch_type, typename _Rx_traits>
01912     bool
01913     regex_match(_Bi_iter                                 __s,
01914                 _Bi_iter                                 __e,
01915                 match_results<_Bi_iter, _Allocator>&     __m,
01916                 const basic_regex<_Ch_type, _Rx_traits>& __re,
01917                 regex_constants::match_flag_type         __flags
01918                                = regex_constants::match_default)
01919     {
01920       __regex::_AutomatonPtr __a = __re._M_get_automaton();
01921       __regex::_Automaton::_SizeT __sz = __a->_M_sub_count();
01922       __regex::_SpecializedCursor<_Bi_iter> __cs(__s, __e);
01923       __regex::_SpecializedResults<_Bi_iter, _Allocator> __r(__sz, __cs, __m);
01924       __regex::_Grep_matcher __matcher(__cs, __r, __a, __flags);
01925       return __m[0].matched;
01926     }
01927 
01928   /**
01929    * @brief Indicates if there is a match between the regular expression @p e
01930    * and all of the character sequence [first, last).
01931    *
01932    * @param first Beginning of the character sequence to match.
01933    * @param last  One-past-the-end of the character sequence to match.
01934    * @param re    The regular expression.
01935    * @param flags Controls how the regular expression is matched.
01936    *
01937    * @retval true  A match exists.
01938    * @retval false Otherwise.
01939    *
01940    * @throws an exception of type regex_error.
01941    */
01942   template<typename _Bi_iter, typename _Ch_type, typename _Rx_traits>
01943     bool
01944     regex_match(_Bi_iter __first, _Bi_iter __last,
01945         const basic_regex<_Ch_type, _Rx_traits>& __re,
01946         regex_constants::match_flag_type __flags
01947         = regex_constants::match_default)
01948     { 
01949       match_results<_Bi_iter> __what;
01950       return regex_match(__first, __last, __what, __re, __flags);
01951     }
01952 
01953   /**
01954    * @brief Determines if there is a match between the regular expression @p e
01955    * and a C-style null-terminated string.
01956    *
01957    * @param s  The C-style null-terminated string to match.
01958    * @param m  The match results.
01959    * @param re The regular expression.
01960    * @param f  Controls how the regular expression is matched.
01961    *
01962    * @retval true  A match exists.
01963    * @retval false Otherwise.
01964    *
01965    * @throws an exception of type regex_error.
01966    */
01967   template<typename _Ch_type, typename _Allocator, typename _Rx_traits>
01968     inline bool
01969     regex_match(const _Ch_type* __s,
01970         match_results<const _Ch_type*, _Allocator>& __m,
01971         const basic_regex<_Ch_type, _Rx_traits>& __re,
01972         regex_constants::match_flag_type __f
01973         = regex_constants::match_default)
01974     { return regex_match(__s, __s + _Rx_traits::length(__s), __m, __re, __f); }
01975 
01976   /**
01977    * @brief Determines if there is a match between the regular expression @p e
01978    * and a string.
01979    *
01980    * @param s     The string to match.
01981    * @param m     The match results.
01982    * @param re    The regular expression.
01983    * @param flags Controls how the regular expression is matched.
01984    *
01985    * @retval true  A match exists.
01986    * @retval false Otherwise.
01987    *
01988    * @throws an exception of type regex_error.
01989    */
01990   template<typename _Ch_traits, typename _Ch_alloc,
01991        typename _Allocator, typename _Ch_type, typename _Rx_traits>
01992     inline bool
01993     regex_match(const basic_string<_Ch_type, _Ch_traits, _Ch_alloc>& __s,
01994         match_results<typename basic_string<_Ch_type, 
01995         _Ch_traits, _Ch_alloc>::const_iterator, _Allocator>& __m,
01996         const basic_regex<_Ch_type, _Rx_traits>& __re,
01997         regex_constants::match_flag_type __flags
01998         = regex_constants::match_default)
01999     { return regex_match(__s.begin(), __s.end(), __m, __re, __flags); }
02000 
02001   /**
02002    * @brief Indicates if there is a match between the regular expression @p e
02003    * and a C-style null-terminated string.
02004    *
02005    * @param s  The C-style null-terminated string to match.
02006    * @param re The regular expression.
02007    * @param f  Controls how the regular expression is matched.
02008    *
02009    * @retval true  A match exists.
02010    * @retval false Otherwise.
02011    *
02012    * @throws an exception of type regex_error.
02013    */
02014   template<typename _Ch_type, class _Rx_traits>
02015     inline bool
02016     regex_match(const _Ch_type* __s,
02017         const basic_regex<_Ch_type, _Rx_traits>& __re,
02018         regex_constants::match_flag_type __f
02019         = regex_constants::match_default)
02020     { return regex_match(__s, __s + _Rx_traits::length(__s), __re, __f); }
02021 
02022   /**
02023    * @brief Indicates if there is a match between the regular expression @p e
02024    * and a string.
02025    *
02026    * @param s     [IN] The string to match.
02027    * @param re    [IN] The regular expression.
02028    * @param flags [IN] Controls how the regular expression is matched.
02029    *
02030    * @retval true  A match exists.
02031    * @retval false Otherwise.
02032    *
02033    * @throws an exception of type regex_error.
02034    */
02035   template<typename _Ch_traits, typename _Str_allocator,
02036        typename _Ch_type, typename _Rx_traits>
02037     inline bool
02038     regex_match(const basic_string<_Ch_type, _Ch_traits, _Str_allocator>& __s,
02039         const basic_regex<_Ch_type, _Rx_traits>& __re,
02040         regex_constants::match_flag_type __flags
02041         = regex_constants::match_default)
02042     { return regex_match(__s.begin(), __s.end(), __re, __flags); }
02043 
02044   // [7.11.3] Function template regex_search
02045   /**
02046    * Searches for a regular expression within a range.
02047    * @param first [IN]  The start of the string to search.
02048    * @param last  [IN]  One-past-the-end of the string to search.
02049    * @param m     [OUT] The match results.
02050    * @param re    [IN]  The regular expression to search for.
02051    * @param flags [IN]  Search policy flags.
02052    * @retval true  A match was found within the string.
02053    * @retval false No match was found within the string, the content of %m is
02054    *               undefined.
02055    *
02056    * @throws an exception of type regex_error.
02057    *
02058    * @todo Implement this function.
02059    */
02060   template<typename _Bi_iter, typename _Allocator,
02061        typename _Ch_type, typename _Rx_traits>
02062     inline bool
02063     regex_search(_Bi_iter __first, _Bi_iter __last,
02064          match_results<_Bi_iter, _Allocator>& __m,
02065          const basic_regex<_Ch_type, _Rx_traits>& __re,
02066          regex_constants::match_flag_type __flags
02067          = regex_constants::match_default)
02068     { return false; }
02069 
02070   /**
02071    * Searches for a regular expression within a range.
02072    * @param first [IN]  The start of the string to search.
02073    * @param last  [IN]  One-past-the-end of the string to search.
02074    * @param re    [IN]  The regular expression to search for.
02075    * @param flags [IN]  Search policy flags.
02076    * @retval true  A match was found within the string.
02077    * @retval false No match was found within the string.
02078    * @doctodo
02079    *
02080    * @throws an exception of type regex_error.
02081    */
02082   template<typename _Bi_iter, typename _Ch_type, typename _Rx_traits>
02083     inline bool
02084     regex_search(_Bi_iter __first, _Bi_iter __last,
02085          const basic_regex<_Ch_type, _Rx_traits>& __re,
02086          regex_constants::match_flag_type __flags
02087          = regex_constants::match_default)
02088     {
02089       match_results<_Bi_iter> __what;
02090       return regex_search(__first, __last, __what, __re, __flags);
02091     }
02092 
02093   /**
02094    * @brief Searches for a regular expression within a C-string.
02095    * @param s [IN]  A C-string to search for the regex.
02096    * @param m [OUT] The set of regex matches.
02097    * @param e [IN]  The regex to search for in @p s.
02098    * @param f [IN]  The search flags.
02099    * @retval true  A match was found within the string.
02100    * @retval false No match was found within the string, the content of %m is
02101    *               undefined.
02102    * @doctodo
02103    *
02104    * @throws an exception of type regex_error.
02105    */
02106   template<typename _Ch_type, class _Allocator, class _Rx_traits>
02107     inline bool
02108     regex_search(const _Ch_type* __s,
02109          match_results<const _Ch_type*, _Allocator>& __m,
02110          const basic_regex<_Ch_type, _Rx_traits>& __e,
02111          regex_constants::match_flag_type __f
02112          = regex_constants::match_default)
02113     { return regex_search(__s, __s + _Rx_traits::length(__s), __m, __e, __f); }
02114 
02115   /**
02116    * @brief Searches for a regular expression within a C-string.
02117    * @param s [IN]  The C-string to search.
02118    * @param e [IN]  The regular expression to search for.
02119    * @param f [IN]  Search policy flags.
02120    * @retval true  A match was found within the string.
02121    * @retval false No match was found within the string.
02122    * @doctodo
02123    *
02124    * @throws an exception of type regex_error.
02125    */
02126   template<typename _Ch_type, typename _Rx_traits>
02127     inline bool
02128     regex_search(const _Ch_type* __s,
02129          const basic_regex<_Ch_type, _Rx_traits>& __e,
02130          regex_constants::match_flag_type __f
02131          = regex_constants::match_default)
02132     { return regex_search(__s, __s + _Rx_traits::length(__s), __e, __f); }
02133 
02134   /**
02135    * @brief Searches for a regular expression within a string.
02136    * @param s     [IN]  The string to search.
02137    * @param e     [IN]  The regular expression to search for.
02138    * @param flags [IN]  Search policy flags.
02139    * @retval true  A match was found within the string.
02140    * @retval false No match was found within the string.
02141    * @doctodo
02142    *
02143    * @throws an exception of type regex_error.
02144    */
02145   template<typename _Ch_traits, typename _String_allocator,
02146        typename _Ch_type, typename _Rx_traits>
02147     inline bool
02148     regex_search(const basic_string<_Ch_type, _Ch_traits,
02149          _String_allocator>& __s,
02150          const basic_regex<_Ch_type, _Rx_traits>& __e,
02151          regex_constants::match_flag_type __flags
02152          = regex_constants::match_default)
02153     { return regex_search(__s.begin(), __s.end(), __e, __flags); }
02154 
02155   /**
02156    * @brief Searches for a regular expression within a string.
02157    * @param s [IN]  A C++ string to search for the regex.
02158    * @param m [OUT] The set of regex matches.
02159    * @param e [IN]  The regex to search for in @p s.
02160    * @param f [IN]  The search flags.
02161    * @retval true  A match was found within the string.
02162    * @retval false No match was found within the string, the content of %m is
02163    *               undefined.
02164    *
02165    * @throws an exception of type regex_error.
02166    */
02167   template<typename _Ch_traits, typename _Ch_alloc,
02168        typename _Allocator, typename _Ch_type,
02169        typename _Rx_traits>
02170     inline bool
02171     regex_search(const basic_string<_Ch_type, _Ch_traits, _Ch_alloc>& __s,
02172          match_results<typename basic_string<_Ch_type,
02173          _Ch_traits, _Ch_alloc>::const_iterator, _Allocator>& __m,
02174          const basic_regex<_Ch_type, _Rx_traits>& __e,
02175          regex_constants::match_flag_type __f
02176          = regex_constants::match_default)
02177     { return regex_search(__s.begin(), __s.end(), __m, __e, __f); }
02178 
02179   // std [28.11.4] Function template regex_replace
02180   /**
02181    * @doctodo
02182    * @param out
02183    * @param first
02184    * @param last
02185    * @param e
02186    * @param fmt
02187    * @param flags
02188    *
02189    * @returns out
02190    * @throws an exception of type regex_error.
02191    *
02192    * @todo Implement this function.
02193    */
02194   template<typename _Out_iter, typename _Bi_iter,
02195        typename _Rx_traits, typename _Ch_type>
02196     inline _Out_iter
02197     regex_replace(_Out_iter __out, _Bi_iter __first, _Bi_iter __last,
02198           const basic_regex<_Ch_type, _Rx_traits>& __e,
02199           const basic_string<_Ch_type>& __fmt,
02200           regex_constants::match_flag_type __flags
02201           = regex_constants::match_default)
02202     { return __out; }
02203 
02204   /**
02205    * @doctodo
02206    * @param s
02207    * @param e
02208    * @param fmt
02209    * @param flags
02210    *
02211    * @returns a copy of string @p s with replacements.
02212    *
02213    * @throws an exception of type regex_error.
02214    */
02215   template<typename _Rx_traits, typename _Ch_type>
02216     inline basic_string<_Ch_type>
02217     regex_replace(const basic_string<_Ch_type>& __s,
02218           const basic_regex<_Ch_type, _Rx_traits>& __e,
02219           const basic_string<_Ch_type>& __fmt,
02220           regex_constants::match_flag_type __flags
02221           = regex_constants::match_default)
02222     {
02223       std::string __result;
02224       regex_replace(std::back_inserter(__result),
02225             __s.begin(), __s.end(), __e, __fmt, __flags);
02226       return __result;
02227     }
02228 
02229   //@}
02230 
02231   // std [28.12] Class template regex_iterator
02232   /**
02233    * An iterator adaptor that will provide repeated calls of regex_search over 
02234    * a range until no more matches remain.
02235    */
02236   template<typename _Bi_iter,
02237        typename _Ch_type = typename iterator_traits<_Bi_iter>::value_type,
02238        typename _Rx_traits = regex_traits<_Ch_type> >
02239     class regex_iterator
02240     {
02241     public:
02242       typedef basic_regex<_Ch_type, _Rx_traits>  regex_type;
02243       typedef match_results<_Bi_iter>            value_type;
02244       typedef std::ptrdiff_t                     difference_type;
02245       typedef const value_type*                  pointer;
02246       typedef const value_type&                  reference;
02247       typedef std::forward_iterator_tag          iterator_category;
02248 
02249     public:
02250       /**
02251        * @brief Provides a singular iterator, useful for indicating
02252        * one-past-the-end of a range.
02253        * @todo Implement this function.
02254        * @doctodo
02255        */
02256       regex_iterator();
02257       
02258       /**
02259        * Constructs a %regex_iterator...
02260        * @param a  [IN] The start of a text range to search.
02261        * @param b  [IN] One-past-the-end of the text range to search.
02262        * @param re [IN] The regular expression to match.
02263        * @param m  [IN] Policy flags for match rules.
02264        * @todo Implement this function.
02265        * @doctodo
02266        */
02267       regex_iterator(_Bi_iter __a, _Bi_iter __b, const regex_type& __re,
02268              regex_constants::match_flag_type __m
02269              = regex_constants::match_default);
02270 
02271       /**
02272        * Copy constructs a %regex_iterator.
02273        * @todo Implement this function.
02274        * @doctodo
02275        */
02276       regex_iterator(const regex_iterator& __rhs);
02277       
02278       /**
02279        * @todo Implement this function.
02280        * @doctodo
02281        */
02282       regex_iterator&
02283       operator=(const regex_iterator& __rhs);
02284       
02285       /**
02286        * @todo Implement this function.
02287        * @doctodo
02288        */
02289       bool
02290       operator==(const regex_iterator& __rhs);
02291       
02292       /**
02293        * @todo Implement this function.
02294        * @doctodo
02295        */
02296       bool
02297       operator!=(const regex_iterator& __rhs);
02298       
02299       /**
02300        * @todo Implement this function.
02301        * @doctodo
02302        */
02303       const value_type&
02304       operator*();
02305       
02306       /**
02307        * @todo Implement this function.
02308        * @doctodo
02309        */
02310       const value_type*
02311       operator->();
02312       
02313       /**
02314        * @todo Implement this function.
02315        * @doctodo
02316        */
02317       regex_iterator&
02318       operator++();
02319       
02320       /**
02321        * @todo Implement this function.
02322        * @doctodo
02323        */
02324       regex_iterator
02325       operator++(int);
02326       
02327     private:
02328       // these members are shown for exposition only:
02329       _Bi_iter                         begin;
02330       _Bi_iter                         end;
02331       const regex_type*                pregex;
02332       regex_constants::match_flag_type flags;
02333       match_results<_Bi_iter>          match;
02334     };
02335   
02336   typedef regex_iterator<const char*>             cregex_iterator;
02337   typedef regex_iterator<string::const_iterator>  sregex_iterator;
02338 #ifdef _GLIBCXX_USE_WCHAR_T
02339   typedef regex_iterator<const wchar_t*>          wcregex_iterator;
02340   typedef regex_iterator<wstring::const_iterator> wsregex_iterator;
02341 #endif
02342 
02343   // [7.12.2] Class template regex_token_iterator
02344   /**
02345    * Iterates over submatches in a range (or @a splits a text string).
02346    *
02347    * The purpose of this iterator is to enumerate all, or all specified,
02348    * matches of a regular expression within a text range.  The dereferenced
02349    * value of an iterator of this class is a std::sub_match object.
02350    */
02351   template<typename _Bi_iter,
02352        typename _Ch_type = typename iterator_traits<_Bi_iter>::value_type,
02353        typename _Rx_traits = regex_traits<_Ch_type> >
02354     class regex_token_iterator
02355     {
02356     public:
02357       typedef basic_regex<_Ch_type, _Rx_traits> regex_type;
02358       typedef sub_match<_Bi_iter>               value_type;
02359       typedef std::ptrdiff_t                    difference_type;
02360       typedef const value_type*                 pointer;
02361       typedef const value_type&                 reference;
02362       typedef std::forward_iterator_tag         iterator_category;
02363       
02364     public:
02365       /**
02366        * @brief Default constructs a %regex_token_iterator.
02367        * @todo Implement this function.
02368        * 
02369        * A default-constructed %regex_token_iterator is a singular iterator
02370        * that will compare equal to the one-past-the-end value for any
02371        * iterator of the same type.
02372        */
02373       regex_token_iterator();
02374       
02375       /**
02376        * Constructs a %regex_token_iterator...
02377        * @param a          [IN] The start of the text to search.
02378        * @param b          [IN] One-past-the-end of the text to search.
02379        * @param re         [IN] The regular expression to search for.
02380        * @param submatch   [IN] Which submatch to return.  There are some
02381        *                        special values for this parameter:
02382        *                        - -1 each enumerated subexpression does NOT
02383        *                          match the regular expression (aka field
02384        *                          splitting)
02385        *                        - 0 the entire string matching the
02386        *                          subexpression is returned for each match
02387        *                          within the text.
02388        *                        - >0 enumerates only the indicated
02389        *                          subexpression from a match within the text.
02390        * @param m          [IN] Policy flags for match rules.
02391        *
02392        * @todo Implement this function.
02393        * @doctodo
02394        */
02395       regex_token_iterator(_Bi_iter __a, _Bi_iter __b, const regex_type& __re,
02396                int __submatch = 0,
02397                regex_constants::match_flag_type __m
02398                = regex_constants::match_default);
02399 
02400       /**
02401        * Constructs a %regex_token_iterator...
02402        * @param a          [IN] The start of the text to search.
02403        * @param b          [IN] One-past-the-end of the text to search.
02404        * @param re         [IN] The regular expression to search for.
02405        * @param submatches [IN] A list of subexpressions to return for each
02406        *                        regular expression match within the text.
02407        * @param m          [IN] Policy flags for match rules.
02408        *
02409        * @todo Implement this function.
02410        * @doctodo
02411        */
02412       regex_token_iterator(_Bi_iter __a, _Bi_iter __b,
02413                const regex_type& __re,
02414                const std::vector<int>& __submatches,
02415                regex_constants::match_flag_type __m
02416                  = regex_constants::match_default);
02417 
02418       /**
02419        * Constructs a %regex_token_iterator...
02420        * @param a          [IN] The start of the text to search.
02421        * @param b          [IN] One-past-the-end of the text to search.
02422        * @param re         [IN] The regular expression to search for.
02423        * @param submatches [IN] A list of subexpressions to return for each
02424        *                        regular expression match within the text.
02425        * @param m          [IN] Policy flags for match rules.
02426        
02427        * @todo Implement this function.
02428        * @doctodo
02429        */
02430       template<std::size_t _Nm>
02431         regex_token_iterator(_Bi_iter __a, _Bi_iter __b,
02432                  const regex_type& __re,
02433                  const int (&__submatches)[_Nm],
02434                  regex_constants::match_flag_type __m
02435                  = regex_constants::match_default);
02436 
02437       /**
02438        * @brief Copy constructs a %regex_token_iterator.
02439        * @param rhs [IN] A %regex_token_iterator to copy.
02440        * @todo Implement this function.
02441        */
02442       regex_token_iterator(const regex_token_iterator& __rhs);
02443       
02444       /**
02445        * @brief Assigns a %regex_token_iterator to another.
02446        * @param rhs [IN] A %regex_token_iterator to copy.
02447        * @todo Implement this function.
02448        */
02449       regex_token_iterator&
02450       operator=(const regex_token_iterator& __rhs);
02451       
02452       /**
02453        * @brief Compares a %regex_token_iterator to another for equality.
02454        * @todo Implement this function.
02455        */
02456       bool
02457       operator==(const regex_token_iterator& __rhs);
02458       
02459       /**
02460        * @brief Compares a %regex_token_iterator to another for inequality.
02461        * @todo Implement this function.
02462        */
02463       bool
02464       operator!=(const regex_token_iterator& __rhs);
02465       
02466       /**
02467        * @brief Dereferences a %regex_token_iterator.
02468        * @todo Implement this function.
02469        */
02470       const value_type&
02471       operator*();
02472       
02473       /**
02474        * @brief Selects a %regex_token_iterator member.
02475        * @todo Implement this function.
02476        */
02477       const value_type*
02478       operator->();
02479       
02480       /**
02481        * @brief Increments a %regex_token_iterator.
02482        * @todo Implement this function.
02483        */
02484       regex_token_iterator&
02485       operator++();
02486       
02487       /**
02488        * @brief Postincrements a %regex_token_iterator.
02489        * @todo Implement this function.
02490        */
02491       regex_token_iterator
02492       operator++(int);
02493       
02494     private: // data members for exposition only:
02495       typedef regex_iterator<_Bi_iter, _Ch_type, _Rx_traits> position_iterator;
02496 
02497       position_iterator __position;
02498       const value_type* __result;
02499       value_type        __suffix;
02500       std::size_t       __n;
02501       std::vector<int>  __subs;
02502     };
02503 
02504   /** @brief Token iterator for C-style NULL-terminated strings. */
02505   typedef regex_token_iterator<const char*>             cregex_token_iterator;
02506   /** @brief Token iterator for standard strings. */
02507   typedef regex_token_iterator<string::const_iterator>  sregex_token_iterator;
02508 #ifdef _GLIBCXX_USE_WCHAR_T
02509   /** @brief Token iterator for C-style NULL-terminated wide strings. */
02510   typedef regex_token_iterator<const wchar_t*>          wcregex_token_iterator;
02511   /** @brief Token iterator for standard wide-character strings. */
02512   typedef regex_token_iterator<wstring::const_iterator> wsregex_token_iterator;
02513 #endif
02514   
02515   //@} // group regex
02516 _GLIBCXX_END_NAMESPACE_VERSION
02517 } // namespace
02518