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