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