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<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<sub_match<_Bi_iter>, _Allocator>    _Base_type;
01477 
01478     public:
01479       /**
01480        * @name 10.? Public Types
01481        */
01482       //@{
01483       typedef sub_match<_Bi_iter>                             value_type;
01484       typedef const value_type&                               const_reference;
01485       typedef const_reference                                 reference;
01486       typedef typename _Base_type::const_iterator             const_iterator;
01487       typedef const_iterator                                  iterator;
01488       typedef typename std::iterator_traits<_Bi_iter>::difference_type
01489                                                               difference_type;
01490       /* TODO: needs allocator_traits */
01491       typedef typename _Allocator::size_type                  size_type;
01492       typedef _Allocator                                      allocator_type;
01493       typedef typename std::iterator_traits<_Bi_iter>::value_type
01494                                                               char_type;
01495       typedef std::basic_string<char_type>                    string_type;
01496       //@}
01497   
01498     public:
01499       /**
01500        * @name 28.10.1 Construction, Copying, and Destruction
01501        */
01502       //@{
01503 
01504       /**
01505        * @brief Constructs a default %match_results container.
01506        * @post size() returns 0 and str() returns an empty string.
01507        */
01508       explicit
01509       match_results(const _Allocator& __a = _Allocator())
01510       : _Base_type(__a)
01511       { }
01512 
01513       /**
01514        * @brief Copy constructs a %match_results.
01515        */
01516       match_results(const match_results& __rhs)
01517       : _Base_type(__rhs)
01518       { }
01519 
01520       /**
01521        * @brief Move constructs a %match_results.
01522        */
01523       match_results(match_results&& __rhs) noexcept
01524       : _Base_type(std::move(__rhs))
01525       { }
01526 
01527       /**
01528        * @brief Assigns rhs to *this.
01529        */
01530       match_results&
01531       operator=(const match_results& __rhs)
01532       {
01533     match_results(__rhs).swap(*this);
01534     return *this;
01535       }
01536 
01537       /**
01538        * @brief Move-assigns rhs to *this.
01539        */
01540       match_results&
01541       operator=(match_results&& __rhs)
01542       {
01543     match_results(std::move(__rhs)).swap(*this);
01544     return *this;
01545       }
01546 
01547       /**
01548        * @brief Destroys a %match_results object.
01549        */
01550       ~match_results()
01551       { }
01552       
01553       //@}
01554 
01555       // 28.10.2, state:
01556       /**
01557        * @brief Indicates if the %match_results is ready.
01558        * @retval true   The object has a fully-established result state.
01559        * @retval false  The object is not ready.
01560        */
01561       bool ready() const { return !_Base_type::empty(); }
01562 
01563       /**
01564        * @name 28.10.2 Size
01565        */
01566       //@{
01567 
01568       /**
01569        * @brief Gets the number of matches and submatches.
01570        *
01571        * The number of matches for a given regular expression will be either 0
01572        * if there was no match or mark_count() + 1 if a match was successful.
01573        * Some matches may be empty.
01574        *
01575        * @returns the number of matches found.
01576        */
01577       size_type
01578       size() const
01579       {
01580         size_type __size = _Base_type::size();
01581         return (__size && _Base_type::operator[](0).matched) ? __size - 2 : 0;
01582       }
01583       
01584       size_type
01585       max_size() const
01586       { return _Base_type::max_size(); }
01587 
01588       /**
01589        * @brief Indicates if the %match_results contains no results.
01590        * @retval true The %match_results object is empty.
01591        * @retval false The %match_results object is not empty.
01592        */
01593       bool
01594       empty() const
01595       { return size() == 0; }
01596       
01597       //@}
01598 
01599       /**
01600        * @name 10.3 Element Access
01601        */
01602       //@{
01603 
01604       /**
01605        * @brief Gets the length of the indicated submatch.
01606        * @param sub indicates the submatch.
01607        * @pre   ready() == true
01608        *
01609        * This function returns the length of the indicated submatch, or the
01610        * length of the entire match if @p sub is zero (the default).
01611        */
01612       difference_type
01613       length(size_type __sub = 0) const
01614       { return (*this)[__sub].length(); }
01615 
01616       /**
01617        * @brief Gets the offset of the beginning of the indicated submatch.
01618        * @param sub indicates the submatch.
01619        * @pre   ready() == true
01620        *
01621        * This function returns the offset from the beginning of the target
01622        * sequence to the beginning of the submatch, unless the value of @p sub
01623        * is zero (the default), in which case this function returns the offset
01624        * from the beginning of the target sequence to the beginning of the
01625        * match.
01626        *
01627        * Returns -1 if @p sub is out of range.
01628        */
01629       difference_type
01630       position(size_type __sub = 0) const
01631       {
01632     return __sub < size() ? std::distance(this->prefix().first,
01633                           (*this)[__sub].first) : -1;
01634       }
01635 
01636       /**
01637        * @brief Gets the match or submatch converted to a string type.
01638        * @param sub indicates the submatch.
01639        * @pre   ready() == true
01640        *
01641        * This function gets the submatch (or match, if @p sub is zero) extracted
01642        * from the target range and converted to the associated string type.
01643        */
01644       string_type
01645       str(size_type __sub = 0) const
01646       { return (*this)[__sub].str(); }
01647       
01648       /**
01649        * @brief Gets a %sub_match reference for the match or submatch.
01650        * @param sub indicates the submatch.
01651        * @pre   ready() == true
01652        *
01653        * This function gets a reference to the indicated submatch, or the entire
01654        * match if @p sub is zero.
01655        *
01656        * If @p sub >= size() then this function returns a %sub_match with a
01657        * special value indicating no submatch.
01658        */
01659       const_reference
01660       operator[](size_type __sub) const
01661       { 
01662         _GLIBCXX_DEBUG_ASSERT( ready() );
01663         return __sub < size()
01664            ?  _Base_type::operator[](__sub)
01665            : __unmatched_sub<_Bi_iter>();
01666       }
01667 
01668       /**
01669        * @brief Gets a %sub_match representing the match prefix.
01670        * @pre   ready() == true
01671        *
01672        * This function gets a reference to a %sub_match object representing the
01673        * part of the target range between the start of the target range and the
01674        * start of the match.
01675        */
01676       const_reference
01677       prefix() const
01678       {
01679         _GLIBCXX_DEBUG_ASSERT( ready() );
01680         return !empty()
01681                ? _Base_type::operator[](_Base_type::size() - 2)
01682            : __unmatched_sub<_Bi_iter>();
01683       }
01684 
01685       /**
01686        * @brief Gets a %sub_match representing the match suffix.
01687        * @pre   ready() == true
01688        *
01689        * This function gets a reference to a %sub_match object representing the
01690        * part of the target range between the end of the match and the end of
01691        * the target range.
01692        */
01693       const_reference
01694       suffix() const
01695       {
01696     _GLIBCXX_DEBUG_ASSERT( ready() );
01697     return !empty()
01698            ? _Base_type::operator[](_Base_type::size() - 1)
01699            : __unmatched_sub<_Bi_iter>();
01700       }
01701 
01702       /**
01703        * @brief Gets an iterator to the start of the %sub_match collection.
01704        */
01705       const_iterator
01706       begin() const
01707       { return _Base_type::begin(); }
01708       
01709       /**
01710        * @brief Gets an iterator to the start of the %sub_match collection.
01711        */
01712       const_iterator
01713       cbegin() const
01714       { return _Base_type::cbegin(); }
01715 
01716       /**
01717        * @brief Gets an iterator to one-past-the-end of the collection.
01718        */
01719       const_iterator
01720       end() const
01721       { return !empty() ? _Base_type::end() - 2 : _Base_type::end(); }
01722       
01723       /**
01724        * @brief Gets an iterator to one-past-the-end of the collection.
01725        */
01726       const_iterator
01727       cend() const
01728       { return end(); }
01729 
01730       //@}
01731 
01732       /**
01733        * @name 10.4 Formatting
01734        *
01735        * These functions perform formatted substitution of the matched
01736        * character sequences into their target.  The format specifiers and
01737        * escape sequences accepted by these functions are determined by
01738        * their @p flags parameter as documented above.
01739        */
01740        //@{
01741 
01742       /**
01743        * @pre   ready() == true
01744        * @todo Implement this function.
01745        */
01746       template<typename _Out_iter>
01747         _Out_iter
01748         format(_Out_iter __out, const char_type* __fmt_first,
01749            const char_type* __fmt_last,
01750            regex_constants::match_flag_type __flags
01751            = regex_constants::format_default) const
01752         { return __out; }
01753 
01754       /**
01755        * @pre   ready() == true
01756        */
01757       template<typename _Out_iter, typename _St, typename _Sa>
01758         _Out_iter
01759         format(_Out_iter __out, const basic_string<char_type, _St, _Sa>& __fmt,
01760            regex_constants::match_flag_type __flags
01761            = regex_constants::format_default) const
01762         {
01763           return format(__out, __fmt.data(), __fmt.data() + __fmt.size(),
01764                         __flags);
01765         }
01766 
01767       /**
01768        * @pre   ready() == true
01769        */
01770       template<typename _Out_iter, typename _St, typename _Sa>
01771         basic_string<char_type, _St, _Sa>
01772         format(const basic_string<char_type, _St, _Sa>& __fmt,
01773            regex_constants::match_flag_type __flags
01774            = regex_constants::format_default) const
01775         {
01776           basic_string<char_type, _St, _Sa> __result;
01777           format(std::back_inserter(__result), __fmt, __flags);
01778           return __result;
01779         }
01780 
01781       /**
01782        * @pre   ready() == true
01783        */
01784       string_type
01785       format(const char_type* __fmt,
01786          regex_constants::match_flag_type __flags
01787          = regex_constants::format_default) const
01788       {
01789         string_type __result;
01790         format(std::back_inserter(__result),
01791                __fmt + char_traits<char_type>::length(__fmt),
01792                __flags);
01793         return __result;
01794       }
01795 
01796       //@} 
01797 
01798       /**
01799        * @name 10.5 Allocator
01800        */
01801       //@{ 
01802 
01803       /**
01804        * @brief Gets a copy of the allocator.
01805        */
01806       allocator_type
01807       get_allocator() const
01808       { return _Base_type::get_allocator(); }
01809       
01810       //@} 
01811 
01812       /**
01813        * @name 10.6 Swap
01814        */
01815        //@{ 
01816 
01817       /**
01818        * @brief Swaps the contents of two match_results.
01819        */
01820       void
01821       swap(match_results& __that)
01822       { _Base_type::swap(__that); }
01823       //@} 
01824       
01825     private:
01826       friend class __regex::_SpecializedResults<_Bi_iter, _Allocator>;
01827     };
01828   
01829   typedef match_results<const char*>             cmatch;
01830   typedef match_results<string::const_iterator>  smatch;
01831 #ifdef _GLIBCXX_USE_WCHAR_T
01832   typedef match_results<const wchar_t*>          wcmatch;
01833   typedef match_results<wstring::const_iterator> wsmatch;
01834 #endif
01835 
01836   // match_results comparisons
01837   /**
01838    * @brief Compares two match_results for equality.
01839    * @returns true if the two objects refer to the same match,
01840    * false otherwise.
01841    */
01842   template<typename _Bi_iter, typename _Allocator>
01843     inline bool
01844     operator==(const match_results<_Bi_iter, _Allocator>& __m1,
01845            const match_results<_Bi_iter, _Allocator>& __m2)
01846     {
01847       if (__m1.ready() != __m2.ready())
01848         return false;
01849       if (!__m1.ready())  // both are not ready
01850         return true;
01851       if (__m1.empty() != __m2.empty())
01852         return false;
01853       if (__m1.empty())   // both are empty
01854         return true;
01855       return __m1.prefix() == __m2.prefix()
01856         && __m1.size() == __m2.size()
01857         && std::equal(__m1.begin(), __m1.end(), __m2.begin())
01858         && __m1.suffix() == __m2.suffix();
01859     }
01860 
01861   /**
01862    * @brief Compares two match_results for inequality.
01863    * @returns true if the two objects do not refer to the same match,
01864    * false otherwise.
01865    */
01866   template<typename _Bi_iter, class _Allocator>
01867     inline bool
01868     operator!=(const match_results<_Bi_iter, _Allocator>& __m1,
01869            const match_results<_Bi_iter, _Allocator>& __m2)
01870     { return !(__m1 == __m2); }
01871 
01872   // [7.10.6] match_results swap
01873   /**
01874    * @brief Swaps two match results.
01875    * @param lhs A match result.
01876    * @param rhs A match result.
01877    *
01878    * The contents of the two match_results objects are swapped.
01879    */
01880   template<typename _Bi_iter, typename _Allocator>
01881     inline void
01882     swap(match_results<_Bi_iter, _Allocator>& __lhs,
01883      match_results<_Bi_iter, _Allocator>& __rhs)
01884     { __lhs.swap(__rhs); }
01885 
01886   // [7.11.2] Function template regex_match
01887   /**
01888    * @name Matching, Searching, and Replacing
01889    */
01890   //@{
01891 
01892   /**
01893    * @brief Determines if there is a match between the regular expression @p e
01894    * and all of the character sequence [first, last).
01895    *
01896    * @param s     Start of the character sequence to match.
01897    * @param e     One-past-the-end of the character sequence to match.
01898    * @param m     The match results.
01899    * @param re    The regular expression.
01900    * @param flags Controls how the regular expression is matched.
01901    *
01902    * @retval true  A match exists.
01903    * @retval false Otherwise.
01904    *
01905    * @throws an exception of type regex_error.
01906    *
01907    * @todo Implement this function.
01908    */
01909   template<typename _Bi_iter, typename _Allocator,
01910        typename _Ch_type, typename _Rx_traits>
01911     bool
01912     regex_match(_Bi_iter                                 __s,
01913                 _Bi_iter                                 __e,
01914                 match_results<_Bi_iter, _Allocator>&     __m,
01915                 const basic_regex<_Ch_type, _Rx_traits>& __re,
01916                 regex_constants::match_flag_type         __flags
01917                                = regex_constants::match_default)
01918     {
01919       __regex::_AutomatonPtr __a = __re._M_get_automaton();
01920       __regex::_Automaton::_SizeT __sz = __a->_M_sub_count();
01921       __regex::_SpecializedCursor<_Bi_iter> __cs(__s, __e);
01922       __regex::_SpecializedResults<_Bi_iter, _Allocator> __r(__sz, __cs, __m);
01923       __regex::_Grep_matcher __matcher(__cs, __r, __a, __flags);
01924       return __m[0].matched;
01925     }
01926 
01927   /**
01928    * @brief Indicates if there is a match between the regular expression @p e
01929    * and all of the character sequence [first, last).
01930    *
01931    * @param first Beginning of the character sequence to match.
01932    * @param last  One-past-the-end of the character sequence to match.
01933    * @param re    The regular expression.
01934    * @param flags Controls how the regular expression is matched.
01935    *
01936    * @retval true  A match exists.
01937    * @retval false Otherwise.
01938    *
01939    * @throws an exception of type regex_error.
01940    */
01941   template<typename _Bi_iter, typename _Ch_type, typename _Rx_traits>
01942     bool
01943     regex_match(_Bi_iter __first, _Bi_iter __last,
01944         const basic_regex<_Ch_type, _Rx_traits>& __re,
01945         regex_constants::match_flag_type __flags
01946         = regex_constants::match_default)
01947     { 
01948       match_results<_Bi_iter> __what;
01949       return regex_match(__first, __last, __what, __re, __flags);
01950     }
01951 
01952   /**
01953    * @brief Determines if there is a match between the regular expression @p e
01954    * and a C-style null-terminated string.
01955    *
01956    * @param s  The C-style null-terminated string to match.
01957    * @param m  The match results.
01958    * @param re The regular expression.
01959    * @param f  Controls how the regular expression is matched.
01960    *
01961    * @retval true  A match exists.
01962    * @retval false Otherwise.
01963    *
01964    * @throws an exception of type regex_error.
01965    */
01966   template<typename _Ch_type, typename _Allocator, typename _Rx_traits>
01967     inline bool
01968     regex_match(const _Ch_type* __s,
01969         match_results<const _Ch_type*, _Allocator>& __m,
01970         const basic_regex<_Ch_type, _Rx_traits>& __re,
01971         regex_constants::match_flag_type __f
01972         = regex_constants::match_default)
01973     { return regex_match(__s, __s + _Rx_traits::length(__s), __m, __re, __f); }
01974 
01975   /**
01976    * @brief Determines if there is a match between the regular expression @p e
01977    * and a string.
01978    *
01979    * @param s     The string to match.
01980    * @param m     The match results.
01981    * @param re    The regular expression.
01982    * @param flags Controls how the regular expression is matched.
01983    *
01984    * @retval true  A match exists.
01985    * @retval false Otherwise.
01986    *
01987    * @throws an exception of type regex_error.
01988    */
01989   template<typename _Ch_traits, typename _Ch_alloc,
01990        typename _Allocator, typename _Ch_type, typename _Rx_traits>
01991     inline bool
01992     regex_match(const basic_string<_Ch_type, _Ch_traits, _Ch_alloc>& __s,
01993         match_results<typename basic_string<_Ch_type, 
01994         _Ch_traits, _Ch_alloc>::const_iterator, _Allocator>& __m,
01995         const basic_regex<_Ch_type, _Rx_traits>& __re,
01996         regex_constants::match_flag_type __flags
01997         = regex_constants::match_default)
01998     { return regex_match(__s.begin(), __s.end(), __m, __re, __flags); }
01999 
02000   /**
02001    * @brief Indicates if there is a match between the regular expression @p e
02002    * and a C-style null-terminated string.
02003    *
02004    * @param s  The C-style null-terminated string to match.
02005    * @param re The regular expression.
02006    * @param f  Controls how the regular expression is matched.
02007    *
02008    * @retval true  A match exists.
02009    * @retval false Otherwise.
02010    *
02011    * @throws an exception of type regex_error.
02012    */
02013   template<typename _Ch_type, class _Rx_traits>
02014     inline bool
02015     regex_match(const _Ch_type* __s,
02016         const basic_regex<_Ch_type, _Rx_traits>& __re,
02017         regex_constants::match_flag_type __f
02018         = regex_constants::match_default)
02019     { return regex_match(__s, __s + _Rx_traits::length(__s), __re, __f); }
02020 
02021   /**
02022    * @brief Indicates if there is a match between the regular expression @p e
02023    * and a string.
02024    *
02025    * @param s     [IN] The string to match.
02026    * @param re    [IN] The regular expression.
02027    * @param flags [IN] Controls how the regular expression is matched.
02028    *
02029    * @retval true  A match exists.
02030    * @retval false Otherwise.
02031    *
02032    * @throws an exception of type regex_error.
02033    */
02034   template<typename _Ch_traits, typename _Str_allocator,
02035        typename _Ch_type, typename _Rx_traits>
02036     inline bool
02037     regex_match(const basic_string<_Ch_type, _Ch_traits, _Str_allocator>& __s,
02038         const basic_regex<_Ch_type, _Rx_traits>& __re,
02039         regex_constants::match_flag_type __flags
02040         = regex_constants::match_default)
02041     { return regex_match(__s.begin(), __s.end(), __re, __flags); }
02042 
02043   // [7.11.3] Function template regex_search
02044   /**
02045    * Searches for a regular expression within a range.
02046    * @param first [IN]  The start of the string to search.
02047    * @param last  [IN]  One-past-the-end of the string to search.
02048    * @param m     [OUT] The match results.
02049    * @param re    [IN]  The regular expression to search for.
02050    * @param flags [IN]  Search policy flags.
02051    * @retval true  A match was found within the string.
02052    * @retval false No match was found within the string, the content of %m is
02053    *               undefined.
02054    *
02055    * @throws an exception of type regex_error.
02056    *
02057    * @todo Implement this function.
02058    */
02059   template<typename _Bi_iter, typename _Allocator,
02060        typename _Ch_type, typename _Rx_traits>
02061     inline bool
02062     regex_search(_Bi_iter __first, _Bi_iter __last,
02063          match_results<_Bi_iter, _Allocator>& __m,
02064          const basic_regex<_Ch_type, _Rx_traits>& __re,
02065          regex_constants::match_flag_type __flags
02066          = regex_constants::match_default)
02067     { return false; }
02068 
02069   /**
02070    * Searches for a regular expression within a range.
02071    * @param first [IN]  The start of the string to search.
02072    * @param last  [IN]  One-past-the-end of the string to search.
02073    * @param re    [IN]  The regular expression to search for.
02074    * @param flags [IN]  Search policy flags.
02075    * @retval true  A match was found within the string.
02076    * @retval false No match was found within the string.
02077    * @doctodo
02078    *
02079    * @throws an exception of type regex_error.
02080    */
02081   template<typename _Bi_iter, typename _Ch_type, typename _Rx_traits>
02082     inline bool
02083     regex_search(_Bi_iter __first, _Bi_iter __last,
02084          const basic_regex<_Ch_type, _Rx_traits>& __re,
02085          regex_constants::match_flag_type __flags
02086          = regex_constants::match_default)
02087     {
02088       match_results<_Bi_iter> __what;
02089       return regex_search(__first, __last, __what, __re, __flags);
02090     }
02091 
02092   /**
02093    * @brief Searches for a regular expression within a C-string.
02094    * @param s [IN]  A C-string to search for the regex.
02095    * @param m [OUT] The set of regex matches.
02096    * @param e [IN]  The regex to search for in @p s.
02097    * @param f [IN]  The search flags.
02098    * @retval true  A match was found within the string.
02099    * @retval false No match was found within the string, the content of %m is
02100    *               undefined.
02101    * @doctodo
02102    *
02103    * @throws an exception of type regex_error.
02104    */
02105   template<typename _Ch_type, class _Allocator, class _Rx_traits>
02106     inline bool
02107     regex_search(const _Ch_type* __s,
02108          match_results<const _Ch_type*, _Allocator>& __m,
02109          const basic_regex<_Ch_type, _Rx_traits>& __e,
02110          regex_constants::match_flag_type __f
02111          = regex_constants::match_default)
02112     { return regex_search(__s, __s + _Rx_traits::length(__s), __m, __e, __f); }
02113 
02114   /**
02115    * @brief Searches for a regular expression within a C-string.
02116    * @param s [IN]  The C-string to search.
02117    * @param e [IN]  The regular expression to search for.
02118    * @param f [IN]  Search policy flags.
02119    * @retval true  A match was found within the string.
02120    * @retval false No match was found within the string.
02121    * @doctodo
02122    *
02123    * @throws an exception of type regex_error.
02124    */
02125   template<typename _Ch_type, typename _Rx_traits>
02126     inline bool
02127     regex_search(const _Ch_type* __s,
02128          const basic_regex<_Ch_type, _Rx_traits>& __e,
02129          regex_constants::match_flag_type __f
02130          = regex_constants::match_default)
02131     { return regex_search(__s, __s + _Rx_traits::length(__s), __e, __f); }
02132 
02133   /**
02134    * @brief Searches for a regular expression within a string.
02135    * @param s     [IN]  The string to search.
02136    * @param e     [IN]  The regular expression to search for.
02137    * @param flags [IN]  Search policy flags.
02138    * @retval true  A match was found within the string.
02139    * @retval false No match was found within the string.
02140    * @doctodo
02141    *
02142    * @throws an exception of type regex_error.
02143    */
02144   template<typename _Ch_traits, typename _String_allocator,
02145        typename _Ch_type, typename _Rx_traits>
02146     inline bool
02147     regex_search(const basic_string<_Ch_type, _Ch_traits,
02148          _String_allocator>& __s,
02149          const basic_regex<_Ch_type, _Rx_traits>& __e,
02150          regex_constants::match_flag_type __flags
02151          = regex_constants::match_default)
02152     { return regex_search(__s.begin(), __s.end(), __e, __flags); }
02153 
02154   /**
02155    * @brief Searches for a regular expression within a string.
02156    * @param s [IN]  A C++ string to search for the regex.
02157    * @param m [OUT] The set of regex matches.
02158    * @param e [IN]  The regex to search for in @p s.
02159    * @param f [IN]  The search flags.
02160    * @retval true  A match was found within the string.
02161    * @retval false No match was found within the string, the content of %m is
02162    *               undefined.
02163    *
02164    * @throws an exception of type regex_error.
02165    */
02166   template<typename _Ch_traits, typename _Ch_alloc,
02167        typename _Allocator, typename _Ch_type,
02168        typename _Rx_traits>
02169     inline bool
02170     regex_search(const basic_string<_Ch_type, _Ch_traits, _Ch_alloc>& __s,
02171          match_results<typename basic_string<_Ch_type,
02172          _Ch_traits, _Ch_alloc>::const_iterator, _Allocator>& __m,
02173          const basic_regex<_Ch_type, _Rx_traits>& __e,
02174          regex_constants::match_flag_type __f
02175          = regex_constants::match_default)
02176     { return regex_search(__s.begin(), __s.end(), __m, __e, __f); }
02177 
02178   // std [28.11.4] Function template regex_replace
02179   /**
02180    * @doctodo
02181    * @param out
02182    * @param first
02183    * @param last
02184    * @param e
02185    * @param fmt
02186    * @param flags
02187    *
02188    * @returns out
02189    * @throws an exception of type regex_error.
02190    *
02191    * @todo Implement this function.
02192    */
02193   template<typename _Out_iter, typename _Bi_iter,
02194        typename _Rx_traits, typename _Ch_type>
02195     inline _Out_iter
02196     regex_replace(_Out_iter __out, _Bi_iter __first, _Bi_iter __last,
02197           const basic_regex<_Ch_type, _Rx_traits>& __e,
02198           const basic_string<_Ch_type>& __fmt,
02199           regex_constants::match_flag_type __flags
02200           = regex_constants::match_default)
02201     { return __out; }
02202 
02203   /**
02204    * @doctodo
02205    * @param s
02206    * @param e
02207    * @param fmt
02208    * @param flags
02209    *
02210    * @returns a copy of string @p s with replacements.
02211    *
02212    * @throws an exception of type regex_error.
02213    */
02214   template<typename _Rx_traits, typename _Ch_type>
02215     inline basic_string<_Ch_type>
02216     regex_replace(const basic_string<_Ch_type>& __s,
02217           const basic_regex<_Ch_type, _Rx_traits>& __e,
02218           const basic_string<_Ch_type>& __fmt,
02219           regex_constants::match_flag_type __flags
02220           = regex_constants::match_default)
02221     {
02222       std::string __result;
02223       regex_replace(std::back_inserter(__result),
02224             __s.begin(), __s.end(), __e, __fmt, __flags);
02225       return __result;
02226     }
02227 
02228   //@}
02229 
02230   // std [28.12] Class template regex_iterator
02231   /**
02232    * An iterator adaptor that will provide repeated calls of regex_search over 
02233    * a range until no more matches remain.
02234    */
02235   template<typename _Bi_iter,
02236        typename _Ch_type = typename iterator_traits<_Bi_iter>::value_type,
02237        typename _Rx_traits = regex_traits<_Ch_type> >
02238     class regex_iterator
02239     {
02240     public:
02241       typedef basic_regex<_Ch_type, _Rx_traits>  regex_type;
02242       typedef match_results<_Bi_iter>            value_type;
02243       typedef std::ptrdiff_t                     difference_type;
02244       typedef const value_type*                  pointer;
02245       typedef const value_type&                  reference;
02246       typedef std::forward_iterator_tag          iterator_category;
02247 
02248     public:
02249       /**
02250        * @brief Provides a singular iterator, useful for indicating
02251        * one-past-the-end of a range.
02252        * @todo Implement this function.
02253        * @doctodo
02254        */
02255       regex_iterator();
02256       
02257       /**
02258        * Constructs a %regex_iterator...
02259        * @param a  [IN] The start of a text range to search.
02260        * @param b  [IN] One-past-the-end of the text range to search.
02261        * @param re [IN] The regular expression to match.
02262        * @param m  [IN] Policy flags for match rules.
02263        * @todo Implement this function.
02264        * @doctodo
02265        */
02266       regex_iterator(_Bi_iter __a, _Bi_iter __b, const regex_type& __re,
02267              regex_constants::match_flag_type __m
02268              = regex_constants::match_default);
02269 
02270       /**
02271        * Copy constructs a %regex_iterator.
02272        * @todo Implement this function.
02273        * @doctodo
02274        */
02275       regex_iterator(const regex_iterator& __rhs);
02276       
02277       /**
02278        * @todo Implement this function.
02279        * @doctodo
02280        */
02281       regex_iterator&
02282       operator=(const regex_iterator& __rhs);
02283       
02284       /**
02285        * @todo Implement this function.
02286        * @doctodo
02287        */
02288       bool
02289       operator==(const regex_iterator& __rhs);
02290       
02291       /**
02292        * @todo Implement this function.
02293        * @doctodo
02294        */
02295       bool
02296       operator!=(const regex_iterator& __rhs);
02297       
02298       /**
02299        * @todo Implement this function.
02300        * @doctodo
02301        */
02302       const value_type&
02303       operator*();
02304       
02305       /**
02306        * @todo Implement this function.
02307        * @doctodo
02308        */
02309       const value_type*
02310       operator->();
02311       
02312       /**
02313        * @todo Implement this function.
02314        * @doctodo
02315        */
02316       regex_iterator&
02317       operator++();
02318       
02319       /**
02320        * @todo Implement this function.
02321        * @doctodo
02322        */
02323       regex_iterator
02324       operator++(int);
02325       
02326     private:
02327       // these members are shown for exposition only:
02328       _Bi_iter                         begin;
02329       _Bi_iter                         end;
02330       const regex_type*                pregex;
02331       regex_constants::match_flag_type flags;
02332       match_results<_Bi_iter>          match;
02333     };
02334   
02335   typedef regex_iterator<const char*>             cregex_iterator;
02336   typedef regex_iterator<string::const_iterator>  sregex_iterator;
02337 #ifdef _GLIBCXX_USE_WCHAR_T
02338   typedef regex_iterator<const wchar_t*>          wcregex_iterator;
02339   typedef regex_iterator<wstring::const_iterator> wsregex_iterator;
02340 #endif
02341 
02342   // [7.12.2] Class template regex_token_iterator
02343   /**
02344    * Iterates over submatches in a range (or @a splits a text string).
02345    *
02346    * The purpose of this iterator is to enumerate all, or all specified,
02347    * matches of a regular expression within a text range.  The dereferenced
02348    * value of an iterator of this class is a std::sub_match object.
02349    */
02350   template<typename _Bi_iter,
02351        typename _Ch_type = typename iterator_traits<_Bi_iter>::value_type,
02352        typename _Rx_traits = regex_traits<_Ch_type> >
02353     class regex_token_iterator
02354     {
02355     public:
02356       typedef basic_regex<_Ch_type, _Rx_traits> regex_type;
02357       typedef sub_match<_Bi_iter>               value_type;
02358       typedef std::ptrdiff_t                    difference_type;
02359       typedef const value_type*                 pointer;
02360       typedef const value_type&                 reference;
02361       typedef std::forward_iterator_tag         iterator_category;
02362       
02363     public:
02364       /**
02365        * @brief Default constructs a %regex_token_iterator.
02366        * @todo Implement this function.
02367        * 
02368        * A default-constructed %regex_token_iterator is a singular iterator
02369        * that will compare equal to the one-past-the-end value for any
02370        * iterator of the same type.
02371        */
02372       regex_token_iterator();
02373       
02374       /**
02375        * Constructs a %regex_token_iterator...
02376        * @param a          [IN] The start of the text to search.
02377        * @param b          [IN] One-past-the-end of the text to search.
02378        * @param re         [IN] The regular expression to search for.
02379        * @param submatch   [IN] Which submatch to return.  There are some
02380        *                        special values for this parameter:
02381        *                        - -1 each enumerated subexpression does NOT
02382        *                          match the regular expression (aka field
02383        *                          splitting)
02384        *                        - 0 the entire string matching the
02385        *                          subexpression is returned for each match
02386        *                          within the text.
02387        *                        - >0 enumerates only the indicated
02388        *                          subexpression from a match within the text.
02389        * @param m          [IN] Policy flags for match rules.
02390        *
02391        * @todo Implement this function.
02392        * @doctodo
02393        */
02394       regex_token_iterator(_Bi_iter __a, _Bi_iter __b, const regex_type& __re,
02395                int __submatch = 0,
02396                regex_constants::match_flag_type __m
02397                = regex_constants::match_default);
02398 
02399       /**
02400        * Constructs a %regex_token_iterator...
02401        * @param a          [IN] The start of the text to search.
02402        * @param b          [IN] One-past-the-end of the text to search.
02403        * @param re         [IN] The regular expression to search for.
02404        * @param submatches [IN] A list of subexpressions to return for each
02405        *                        regular expression match within the text.
02406        * @param m          [IN] Policy flags for match rules.
02407        *
02408        * @todo Implement this function.
02409        * @doctodo
02410        */
02411       regex_token_iterator(_Bi_iter __a, _Bi_iter __b,
02412                const regex_type& __re,
02413                const std::vector<int>& __submatches,
02414                regex_constants::match_flag_type __m
02415                  = regex_constants::match_default);
02416 
02417       /**
02418        * Constructs a %regex_token_iterator...
02419        * @param a          [IN] The start of the text to search.
02420        * @param b          [IN] One-past-the-end of the text to search.
02421        * @param re         [IN] The regular expression to search for.
02422        * @param submatches [IN] A list of subexpressions to return for each
02423        *                        regular expression match within the text.
02424        * @param m          [IN] Policy flags for match rules.
02425        
02426        * @todo Implement this function.
02427        * @doctodo
02428        */
02429       template<std::size_t _Nm>
02430         regex_token_iterator(_Bi_iter __a, _Bi_iter __b,
02431                  const regex_type& __re,
02432                  const int (&__submatches)[_Nm],
02433                  regex_constants::match_flag_type __m
02434                  = regex_constants::match_default);
02435 
02436       /**
02437        * @brief Copy constructs a %regex_token_iterator.
02438        * @param rhs [IN] A %regex_token_iterator to copy.
02439        * @todo Implement this function.
02440        */
02441       regex_token_iterator(const regex_token_iterator& __rhs);
02442       
02443       /**
02444        * @brief Assigns a %regex_token_iterator to another.
02445        * @param rhs [IN] A %regex_token_iterator to copy.
02446        * @todo Implement this function.
02447        */
02448       regex_token_iterator&
02449       operator=(const regex_token_iterator& __rhs);
02450       
02451       /**
02452        * @brief Compares a %regex_token_iterator to another for equality.
02453        * @todo Implement this function.
02454        */
02455       bool
02456       operator==(const regex_token_iterator& __rhs);
02457       
02458       /**
02459        * @brief Compares a %regex_token_iterator to another for inequality.
02460        * @todo Implement this function.
02461        */
02462       bool
02463       operator!=(const regex_token_iterator& __rhs);
02464       
02465       /**
02466        * @brief Dereferences a %regex_token_iterator.
02467        * @todo Implement this function.
02468        */
02469       const value_type&
02470       operator*();
02471       
02472       /**
02473        * @brief Selects a %regex_token_iterator member.
02474        * @todo Implement this function.
02475        */
02476       const value_type*
02477       operator->();
02478       
02479       /**
02480        * @brief Increments a %regex_token_iterator.
02481        * @todo Implement this function.
02482        */
02483       regex_token_iterator&
02484       operator++();
02485       
02486       /**
02487        * @brief Postincrements a %regex_token_iterator.
02488        * @todo Implement this function.
02489        */
02490       regex_token_iterator
02491       operator++(int);
02492       
02493     private: // data members for exposition only:
02494       typedef regex_iterator<_Bi_iter, _Ch_type, _Rx_traits> position_iterator;
02495 
02496       position_iterator __position;
02497       const value_type* __result;
02498       value_type        __suffix;
02499       std::size_t       __n;
02500       std::vector<int>  __subs;
02501     };
02502 
02503   /** @brief Token iterator for C-style NULL-terminated strings. */
02504   typedef regex_token_iterator<const char*>             cregex_token_iterator;
02505   /** @brief Token iterator for standard strings. */
02506   typedef regex_token_iterator<string::const_iterator>  sregex_token_iterator;
02507 #ifdef _GLIBCXX_USE_WCHAR_T
02508   /** @brief Token iterator for C-style NULL-terminated wide strings. */
02509   typedef regex_token_iterator<const wchar_t*>          wcregex_token_iterator;
02510   /** @brief Token iterator for standard wide-character strings. */
02511   typedef regex_token_iterator<wstring::const_iterator> wsregex_token_iterator;
02512 #endif
02513   
02514   //@} // group regex
02515 _GLIBCXX_END_NAMESPACE_VERSION
02516 } // namespace
02517