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