libstdc++
regex.h
Go to the documentation of this file.
1// class template regex -*- C++ -*-
2
3// Copyright (C) 2010-2022 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#if __cplusplus >= 202002L
32# include <bits/iterator_concepts.h> // std::default_sentinel_t
33#endif
34
35namespace std _GLIBCXX_VISIBILITY(default)
36{
37_GLIBCXX_BEGIN_NAMESPACE_VERSION
38_GLIBCXX_BEGIN_NAMESPACE_CXX11
39 template<typename, typename>
40 class basic_regex;
41
42 template<typename _Bi_iter, typename _Alloc>
43 class match_results;
44
45_GLIBCXX_END_NAMESPACE_CXX11
46
47namespace __detail
48{
49 enum class _RegexExecutorPolicy : int { _S_auto, _S_alternate };
50
51 template<typename _BiIter, typename _Alloc,
52 typename _CharT, typename _TraitsT>
53 bool
54 __regex_algo_impl(_BiIter __s, _BiIter __e,
55 match_results<_BiIter, _Alloc>& __m,
56 const basic_regex<_CharT, _TraitsT>& __re,
58 _RegexExecutorPolicy __policy,
59 bool __match_mode);
60
61 template<typename, typename, typename, bool>
62 class _Executor;
63
64 template<typename _Tp>
65 struct __is_contiguous_iter : false_type { };
66
67 template<typename _Tp>
68 struct __is_contiguous_iter<_Tp*> : true_type { };
69
70 template<typename _Tp, typename _Cont>
71 struct __is_contiguous_iter<__gnu_cxx::__normal_iterator<_Tp*, _Cont>>
72 : true_type { };
73}
74
75_GLIBCXX_BEGIN_NAMESPACE_CXX11
76
77 /**
78 * @addtogroup regex
79 * @{
80 */
81
82 /**
83 * @brief Describes aspects of a regular expression.
84 *
85 * A regular expression traits class that satisfies the requirements of
86 * section [28.7].
87 *
88 * The class %regex is parameterized around a set of related types and
89 * functions used to complete the definition of its semantics. This class
90 * satisfies the requirements of such a traits class.
91 *
92 * @headerfile regex
93 * @since C++11
94 */
95 template<typename _Ch_type>
97 {
98 public:
99 typedef _Ch_type char_type;
101 typedef std::locale locale_type;
102
103 private:
104 struct _RegexMask
105 {
106 typedef std::ctype_base::mask _BaseType;
107 _BaseType _M_base;
108 unsigned char _M_extended;
109 static constexpr unsigned char _S_under = 1 << 0;
110 static constexpr unsigned char _S_valid_mask = 0x1;
111
112 constexpr _RegexMask(_BaseType __base = 0,
113 unsigned char __extended = 0)
114 : _M_base(__base), _M_extended(__extended)
115 { }
116
117 constexpr _RegexMask
118 operator&(_RegexMask __other) const
119 {
120 return _RegexMask(_M_base & __other._M_base,
121 _M_extended & __other._M_extended);
122 }
123
124 constexpr _RegexMask
125 operator|(_RegexMask __other) const
126 {
127 return _RegexMask(_M_base | __other._M_base,
128 _M_extended | __other._M_extended);
129 }
130
131 constexpr _RegexMask
132 operator^(_RegexMask __other) const
133 {
134 return _RegexMask(_M_base ^ __other._M_base,
135 _M_extended ^ __other._M_extended);
136 }
137
138 constexpr _RegexMask
139 operator~() const
140 { return _RegexMask(~_M_base, ~_M_extended); }
141
142 _RegexMask&
143 operator&=(_RegexMask __other)
144 { return *this = (*this) & __other; }
145
146 _RegexMask&
147 operator|=(_RegexMask __other)
148 { return *this = (*this) | __other; }
149
150 _RegexMask&
151 operator^=(_RegexMask __other)
152 { return *this = (*this) ^ __other; }
153
154 constexpr bool
155 operator==(_RegexMask __other) const
156 {
157 return (_M_extended & _S_valid_mask)
158 == (__other._M_extended & _S_valid_mask)
159 && _M_base == __other._M_base;
160 }
161
162#if __cpp_impl_three_way_comparison < 201907L
163 constexpr bool
164 operator!=(_RegexMask __other) const
165 { return !((*this) == __other); }
166#endif
167 };
168
169 public:
170 typedef _RegexMask char_class_type;
171
172 public:
173 /**
174 * @brief Constructs a default traits object.
175 */
177
178 /**
179 * @brief Gives the length of a C-style string starting at @p __p.
180 *
181 * @param __p a pointer to the start of a character sequence.
182 *
183 * @returns the number of characters between @p *__p and the first
184 * default-initialized value of type @p char_type. In other words, uses
185 * the C-string algorithm for determining the length of a sequence of
186 * characters.
187 */
188 static std::size_t
189 length(const char_type* __p)
190 { return string_type::traits_type::length(__p); }
191
192 /**
193 * @brief Performs the identity translation.
194 *
195 * @param __c A character to the locale-specific character set.
196 *
197 * @returns __c.
198 */
199 char_type
200 translate(char_type __c) const
201 { return __c; }
202
203 /**
204 * @brief Translates a character into a case-insensitive equivalent.
205 *
206 * @param __c A character to the locale-specific character set.
207 *
208 * @returns the locale-specific lower-case equivalent of __c.
209 * @throws std::bad_cast if the imbued locale does not support the ctype
210 * facet.
211 */
212 char_type
213 translate_nocase(char_type __c) const
214 {
215 typedef std::ctype<char_type> __ctype_type;
216 const __ctype_type& __fctyp(use_facet<__ctype_type>(_M_locale));
217 return __fctyp.tolower(__c);
218 }
219
220 /**
221 * @brief Gets a sort key for a character sequence.
222 *
223 * @param __first beginning of the character sequence.
224 * @param __last one-past-the-end of the character sequence.
225 *
226 * Returns a sort key for the character sequence designated by the
227 * iterator range [F1, F2) such that if the character sequence [G1, G2)
228 * sorts before the character sequence [H1, H2) then
229 * v.transform(G1, G2) < v.transform(H1, H2).
230 *
231 * What this really does is provide a more efficient way to compare a
232 * string to multiple other strings in locales with fancy collation
233 * rules and equivalence classes.
234 *
235 * @returns a locale-specific sort key equivalent to the input range.
236 *
237 * @throws std::bad_cast if the current locale does not have a collate
238 * facet.
239 */
240 template<typename _Fwd_iter>
241 string_type
242 transform(_Fwd_iter __first, _Fwd_iter __last) const
243 {
244 typedef std::collate<char_type> __collate_type;
245 const __collate_type& __fclt(use_facet<__collate_type>(_M_locale));
246 string_type __s(__first, __last);
247 return __fclt.transform(__s.data(), __s.data() + __s.size());
248 }
249
250 /**
251 * @brief Gets a sort key for a character sequence, independent of case.
252 *
253 * @param __first beginning of the character sequence.
254 * @param __last one-past-the-end of the character sequence.
255 *
256 * Effects: if typeid(use_facet<collate<_Ch_type> >) ==
257 * typeid(collate_byname<_Ch_type>) and the form of the sort key
258 * returned by collate_byname<_Ch_type>::transform(__first, __last)
259 * is known and can be converted into a primary sort key
260 * then returns that key, otherwise returns an empty string.
261 *
262 * @todo Implement this function correctly.
263 */
264 template<typename _Fwd_iter>
265 string_type
266 transform_primary(_Fwd_iter __first, _Fwd_iter __last) const
267 {
268 // TODO : this is not entirely correct.
269 // This function requires extra support from the platform.
270 //
271 // Read http://gcc.gnu.org/ml/libstdc++/2013-09/msg00117.html and
272 // http://www.open-std.org/Jtc1/sc22/wg21/docs/papers/2003/n1429.htm
273 // for details.
274 typedef std::ctype<char_type> __ctype_type;
275 const __ctype_type& __fctyp(use_facet<__ctype_type>(_M_locale));
276 _GLIBCXX_STD_C::vector<char_type> __s(__first, __last);
277 __fctyp.tolower(__s.data(), __s.data() + __s.size());
278 return this->transform(__s.data(), __s.data() + __s.size());
279 }
280
281 /**
282 * @brief Gets a collation element by name.
283 *
284 * @param __first beginning of the collation element name.
285 * @param __last one-past-the-end of the collation element name.
286 *
287 * @returns a sequence of one or more characters that represents the
288 * collating element consisting of the character sequence designated by
289 * the iterator range [__first, __last). Returns an empty string if the
290 * character sequence is not a valid collating element.
291 */
292 template<typename _Fwd_iter>
293 string_type
294 lookup_collatename(_Fwd_iter __first, _Fwd_iter __last) const;
295
296 /**
297 * @brief Maps one or more characters to a named character
298 * classification.
299 *
300 * @param __first beginning of the character sequence.
301 * @param __last one-past-the-end of the character sequence.
302 * @param __icase ignores the case of the classification name.
303 *
304 * @returns an unspecified value that represents the character
305 * classification named by the character sequence designated by
306 * the iterator range [__first, __last). If @p icase is true,
307 * the returned mask identifies the classification regardless of
308 * the case of the characters to be matched (for example,
309 * [[:lower:]] is the same as [[:alpha:]]), otherwise a
310 * case-dependent classification is returned. The value
311 * returned shall be independent of the case of the characters
312 * in the character sequence. If the name is not recognized then
313 * returns a value that compares equal to 0.
314 *
315 * At least the following names (or their wide-character equivalent) are
316 * supported.
317 * - d
318 * - w
319 * - s
320 * - alnum
321 * - alpha
322 * - blank
323 * - cntrl
324 * - digit
325 * - graph
326 * - lower
327 * - print
328 * - punct
329 * - space
330 * - upper
331 * - xdigit
332 */
333 template<typename _Fwd_iter>
334 char_class_type
335 lookup_classname(_Fwd_iter __first, _Fwd_iter __last,
336 bool __icase = false) const;
337
338 /**
339 * @brief Determines if @p c is a member of an identified class.
340 *
341 * @param __c a character.
342 * @param __f a class type (as returned from lookup_classname).
343 *
344 * @returns true if the character @p __c is a member of the classification
345 * represented by @p __f, false otherwise.
346 *
347 * @throws std::bad_cast if the current locale does not have a ctype
348 * facet.
349 */
350 bool
351 isctype(_Ch_type __c, char_class_type __f) const;
352
353 /**
354 * @brief Converts a digit to an int.
355 *
356 * @param __ch a character representing a digit.
357 * @param __radix the radix if the numeric conversion (limited to 8, 10,
358 * or 16).
359 *
360 * @returns the value represented by the digit __ch in base radix if the
361 * character __ch is a valid digit in base radix; otherwise returns -1.
362 */
363 int
364 value(_Ch_type __ch, int __radix) const;
365
366 /**
367 * @brief Imbues the regex_traits object with a copy of a new locale.
368 *
369 * @param __loc A locale.
370 *
371 * @returns a copy of the previous locale in use by the regex_traits
372 * object.
373 *
374 * @note Calling imbue with a different locale than the one currently in
375 * use invalidates all cached data held by *this.
376 */
379 {
380 std::swap(_M_locale, __loc);
381 return __loc;
382 }
383
384 /**
385 * @brief Gets a copy of the current locale in use by the regex_traits
386 * object.
387 */
388 locale_type
389 getloc() const
390 { return _M_locale; }
391
392 protected:
393 locale_type _M_locale;
394 };
395
396 // [7.8] Class basic_regex
397 /**
398 * @brief A regular expression
399 *
400 * Specializations of this class template represent regular expressions
401 * constructed from sequences of character type `_Ch_type`.
402 * Use the `std::regex` typedef for `std::basic_regex<char>`.
403 *
404 * A character sequence passed to the constructor will be parsed according
405 * to the chosen grammar, and used to create a state machine representing
406 * the regular expression. The regex object can then be passed to algorithms
407 * such as `std::regex_match` to match sequences of characters.
408 *
409 * The `syntax_option_type` flag passed to the constructor selects from
410 * one of the supported regular expression grammars. The default is
411 * `ECMAScript` and the others are `basic`, `extended`, `awk`, `grep`, and
412 * `egrep`, which are variations on POSIX regular expressions.
413 *
414 * @headerfile regex
415 * @since C++11
416 */
417 template<typename _Ch_type, typename _Rx_traits = regex_traits<_Ch_type>>
419 {
420 public:
422 "regex traits class must have the same char_type");
423
424 // types:
425 typedef _Ch_type value_type;
426 typedef _Rx_traits traits_type;
427 typedef typename traits_type::string_type string_type;
429 typedef typename traits_type::locale_type locale_type;
430
431 /**
432 * @name Constants
433 * std [28.8.1](1)
434 */
435 ///@{
436 static constexpr flag_type icase = regex_constants::icase;
437 static constexpr flag_type nosubs = regex_constants::nosubs;
438 static constexpr flag_type optimize = regex_constants::optimize;
439 static constexpr flag_type collate = regex_constants::collate;
440 static constexpr flag_type ECMAScript = regex_constants::ECMAScript;
441 static constexpr flag_type basic = regex_constants::basic;
442 static constexpr flag_type extended = regex_constants::extended;
443 static constexpr flag_type awk = regex_constants::awk;
444 static constexpr flag_type grep = regex_constants::grep;
445 static constexpr flag_type egrep = regex_constants::egrep;
446#if __cplusplus >= 201703L || !defined __STRICT_ANSI__
447 static constexpr flag_type multiline = regex_constants::multiline;
448#endif
449 ///@}
450
451 // [7.8.2] construct/copy/destroy
452 /**
453 * Constructs a basic regular expression that does not match any
454 * character sequence.
455 */
456 basic_regex() noexcept
457 : _M_flags(ECMAScript), _M_loc(), _M_automaton(nullptr)
458 { }
459
460 /**
461 * @brief Constructs a basic regular expression from the
462 * sequence [__p, __p + char_traits<_Ch_type>::length(__p))
463 * interpreted according to the flags in @p __f.
464 *
465 * @param __p A pointer to the start of a C-style null-terminated string
466 * containing a regular expression.
467 * @param __f Flags indicating the syntax rules and options.
468 *
469 * @throws regex_error if @p __p is not a valid regular expression.
470 */
471 explicit
472 basic_regex(const _Ch_type* __p, flag_type __f = ECMAScript)
473 { _M_compile(__p, __p + _Rx_traits::length(__p), __f); }
474
475 /**
476 * @brief Constructs a basic regular expression from the sequence
477 * [p, p + len) interpreted according to the flags in @p f.
478 *
479 * @param __p A pointer to the start of a string containing a regular
480 * expression.
481 * @param __len The length of the string containing the regular
482 * expression.
483 * @param __f Flags indicating the syntax rules and options.
484 *
485 * @throws regex_error if @p __p is not a valid regular expression.
486 */
487 basic_regex(const _Ch_type* __p, std::size_t __len,
488 flag_type __f = ECMAScript)
489 {
490 __glibcxx_requires_string_len(__p, __len);
491 _M_compile(__p, __p + __len, __f);
492 }
493
494 /**
495 * @brief Copy-constructs a basic regular expression.
496 *
497 * @param __rhs A @p regex object.
498 */
499 basic_regex(const basic_regex& __rhs) = default;
500
501 /**
502 * @brief Move-constructs a basic regular expression.
503 *
504 * @param __rhs A @p regex object.
505 */
506 basic_regex(basic_regex&& __rhs) noexcept = default;
507
508 /**
509 * @brief Constructs a basic regular expression from the string
510 * @p s interpreted according to the flags in @p f.
511 *
512 * @param __s A string containing a regular expression.
513 * @param __f Flags indicating the syntax rules and options.
514 *
515 * @throws regex_error if @p __s is not a valid regular expression.
516 */
517 template<typename _Ch_traits, typename _Ch_alloc>
518 explicit
519 basic_regex(const std::basic_string<_Ch_type, _Ch_traits,
520 _Ch_alloc>& __s,
521 flag_type __f = ECMAScript)
522 { _M_compile(__s.data(), __s.data() + __s.size(), __f); }
523
524 /**
525 * @brief Constructs a basic regular expression from the range
526 * [first, last) interpreted according to the flags in @p f.
527 *
528 * @param __first The start of a range containing a valid regular
529 * expression.
530 * @param __last The end of a range containing a valid regular
531 * expression.
532 * @param __f The format flags of the regular expression.
533 *
534 * @throws regex_error if @p [__first, __last) is not a valid regular
535 * expression.
536 */
537 template<typename _FwdIter>
538 basic_regex(_FwdIter __first, _FwdIter __last,
539 flag_type __f = ECMAScript)
540 { this->assign(__first, __last, __f); }
541
542 /**
543 * @brief Constructs a basic regular expression from an initializer list.
544 *
545 * @param __l The initializer list.
546 * @param __f The format flags of the regular expression.
547 *
548 * @throws regex_error if @p __l is not a valid regular expression.
549 */
551 { _M_compile(__l.begin(), __l.end(), __f); }
552
553 /**
554 * @brief Destroys a basic regular expression.
555 */
557 { }
558
559 /**
560 * @brief Assigns one regular expression to another.
561 */
563 operator=(const basic_regex&) = default;
564
565 /**
566 * @brief Move-assigns one regular expression to another.
567 */
569 operator=(basic_regex&&) = default;
570
571 /**
572 * @brief Replaces a regular expression with a new one constructed from
573 * a C-style null-terminated string.
574 *
575 * @param __p A pointer to the start of a null-terminated C-style string
576 * containing a regular expression.
577 */
579 operator=(const _Ch_type* __p)
580 { return this->assign(__p); }
581
582 /**
583 * @brief Replaces a regular expression with a new one constructed from
584 * an initializer list.
585 *
586 * @param __l The initializer list.
587 *
588 * @throws regex_error if @p __l is not a valid regular expression.
589 */
592 { return this->assign(__l); }
593
594 /**
595 * @brief Replaces a regular expression with a new one constructed from
596 * a string.
597 *
598 * @param __s A pointer to a string containing a regular expression.
599 */
600 template<typename _Ch_traits, typename _Alloc>
603 { return this->assign(__s); }
604
605 // [7.8.3] assign
606 /**
607 * @brief Assigns one regular expression to another.
608 *
609 * @param __rhs Another regular expression object.
610 */
612 assign(const basic_regex& __rhs) noexcept
613 { return *this = __rhs; }
614
615 /**
616 * @brief Move-assigns one regular expression to another.
617 *
618 * @param __rhs Another regular expression object.
619 */
621 assign(basic_regex&& __rhs) noexcept
622 { return *this = std::move(__rhs); }
623
624 /**
625 * @brief Assigns a new regular expression to a regex object from a
626 * C-style null-terminated string containing a regular expression
627 * pattern.
628 *
629 * @param __p A pointer to a C-style null-terminated string containing
630 * a regular expression pattern.
631 * @param __flags Syntax option flags.
632 *
633 * @throws regex_error if __p does not contain a valid regular
634 * expression pattern interpreted according to @p __flags. If
635 * regex_error is thrown, *this remains unchanged.
636 */
638 assign(const _Ch_type* __p, flag_type __flags = ECMAScript)
639 {
640 _M_compile(__p, __p + _Rx_traits::length(__p), __flags);
641 return *this;
642 }
643
644 /**
645 * @brief Assigns a new regular expression to a regex object from a
646 * C-style string containing a regular expression pattern.
647 *
648 * @param __p A pointer to a C-style string containing a
649 * regular expression pattern.
650 * @param __len The length of the regular expression pattern string.
651 * @param __flags Syntax option flags.
652 *
653 * @throws regex_error if p does not contain a valid regular
654 * expression pattern interpreted according to @p __flags. If
655 * regex_error is thrown, *this remains unchanged.
656 */
657 // _GLIBCXX_RESOLVE_LIB_DEFECTS
658 // 3296. Inconsistent default argument for basic_regex<>::assign
660 assign(const _Ch_type* __p, size_t __len, flag_type __flags = ECMAScript)
661 {
662 _M_compile(__p, __p + __len, __flags);
663 return *this;
664 }
665
666 /**
667 * @brief Assigns a new regular expression to a regex object from a
668 * string containing a regular expression pattern.
669 *
670 * @param __s A string containing a regular expression pattern.
671 * @param __flags Syntax option flags.
672 *
673 * @throws regex_error if __s does not contain a valid regular
674 * expression pattern interpreted according to @p __flags. If
675 * regex_error is thrown, *this remains unchanged.
676 */
677 template<typename _Ch_traits, typename _Alloc>
680 flag_type __flags = ECMAScript)
681 {
682 _M_compile(__s.data(), __s.data() + __s.size(), __flags);
683 return *this;
684 }
685
686 /**
687 * @brief Assigns a new regular expression to a regex object.
688 *
689 * @param __first The start of a range containing a valid regular
690 * expression.
691 * @param __last The end of a range containing a valid regular
692 * expression.
693 * @param __flags Syntax option flags.
694 *
695 * @throws regex_error if p does not contain a valid regular
696 * expression pattern interpreted according to @p __flags. If
697 * regex_error is thrown, the object remains unchanged.
698 */
699 template<typename _InputIterator>
701 assign(_InputIterator __first, _InputIterator __last,
702 flag_type __flags = ECMAScript)
703 {
704#if __cpp_if_constexpr >= 201606L
705 using _ValT = typename iterator_traits<_InputIterator>::value_type;
706 if constexpr (__detail::__is_contiguous_iter<_InputIterator>::value
707 && is_same_v<_ValT, value_type>)
708 {
709 __glibcxx_requires_valid_range(__first, __last);
710 if constexpr (is_pointer_v<_InputIterator>)
711 _M_compile(__first, __last, __flags);
712 else // __normal_iterator<_T*, C>
713 _M_compile(__first.base(), __last.base(), __flags);
714 }
715 else
716#endif
717 this->assign(string_type(__first, __last), __flags);
718 return *this;
719 }
720
721 /**
722 * @brief Assigns a new regular expression to a regex object.
723 *
724 * @param __l An initializer list representing a regular expression.
725 * @param __flags Syntax option flags.
726 *
727 * @throws regex_error if @p __l does not contain a valid
728 * regular expression pattern interpreted according to @p
729 * __flags. If regex_error is thrown, the object remains
730 * unchanged.
731 */
733 assign(initializer_list<_Ch_type> __l, flag_type __flags = ECMAScript)
734 {
735 _M_compile(__l.begin(), __l.end(), __flags);
736 return *this;
737 }
738
739 // [7.8.4] const operations
740 /**
741 * @brief Gets the number of marked subexpressions within the regular
742 * expression.
743 */
744 unsigned int
745 mark_count() const noexcept
746 {
747 if (_M_automaton)
748 return _M_automaton->_M_sub_count() - 1;
749 return 0;
750 }
751
752 /**
753 * @brief Gets the flags used to construct the regular expression
754 * or in the last call to assign().
755 */
756 flag_type
757 flags() const noexcept
758 { return _M_flags; }
759
760 // [7.8.5] locale
761 /**
762 * @brief Imbues the regular expression object with the given locale.
763 *
764 * @param __loc A locale.
765 */
766 locale_type
767 imbue(locale_type __loc)
768 {
769 std::swap(__loc, _M_loc);
770 _M_automaton.reset();
771 return __loc;
772 }
773
774 /**
775 * @brief Gets the locale currently imbued in the regular expression
776 * object.
777 */
778 locale_type
779 getloc() const noexcept
780 { return _M_loc; }
781
782 // [7.8.6] swap
783 /**
784 * @brief Swaps the contents of two regular expression objects.
785 *
786 * @param __rhs Another regular expression object.
787 */
788 void
789 swap(basic_regex& __rhs) noexcept
790 {
791 std::swap(_M_flags, __rhs._M_flags);
792 std::swap(_M_loc, __rhs._M_loc);
793 std::swap(_M_automaton, __rhs._M_automaton);
794 }
795
796#ifdef _GLIBCXX_DEBUG
797 void
798 _M_dot(std::ostream& __ostr)
799 { _M_automaton->_M_dot(__ostr); }
800#endif
801
802 private:
804
805 void
806 _M_compile(const _Ch_type* __first, const _Ch_type* __last,
807 flag_type __f)
808 {
809 __detail::_Compiler<_Rx_traits> __c(__first, __last, _M_loc, __f);
810 _M_automaton = __c._M_get_nfa();
811 _M_flags = __f;
812 }
813
814 template<typename _Bp, typename _Ap, typename _Cp, typename _Rp>
815 friend bool
816 __detail::__regex_algo_impl(_Bp, _Bp, match_results<_Bp, _Ap>&,
817 const basic_regex<_Cp, _Rp>&,
819 __detail::_RegexExecutorPolicy, bool);
820
821 template<typename, typename, typename, bool>
822 friend class __detail::_Executor;
823
824 flag_type _M_flags;
825 locale_type _M_loc;
826 _AutomatonPtr _M_automaton;
827 };
828
829#if ! __cpp_inline_variables
830 template<typename _Ch, typename _Tr>
833
834 template<typename _Ch, typename _Tr>
837
838 template<typename _Ch, typename _Tr>
841
842 template<typename _Ch, typename _Tr>
845
846 template<typename _Ch, typename _Tr>
849
850 template<typename _Ch, typename _Tr>
853
854 template<typename _Ch, typename _Tr>
857
858 template<typename _Ch, typename _Tr>
861
862 template<typename _Ch, typename _Tr>
865
866 template<typename _Ch, typename _Tr>
869#endif // ! C++17
870
871#if __cpp_deduction_guides >= 201606
872 template<typename _ForwardIterator>
873 basic_regex(_ForwardIterator, _ForwardIterator,
875 -> basic_regex<typename iterator_traits<_ForwardIterator>::value_type>;
876#endif
877
878 /** @brief Standard regular expressions. */
880
881#ifdef _GLIBCXX_USE_WCHAR_T
882 /** @brief Standard wide-character regular expressions. */
884#endif
885
886
887 // [7.8.6] basic_regex swap
888 /**
889 * @brief Swaps the contents of two regular expression objects.
890 * @param __lhs First regular expression.
891 * @param __rhs Second regular expression.
892 * @relates basic_regex
893 */
894 template<typename _Ch_type, typename _Rx_traits>
895 inline void
897 basic_regex<_Ch_type, _Rx_traits>& __rhs) noexcept
898 { __lhs.swap(__rhs); }
899
900
901 // C++11 28.9 [re.submatch] Class template sub_match
902 /**
903 * A sequence of characters matched by a particular marked sub-expression.
904 *
905 * An object of this class is essentially a pair of iterators marking a
906 * matched subexpression within a regular expression pattern match. Such
907 * objects can be converted to and compared with std::basic_string objects
908 * of the same character type as the pattern matched by the regular
909 * expression.
910 *
911 * A `sub_match<Iter>` has a public base class of type `pair<Iter, Iter>`,
912 * so inherits pair's data members named `first` and `second`.
913 * The iterators that make up the pair are the usual half-open interval
914 * referencing the actual original pattern matched.
915 *
916 * @headerfile regex
917 * @since C++11
918 */
919 template<typename _BiIter>
921 /// @cond undocumented
922 : public std::pair<_BiIter, _BiIter>
923 /// @endcond
924 {
926
927 public:
928 typedef typename __iter_traits::value_type value_type;
929 typedef typename __iter_traits::difference_type difference_type;
930 typedef _BiIter iterator;
932
933 _GLIBCXX_DOXYGEN_ONLY(iterator first; iterator second;)
934
935 bool matched;
936
937 constexpr sub_match() noexcept : matched() { }
938
939 /// Gets the length of the matching sequence.
940 difference_type
941 length() const noexcept
942 { return this->matched ? std::distance(this->first, this->second) : 0; }
943
944 /**
945 * @brief Gets the matching sequence as a string.
946 *
947 * @returns the matching sequence as a string.
948 *
949 * This is the implicit conversion operator. It is identical to the
950 * str() member function except that it will want to pop up in
951 * unexpected places and cause a great deal of confusion and cursing
952 * from the unwary.
953 */
954 operator string_type() const
955 { return str(); }
956
957 /**
958 * @brief Gets the matching sequence as a string.
959 *
960 * @returns the matching sequence as a string.
961 */
962 string_type
963 str() const
964 {
965 return this->matched
966 ? string_type(this->first, this->second)
967 : string_type();
968 }
969
970 /**
971 * @brief Compares this and another matched sequence.
972 *
973 * @param __s Another matched sequence to compare to this one.
974 *
975 * @retval negative This matched sequence will collate before `__s`.
976 * @retval zero This matched sequence is equivalent to `__s`.
977 * @retval positive This matched sequence will collate after `__s`.
978 */
979 int
980 compare(const sub_match& __s) const
981 { return this->_M_str().compare(__s._M_str()); }
982
983 /**
984 * @{
985 * @brief Compares this `sub_match` to a string.
986 *
987 * @param __s A string to compare to this `sub_match`.
988 *
989 * @retval negative This matched sequence will collate before `__s`.
990 * @retval zero This matched sequence is equivalent to `__s`.
991 * @retval positive This matched sequence will collate after `__s`.
992 */
993 int
994 compare(const string_type& __s) const
995 { return this->_M_str().compare(__s); }
996
997 int
998 compare(const value_type* __s) const
999 { return this->_M_str().compare(__s); }
1000 /// @}
1001
1002 /// @cond undocumented
1003 // Non-standard, used by comparison operators
1004 int
1005 _M_compare(const value_type* __s, size_t __n) const
1006 { return this->_M_str().compare({__s, __n}); }
1007 /// @endcond
1008
1009 private:
1010 // Simplified basic_string_view for C++11
1011 struct __string_view
1012 {
1013 using traits_type = typename string_type::traits_type;
1014
1015 __string_view() = default;
1016
1017 __string_view(const value_type* __s, size_t __n) noexcept
1018 : _M_data(__s), _M_len(__n) { }
1019
1020 __string_view(const value_type* __s) noexcept
1021 : _M_data(__s), _M_len(traits_type::length(__s)) { }
1022
1023 __string_view(const string_type& __s) noexcept
1024 : _M_data(__s.data()), _M_len(__s.length()) { }
1025
1026 int
1027 compare(__string_view __s) const noexcept
1028 {
1029 if (const size_t __n = std::min(_M_len, __s._M_len))
1030 if (int __ret = traits_type::compare(_M_data, __s._M_data, __n))
1031 return __ret;
1032 using __limits = __gnu_cxx::__int_traits<int>;
1033 const difference_type __diff = _M_len - __s._M_len;
1034 if (__diff > __limits::__max)
1035 return __limits::__max;
1036 if (__diff < __limits::__min)
1037 return __limits::__min;
1038 return static_cast<int>(__diff);
1039 }
1040
1041 private:
1042 const value_type* _M_data = nullptr;
1043 size_t _M_len = 0;
1044 };
1045
1046 // Create a __string_view over the iterator range.
1047 template<typename _Iter = _BiIter>
1048 __enable_if_t<__detail::__is_contiguous_iter<_Iter>::value,
1049 __string_view>
1050 _M_str() const noexcept
1051 {
1052 if (this->matched)
1053 if (size_t __len = this->second - this->first)
1054 return { std::__addressof(*this->first), __len };
1055 return {};
1056 }
1057
1058 // Create a temporary string that can be converted to __string_view.
1059 template<typename _Iter = _BiIter>
1060 __enable_if_t<!__detail::__is_contiguous_iter<_Iter>::value,
1061 string_type>
1062 _M_str() const
1063 { return str(); }
1064 };
1065
1066
1067 /** @brief Standard regex submatch over a C-style null-terminated string. */
1069
1070 /** @brief Standard regex submatch over a standard string. */
1072
1073#ifdef _GLIBCXX_USE_WCHAR_T
1074 /** @brief Regex submatch over a C-style null-terminated wide string. */
1076
1077 /** @brief Regex submatch over a standard wide string. */
1079#endif
1080
1081 // [7.9.2] sub_match non-member operators
1082
1083 /// @relates sub_match @{
1084
1085 /**
1086 * @brief Tests the equivalence of two regular expression submatches.
1087 * @param __lhs First regular expression submatch.
1088 * @param __rhs Second regular expression submatch.
1089 * @returns true if @a __lhs is equivalent to @a __rhs, false otherwise.
1090 */
1091 template<typename _BiIter>
1092 inline bool
1094 { return __lhs.compare(__rhs) == 0; }
1095
1096#if __cpp_lib_three_way_comparison
1097 /**
1098 * @brief Three-way comparison of two regular expression submatches.
1099 * @param __lhs First regular expression submatch.
1100 * @param __rhs Second regular expression submatch.
1101 * @returns A value indicating whether `__lhs` is less than, equal to,
1102 * greater than, or incomparable with `__rhs`.
1103 */
1104 template<typename _BiIter>
1105 inline auto
1106 operator<=>(const sub_match<_BiIter>& __lhs,
1107 const sub_match<_BiIter>& __rhs)
1108 noexcept(__detail::__is_contiguous_iter<_BiIter>::value)
1109 {
1111 return __detail::__char_traits_cmp_cat<_Tr>(__lhs.compare(__rhs));
1112 }
1113#else
1114 /**
1115 * @brief Tests the inequivalence of two regular expression submatches.
1116 * @param __lhs First regular expression submatch.
1117 * @param __rhs Second regular expression submatch.
1118 * @returns true if @a __lhs is not equivalent to @a __rhs, false otherwise.
1119 */
1120 template<typename _BiIter>
1121 inline bool
1123 { return __lhs.compare(__rhs) != 0; }
1124
1125 /**
1126 * @brief Tests the ordering of two regular expression submatches.
1127 * @param __lhs First regular expression submatch.
1128 * @param __rhs Second regular expression submatch.
1129 * @returns true if @a __lhs precedes @a __rhs, false otherwise.
1130 */
1131 template<typename _BiIter>
1132 inline bool
1133 operator<(const sub_match<_BiIter>& __lhs, const sub_match<_BiIter>& __rhs)
1134 { return __lhs.compare(__rhs) < 0; }
1135
1136 /**
1137 * @brief Tests the ordering of two regular expression submatches.
1138 * @param __lhs First regular expression submatch.
1139 * @param __rhs Second regular expression submatch.
1140 * @returns true if @a __lhs does not succeed @a __rhs, false otherwise.
1141 */
1142 template<typename _BiIter>
1143 inline bool
1144 operator<=(const sub_match<_BiIter>& __lhs, const sub_match<_BiIter>& __rhs)
1145 { return __lhs.compare(__rhs) <= 0; }
1146
1147 /**
1148 * @brief Tests the ordering of two regular expression submatches.
1149 * @param __lhs First regular expression submatch.
1150 * @param __rhs Second regular expression submatch.
1151 * @returns true if @a __lhs does not precede @a __rhs, false otherwise.
1152 */
1153 template<typename _BiIter>
1154 inline bool
1156 { return __lhs.compare(__rhs) >= 0; }
1157
1158 /**
1159 * @brief Tests the ordering of two regular expression submatches.
1160 * @param __lhs First regular expression submatch.
1161 * @param __rhs Second regular expression submatch.
1162 * @returns true if @a __lhs succeeds @a __rhs, false otherwise.
1163 */
1164 template<typename _BiIter>
1165 inline bool
1167 { return __lhs.compare(__rhs) > 0; }
1168#endif // three-way comparison
1169
1170 /// @cond undocumented
1171
1172 // Alias for a basic_string that can be compared to a sub_match.
1173 template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
1174 using __sub_match_string = basic_string<
1176 _Ch_traits, _Ch_alloc>;
1177 /// @endcond
1178
1179#if ! __cpp_lib_three_way_comparison
1180 /**
1181 * @brief Tests the equivalence of a string and a regular expression
1182 * submatch.
1183 * @param __lhs A string.
1184 * @param __rhs A regular expression submatch.
1185 * @returns true if @a __lhs is equivalent to @a __rhs, false otherwise.
1186 */
1187 template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
1188 inline bool
1189 operator==(const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __lhs,
1190 const sub_match<_Bi_iter>& __rhs)
1191 { return __rhs._M_compare(__lhs.data(), __lhs.size()) == 0; }
1192
1193 /**
1194 * @brief Tests the inequivalence of a string and a regular expression
1195 * submatch.
1196 * @param __lhs A string.
1197 * @param __rhs A regular expression submatch.
1198 * @returns true if @a __lhs is not equivalent to @a __rhs, false otherwise.
1199 */
1200 template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
1201 inline bool
1202 operator!=(const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __lhs,
1203 const sub_match<_Bi_iter>& __rhs)
1204 { return !(__lhs == __rhs); }
1205
1206 /**
1207 * @brief Tests the ordering of a string and a regular expression submatch.
1208 * @param __lhs A string.
1209 * @param __rhs A regular expression submatch.
1210 * @returns true if @a __lhs precedes @a __rhs, false otherwise.
1211 */
1212 template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
1213 inline bool
1214 operator<(const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __lhs,
1215 const sub_match<_Bi_iter>& __rhs)
1216 { return __rhs._M_compare(__lhs.data(), __lhs.size()) > 0; }
1217
1218 /**
1219 * @brief Tests the ordering of a string and a regular expression submatch.
1220 * @param __lhs A string.
1221 * @param __rhs A regular expression submatch.
1222 * @returns true if @a __lhs succeeds @a __rhs, false otherwise.
1223 */
1224 template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
1225 inline bool
1226 operator>(const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __lhs,
1227 const sub_match<_Bi_iter>& __rhs)
1228 { return __rhs < __lhs; }
1229
1230 /**
1231 * @brief Tests the ordering of a string and a regular expression submatch.
1232 * @param __lhs A string.
1233 * @param __rhs A regular expression submatch.
1234 * @returns true if @a __lhs does not precede @a __rhs, false otherwise.
1235 */
1236 template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
1237 inline bool
1238 operator>=(const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __lhs,
1239 const sub_match<_Bi_iter>& __rhs)
1240 { return !(__lhs < __rhs); }
1241
1242 /**
1243 * @brief Tests the ordering of a string and a regular expression submatch.
1244 * @param __lhs A string.
1245 * @param __rhs A regular expression submatch.
1246 * @returns true if @a __lhs does not succeed @a __rhs, false otherwise.
1247 */
1248 template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
1249 inline bool
1250 operator<=(const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __lhs,
1251 const sub_match<_Bi_iter>& __rhs)
1252 { return !(__rhs < __lhs); }
1253#endif // three-way comparison
1254
1255 /**
1256 * @brief Tests the equivalence of a regular expression submatch and a
1257 * string.
1258 * @param __lhs A regular expression submatch.
1259 * @param __rhs A string.
1260 * @returns true if @a __lhs is equivalent to @a __rhs, false otherwise.
1261 */
1262 template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
1263 inline bool
1265 const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __rhs)
1266 { return __lhs._M_compare(__rhs.data(), __rhs.size()) == 0; }
1267
1268#if __cpp_lib_three_way_comparison
1269 /**
1270 * @brief Three-way comparison of a regular expression submatch and a string.
1271 * @param __lhs A regular expression submatch.
1272 * @param __rhs A string.
1273 * @returns A value indicating whether `__lhs` is less than, equal to,
1274 * greater than, or incomparable with `__rhs`.
1275 */
1276 template<typename _Bi_iter, typename _Ch_traits, typename _Alloc>
1277 inline auto
1278 operator<=>(const sub_match<_Bi_iter>& __lhs,
1279 const __sub_match_string<_Bi_iter, _Ch_traits, _Alloc>& __rhs)
1280 noexcept(__detail::__is_contiguous_iter<_Bi_iter>::value)
1281 {
1282 return __detail::__char_traits_cmp_cat<_Ch_traits>(
1283 __lhs._M_compare(__rhs.data(), __rhs.size()));
1284 }
1285#else
1286 /**
1287 * @brief Tests the inequivalence of a regular expression submatch and a
1288 * string.
1289 * @param __lhs A regular expression submatch.
1290 * @param __rhs A string.
1291 * @returns true if @a __lhs is not equivalent to @a __rhs, false otherwise.
1292 */
1293 template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
1294 inline bool
1296 const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __rhs)
1297 { return !(__lhs == __rhs); }
1298
1299 /**
1300 * @brief Tests the ordering of a regular expression submatch and a string.
1301 * @param __lhs A regular expression submatch.
1302 * @param __rhs A string.
1303 * @returns true if @a __lhs precedes @a __rhs, false otherwise.
1304 */
1305 template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
1306 inline bool
1307 operator<(const sub_match<_Bi_iter>& __lhs,
1308 const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __rhs)
1309 { return __lhs._M_compare(__rhs.data(), __rhs.size()) < 0; }
1310
1311 /**
1312 * @brief Tests the ordering of a regular expression submatch and a string.
1313 * @param __lhs A regular expression submatch.
1314 * @param __rhs A string.
1315 * @returns true if @a __lhs succeeds @a __rhs, false otherwise.
1316 */
1317 template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
1318 inline bool
1320 const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __rhs)
1321 { return __rhs < __lhs; }
1322
1323 /**
1324 * @brief Tests the ordering of a regular expression submatch and a string.
1325 * @param __lhs A regular expression submatch.
1326 * @param __rhs A string.
1327 * @returns true if @a __lhs does not precede @a __rhs, false otherwise.
1328 */
1329 template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
1330 inline bool
1332 const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __rhs)
1333 { return !(__lhs < __rhs); }
1334
1335 /**
1336 * @brief Tests the ordering of a regular expression submatch and a string.
1337 * @param __lhs A regular expression submatch.
1338 * @param __rhs A string.
1339 * @returns true if @a __lhs does not succeed @a __rhs, false otherwise.
1340 */
1341 template<typename _Bi_iter, typename _Ch_traits, typename _Ch_alloc>
1342 inline bool
1343 operator<=(const sub_match<_Bi_iter>& __lhs,
1344 const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __rhs)
1345 { return !(__rhs < __lhs); }
1346
1347 /**
1348 * @brief Tests the equivalence of a C string and a regular expression
1349 * submatch.
1350 * @param __lhs A null-terminated string.
1351 * @param __rhs A regular expression submatch.
1352 * @returns true if @a __lhs is equivalent to @a __rhs, false otherwise.
1353 */
1354 template<typename _Bi_iter>
1355 inline bool
1357 const sub_match<_Bi_iter>& __rhs)
1358 { return __rhs.compare(__lhs) == 0; }
1359
1360 /**
1361 * @brief Tests the inequivalence of a C string and a regular
1362 * expression submatch.
1363 * @param __lhs A null-terminated string.
1364 * @param __rhs A regular expression submatch.
1365 * @returns true if @a __lhs is not equivalent to @a __rhs, false otherwise.
1366 */
1367 template<typename _Bi_iter>
1368 inline bool
1370 const sub_match<_Bi_iter>& __rhs)
1371 { return !(__lhs == __rhs); }
1372
1373 /**
1374 * @brief Tests the ordering of a C string and a regular expression submatch.
1375 * @param __lhs A null-terminated string.
1376 * @param __rhs A regular expression submatch.
1377 * @returns true if @a __lhs precedes @a __rhs, false otherwise.
1378 */
1379 template<typename _Bi_iter>
1380 inline bool
1381 operator<(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
1382 const sub_match<_Bi_iter>& __rhs)
1383 { return __rhs.compare(__lhs) > 0; }
1384
1385 /**
1386 * @brief Tests the ordering of a C string and a regular expression submatch.
1387 * @param __lhs A null-terminated string.
1388 * @param __rhs A regular expression submatch.
1389 * @returns true if @a __lhs succeeds @a __rhs, false otherwise.
1390 */
1391 template<typename _Bi_iter>
1392 inline bool
1394 const sub_match<_Bi_iter>& __rhs)
1395 { return __rhs < __lhs; }
1396
1397 /**
1398 * @brief Tests the ordering of a C string and a regular expression submatch.
1399 * @param __lhs A null-terminated string.
1400 * @param __rhs A regular expression submatch.
1401 * @returns true if @a __lhs does not precede @a __rhs, false otherwise.
1402 */
1403 template<typename _Bi_iter>
1404 inline bool
1406 const sub_match<_Bi_iter>& __rhs)
1407 { return !(__lhs < __rhs); }
1408
1409 /**
1410 * @brief Tests the ordering of a C string and a regular expression submatch.
1411 * @param __lhs A null-terminated string.
1412 * @param __rhs A regular expression submatch.
1413 * @returns true if @a __lhs does not succeed @a __rhs, false otherwise.
1414 */
1415 template<typename _Bi_iter>
1416 inline bool
1417 operator<=(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
1418 const sub_match<_Bi_iter>& __rhs)
1419 { return !(__rhs < __lhs); }
1420#endif // three-way comparison
1421
1422 /**
1423 * @brief Tests the equivalence of a regular expression submatch and a C
1424 * string.
1425 * @param __lhs A regular expression submatch.
1426 * @param __rhs A null-terminated string.
1427 * @returns true if @a __lhs is equivalent to @a __rhs, false otherwise.
1428 */
1429 template<typename _Bi_iter>
1430 inline bool
1432 typename iterator_traits<_Bi_iter>::value_type const* __rhs)
1433 { return __lhs.compare(__rhs) == 0; }
1434
1435#if __cpp_lib_three_way_comparison
1436 /**
1437 * @brief Three-way comparison of a regular expression submatch and a C
1438 * string.
1439 * @param __lhs A regular expression submatch.
1440 * @param __rhs A null-terminated string.
1441 * @returns A value indicating whether `__lhs` is less than, equal to,
1442 * greater than, or incomparable with `__rhs`.
1443 */
1444 template<typename _Bi_iter>
1445 inline auto
1446 operator<=>(const sub_match<_Bi_iter>& __lhs,
1447 typename iterator_traits<_Bi_iter>::value_type const* __rhs)
1448 noexcept(__detail::__is_contiguous_iter<_Bi_iter>::value)
1449 {
1451 return __detail::__char_traits_cmp_cat<_Tr>(__lhs.compare(__rhs));
1452 }
1453#else
1454 /**
1455 * @brief Tests the inequivalence of a regular expression submatch and a
1456 * string.
1457 * @param __lhs A regular expression submatch.
1458 * @param __rhs A null-terminated string.
1459 * @returns true if @a __lhs is not equivalent to @a __rhs, false otherwise.
1460 */
1461 template<typename _Bi_iter>
1462 inline bool
1464 typename iterator_traits<_Bi_iter>::value_type const* __rhs)
1465 { return !(__lhs == __rhs); }
1466
1467 /**
1468 * @brief Tests the ordering of a regular expression submatch and a C string.
1469 * @param __lhs A regular expression submatch.
1470 * @param __rhs A null-terminated string.
1471 * @returns true if @a __lhs precedes @a __rhs, false otherwise.
1472 */
1473 template<typename _Bi_iter>
1474 inline bool
1475 operator<(const sub_match<_Bi_iter>& __lhs,
1476 typename iterator_traits<_Bi_iter>::value_type const* __rhs)
1477 { return __lhs.compare(__rhs) < 0; }
1478
1479 /**
1480 * @brief Tests the ordering of a regular expression submatch and a C string.
1481 * @param __lhs A regular expression submatch.
1482 * @param __rhs A null-terminated string.
1483 * @returns true if @a __lhs succeeds @a __rhs, false otherwise.
1484 */
1485 template<typename _Bi_iter>
1486 inline bool
1488 typename iterator_traits<_Bi_iter>::value_type const* __rhs)
1489 { return __rhs < __lhs; }
1490
1491 /**
1492 * @brief Tests the ordering of a regular expression submatch and a C string.
1493 * @param __lhs A regular expression submatch.
1494 * @param __rhs A null-terminated string.
1495 * @returns true if @a __lhs does not precede @a __rhs, false otherwise.
1496 */
1497 template<typename _Bi_iter>
1498 inline bool
1500 typename iterator_traits<_Bi_iter>::value_type const* __rhs)
1501 { return !(__lhs < __rhs); }
1502
1503 /**
1504 * @brief Tests the ordering of a regular expression submatch and a C string.
1505 * @param __lhs A regular expression submatch.
1506 * @param __rhs A null-terminated string.
1507 * @returns true if @a __lhs does not succeed @a __rhs, false otherwise.
1508 */
1509 template<typename _Bi_iter>
1510 inline bool
1511 operator<=(const sub_match<_Bi_iter>& __lhs,
1512 typename iterator_traits<_Bi_iter>::value_type const* __rhs)
1513 { return !(__rhs < __lhs); }
1514
1515 /**
1516 * @brief Tests the equivalence of a character and a regular expression
1517 * submatch.
1518 * @param __lhs A character.
1519 * @param __rhs A regular expression submatch.
1520 * @returns true if @a __lhs is equivalent to @a __rhs, false otherwise.
1521 */
1522 template<typename _Bi_iter>
1523 inline bool
1525 const sub_match<_Bi_iter>& __rhs)
1526 { return __rhs._M_compare(std::__addressof(__lhs), 1) == 0; }
1527
1528 /**
1529 * @brief Tests the inequivalence of a character and a regular expression
1530 * submatch.
1531 * @param __lhs A character.
1532 * @param __rhs A regular expression submatch.
1533 * @returns true if @a __lhs is not equivalent to @a __rhs, false otherwise.
1534 */
1535 template<typename _Bi_iter>
1536 inline bool
1538 const sub_match<_Bi_iter>& __rhs)
1539 { return !(__lhs == __rhs); }
1540
1541 /**
1542 * @brief Tests the ordering of a character and a regular expression
1543 * submatch.
1544 * @param __lhs A character.
1545 * @param __rhs A regular expression submatch.
1546 * @returns true if @a __lhs precedes @a __rhs, false otherwise.
1547 */
1548 template<typename _Bi_iter>
1549 inline bool
1550 operator<(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
1551 const sub_match<_Bi_iter>& __rhs)
1552 { return __rhs._M_compare(std::__addressof(__lhs), 1) > 0; }
1553
1554 /**
1555 * @brief Tests the ordering of a character and a regular expression
1556 * submatch.
1557 * @param __lhs A character.
1558 * @param __rhs A regular expression submatch.
1559 * @returns true if @a __lhs succeeds @a __rhs, false otherwise.
1560 */
1561 template<typename _Bi_iter>
1562 inline bool
1564 const sub_match<_Bi_iter>& __rhs)
1565 { return __rhs < __lhs; }
1566
1567 /**
1568 * @brief Tests the ordering of a character and a regular expression
1569 * submatch.
1570 * @param __lhs A character.
1571 * @param __rhs A regular expression submatch.
1572 * @returns true if @a __lhs does not precede @a __rhs, false otherwise.
1573 */
1574 template<typename _Bi_iter>
1575 inline bool
1577 const sub_match<_Bi_iter>& __rhs)
1578 { return !(__lhs < __rhs); }
1579
1580 /**
1581 * @brief Tests the ordering of a character and a regular expression
1582 * submatch.
1583 * @param __lhs A character.
1584 * @param __rhs A regular expression submatch.
1585 * @returns true if @a __lhs does not succeed @a __rhs, false otherwise.
1586 */
1587 template<typename _Bi_iter>
1588 inline bool
1589 operator<=(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
1590 const sub_match<_Bi_iter>& __rhs)
1591 { return !(__rhs < __lhs); }
1592#endif // three-way comparison
1593
1594 /**
1595 * @brief Tests the equivalence of a regular expression submatch and a
1596 * character.
1597 * @param __lhs A regular expression submatch.
1598 * @param __rhs A character.
1599 * @returns true if @a __lhs is equivalent to @a __rhs, false otherwise.
1600 */
1601 template<typename _Bi_iter>
1602 inline bool
1604 typename iterator_traits<_Bi_iter>::value_type const& __rhs)
1605 { return __lhs._M_compare(std::__addressof(__rhs), 1) == 0; }
1606
1607#if __cpp_lib_three_way_comparison
1608 /**
1609 * @brief Three-way comparison of a regular expression submatch and a
1610 * character.
1611 * @param __lhs A regular expression submatch.
1612 * @param __rhs A character.
1613 * @returns A value indicating whether `__lhs` is less than, equal to,
1614 * greater than, or incomparable with `__rhs`.
1615 */
1616
1617 template<typename _Bi_iter>
1618 inline auto
1619 operator<=>(const sub_match<_Bi_iter>& __lhs,
1620 typename iterator_traits<_Bi_iter>::value_type const& __rhs)
1621 noexcept(__detail::__is_contiguous_iter<_Bi_iter>::value)
1622 {
1624 return __detail::__char_traits_cmp_cat<_Tr>(
1625 __lhs._M_compare(std::__addressof(__rhs), 1));
1626 }
1627#else
1628 /**
1629 * @brief Tests the inequivalence of a regular expression submatch and a
1630 * character.
1631 * @param __lhs A regular expression submatch.
1632 * @param __rhs A character.
1633 * @returns true if @a __lhs is not equivalent to @a __rhs, false otherwise.
1634 */
1635 template<typename _Bi_iter>
1636 inline bool
1638 typename iterator_traits<_Bi_iter>::value_type const& __rhs)
1639 { return !(__lhs == __rhs); }
1640
1641 /**
1642 * @brief Tests the ordering of a regular expression submatch and a
1643 * character.
1644 * @param __lhs A regular expression submatch.
1645 * @param __rhs A character.
1646 * @returns true if @a __lhs precedes @a __rhs, false otherwise.
1647 */
1648 template<typename _Bi_iter>
1649 inline bool
1650 operator<(const sub_match<_Bi_iter>& __lhs,
1651 typename iterator_traits<_Bi_iter>::value_type const& __rhs)
1652 { return __lhs._M_compare(std::__addressof(__rhs), 1) < 0; }
1653
1654 /**
1655 * @brief Tests the ordering of a regular expression submatch and a
1656 * character.
1657 * @param __lhs A regular expression submatch.
1658 * @param __rhs A character.
1659 * @returns true if @a __lhs succeeds @a __rhs, false otherwise.
1660 */
1661 template<typename _Bi_iter>
1662 inline bool
1664 typename iterator_traits<_Bi_iter>::value_type const& __rhs)
1665 { return __rhs < __lhs; }
1666
1667 /**
1668 * @brief Tests the ordering of a regular expression submatch and a
1669 * character.
1670 * @param __lhs A regular expression submatch.
1671 * @param __rhs A character.
1672 * @returns true if @a __lhs does not precede @a __rhs, false otherwise.
1673 */
1674 template<typename _Bi_iter>
1675 inline bool
1677 typename iterator_traits<_Bi_iter>::value_type const& __rhs)
1678 { return !(__lhs < __rhs); }
1679
1680 /**
1681 * @brief Tests the ordering of a regular expression submatch and a
1682 * character.
1683 * @param __lhs A regular expression submatch.
1684 * @param __rhs A character.
1685 * @returns true if @a __lhs does not succeed @a __rhs, false otherwise.
1686 */
1687 template<typename _Bi_iter>
1688 inline bool
1689 operator<=(const sub_match<_Bi_iter>& __lhs,
1690 typename iterator_traits<_Bi_iter>::value_type const& __rhs)
1691 { return !(__rhs < __lhs); }
1692#endif // three-way comparison
1693
1694 /**
1695 * @brief Inserts a matched string into an output stream.
1696 *
1697 * @param __os The output stream.
1698 * @param __m A submatch string.
1699 *
1700 * @returns the output stream with the submatch string inserted.
1701 */
1702 template<typename _Ch_type, typename _Ch_traits, typename _Bi_iter>
1703 inline
1706 const sub_match<_Bi_iter>& __m)
1707 { return __os << __m.str(); }
1708
1709 /// @} relates sub_match
1710
1711 // [7.10] Class template match_results
1712
1713 /**
1714 * @brief The results of a match or search operation.
1715 *
1716 * A collection of character sequences representing the result of a regular
1717 * expression match. Storage for the collection is allocated and freed as
1718 * necessary by the member functions of class template match_results.
1719 *
1720 * This class satisfies the Sequence requirements, with the exception that
1721 * only the operations defined for a const-qualified Sequence are supported.
1722 *
1723 * The sub_match object stored at index 0 represents sub-expression 0, i.e.
1724 * the whole match. In this case the %sub_match member matched is always true.
1725 * The sub_match object stored at index n denotes what matched the marked
1726 * sub-expression n within the matched expression. If the sub-expression n
1727 * participated in a regular expression match then the %sub_match member
1728 * matched evaluates to true, and members first and second denote the range
1729 * of characters [first, second) which formed that match. Otherwise matched
1730 * is false, and members first and second point to the end of the sequence
1731 * that was searched.
1732 *
1733 * @headerfile regex
1734 * @since C++11
1735 */
1736 template<typename _Bi_iter,
1737 typename _Alloc = allocator<sub_match<_Bi_iter> > >
1739 : private std::vector<sub_match<_Bi_iter>, _Alloc>
1740 {
1741 private:
1742 /*
1743 * The vector base is empty if this does not represent a match (!ready());
1744 * Otherwise if it's a match failure, it contains 3 elements:
1745 * [0] unmatched
1746 * [1] prefix
1747 * [2] suffix
1748 * Otherwise it contains n+4 elements where n is the number of marked
1749 * sub-expressions:
1750 * [0] entire match
1751 * [1] 1st marked subexpression
1752 * ...
1753 * [n] nth marked subexpression
1754 * [n+1] unmatched
1755 * [n+2] prefix
1756 * [n+3] suffix
1757 */
1759 // In debug mode _Base_type is the debug vector, this is the unsafe one:
1760 typedef _GLIBCXX_STD_C::vector<sub_match<_Bi_iter>, _Alloc> _Unchecked;
1763
1764 public:
1765 /**
1766 * @name 28.10 Public Types
1767 */
1768 ///@{
1770 typedef const value_type& const_reference;
1771 typedef value_type& reference;
1772 typedef typename _Base_type::const_iterator const_iterator;
1773 typedef const_iterator iterator;
1774 typedef typename __iter_traits::difference_type difference_type;
1775 typedef typename allocator_traits<_Alloc>::size_type size_type;
1776 typedef _Alloc allocator_type;
1777 typedef typename __iter_traits::value_type char_type;
1779 ///@}
1780
1781 public:
1782 /**
1783 * @name 28.10.1 Construction, Copying, and Destruction
1784 */
1785 ///@{
1786
1787 /**
1788 * @brief Constructs a default %match_results container.
1789 * @post size() returns 0 and str() returns an empty string.
1790 */
1792
1793 /**
1794 * @brief Constructs a default %match_results container.
1795 * @post size() returns 0 and str() returns an empty string.
1796 */
1797 explicit
1798 match_results(const _Alloc& __a) noexcept
1799 : _Base_type(__a)
1800 { }
1801
1802 /**
1803 * @brief Copy constructs a %match_results.
1804 */
1805 match_results(const match_results&) = default;
1806
1807 /**
1808 * @brief Move constructs a %match_results.
1809 */
1810 match_results(match_results&&) noexcept = default;
1811
1812 /**
1813 * @brief Assigns rhs to *this.
1814 */
1816 operator=(const match_results&) = default;
1817
1818 /**
1819 * @brief Move-assigns rhs to *this.
1820 */
1822 operator=(match_results&&) = default;
1823
1824 /**
1825 * @brief Destroys a %match_results object.
1826 */
1827 ~match_results() = default;
1828
1829 ///@}
1830
1831 // 28.10.2, state:
1832 /**
1833 * @brief Indicates if the %match_results is ready.
1834 * @retval true The object has a fully-established result state.
1835 * @retval false The object is not ready.
1836 */
1837 bool ready() const noexcept { return !_Unchecked::empty(); }
1838
1839 /**
1840 * @name 28.10.2 Size
1841 */
1842 ///@{
1843
1844 /**
1845 * @brief Gets the number of matches and submatches.
1846 *
1847 * The number of matches for a given regular expression will be either 0
1848 * if there was no match or mark_count() + 1 if a match was successful.
1849 * Some matches may be empty.
1850 *
1851 * @returns the number of matches found.
1852 */
1853 size_type
1854 size() const noexcept
1855 { return _Unchecked::empty() ? 0 : _Unchecked::size() - 3; }
1856
1857 size_type
1858 max_size() const noexcept
1859 { return _Unchecked::max_size() - 3; }
1860
1861 /**
1862 * @brief Indicates if the %match_results contains no results.
1863 * @retval true The %match_results object is empty.
1864 * @retval false The %match_results object is not empty.
1865 */
1866 _GLIBCXX_NODISCARD bool
1867 empty() const noexcept
1868 { return _Unchecked::size() <= 3; }
1869
1870 ///@}
1871
1872 /**
1873 * @name 28.10.4 Element Access
1874 */
1875 ///@{
1876
1877 /**
1878 * @brief Gets the length of the indicated submatch.
1879 * @param __sub indicates the submatch.
1880 * @pre ready() == true
1881 *
1882 * This function returns the length of the indicated submatch, or the
1883 * length of the entire match if @p __sub is zero (the default).
1884 */
1885 difference_type
1886 length(size_type __sub = 0) const
1887 { return (*this)[__sub].length(); }
1888
1889 /**
1890 * @brief Gets the offset of the beginning of the indicated submatch.
1891 * @param __sub indicates the submatch.
1892 * @pre ready() == true
1893 *
1894 * This function returns the offset from the beginning of the target
1895 * sequence to the beginning of the submatch, unless the value of @p __sub
1896 * is zero (the default), in which case this function returns the offset
1897 * from the beginning of the target sequence to the beginning of the
1898 * match.
1899 */
1900 difference_type
1901 position(size_type __sub = 0) const
1902 { return std::distance(_M_begin, (*this)[__sub].first); }
1903
1904 /**
1905 * @brief Gets the match or submatch converted to a string type.
1906 * @param __sub indicates the submatch.
1907 * @pre ready() == true
1908 *
1909 * This function gets the submatch (or match, if @p __sub is
1910 * zero) extracted from the target range and converted to the
1911 * associated string type.
1912 */
1913 string_type
1914 str(size_type __sub = 0) const
1915 { return string_type((*this)[__sub]); }
1916
1917 /**
1918 * @brief Gets a %sub_match reference for the match or submatch.
1919 * @param __sub indicates the submatch.
1920 * @pre ready() == true
1921 *
1922 * This function gets a reference to the indicated submatch, or
1923 * the entire match if @p __sub is zero.
1924 *
1925 * If @p __sub >= size() then this function returns a %sub_match with a
1926 * special value indicating no submatch.
1927 */
1928 const_reference
1929 operator[](size_type __sub) const
1930 {
1931 __glibcxx_assert( ready() );
1932 return __sub < size()
1933 ? _Unchecked::operator[](__sub)
1934 : _M_unmatched_sub();
1935 }
1936
1937 /**
1938 * @brief Gets a %sub_match representing the match prefix.
1939 * @pre ready() == true
1940 *
1941 * This function gets a reference to a %sub_match object representing the
1942 * part of the target range between the start of the target range and the
1943 * start of the match.
1944 */
1945 const_reference
1946 prefix() const
1947 {
1948 __glibcxx_assert( ready() );
1949 return !empty() ? _M_prefix() : _M_unmatched_sub();
1950 }
1951
1952 /**
1953 * @brief Gets a %sub_match representing the match suffix.
1954 * @pre ready() == true
1955 *
1956 * This function gets a reference to a %sub_match object representing the
1957 * part of the target range between the end of the match and the end of
1958 * the target range.
1959 */
1960 const_reference
1961 suffix() const
1962 {
1963 __glibcxx_assert( ready() );
1964 return !empty() ? _M_suffix() : _M_unmatched_sub();
1965 }
1966
1967 /**
1968 * @brief Gets an iterator to the start of the %sub_match collection.
1969 */
1970 const_iterator
1971 begin() const noexcept
1972 { return _Base_type::begin(); }
1973
1974 /**
1975 * @brief Gets an iterator to the start of the %sub_match collection.
1976 */
1977 const_iterator
1978 cbegin() const noexcept
1979 { return this->begin(); }
1980
1981 /**
1982 * @brief Gets an iterator to one-past-the-end of the collection.
1983 */
1984 const_iterator
1985 end() const noexcept
1986 { return _Base_type::end() - (_Base_type::empty() ? 0 : 3); }
1987
1988 /**
1989 * @brief Gets an iterator to one-past-the-end of the collection.
1990 */
1991 const_iterator
1992 cend() const noexcept
1993 { return this->end(); }
1994
1995 ///@}
1996
1997 /**
1998 * @name 28.10.5 Formatting
1999 *
2000 * These functions perform formatted substitution of the matched
2001 * character sequences into their target. The format specifiers and
2002 * escape sequences accepted by these functions are determined by
2003 * their @p flags parameter as documented above.
2004 */
2005 ///@{
2006
2007 /**
2008 * @pre ready() == true
2009 */
2010 template<typename _Out_iter>
2011 _Out_iter
2012 format(_Out_iter __out, const char_type* __fmt_first,
2013 const char_type* __fmt_last,
2015
2016 /**
2017 * @pre ready() == true
2018 */
2019 template<typename _Out_iter, typename _St, typename _Sa>
2020 _Out_iter
2021 format(_Out_iter __out, const basic_string<char_type, _St, _Sa>& __fmt,
2023 {
2024 return format(__out, __fmt.data(), __fmt.data() + __fmt.size(),
2025 __flags);
2026 }
2027
2028 /**
2029 * @pre ready() == true
2030 */
2031 template<typename _St, typename _Sa>
2035 {
2037 format(std::back_inserter(__result), __fmt, __flags);
2038 return __result;
2039 }
2040
2041 /**
2042 * @pre ready() == true
2043 */
2044 string_type
2045 format(const char_type* __fmt,
2047 {
2048 string_type __result;
2049 format(std::back_inserter(__result),
2050 __fmt,
2051 __fmt + char_traits<char_type>::length(__fmt),
2052 __flags);
2053 return __result;
2054 }
2055
2056 ///@}
2057
2058 /**
2059 * @name 28.10.6 Allocator
2060 */
2061 ///@{
2062
2063 /**
2064 * @brief Gets a copy of the allocator.
2065 */
2066 allocator_type
2067 get_allocator() const noexcept
2068 { return _Base_type::get_allocator(); }
2069
2070 ///@}
2071
2072 /**
2073 * @name 28.10.7 Swap
2074 */
2075 ///@{
2076
2077 /**
2078 * @brief Swaps the contents of two match_results.
2079 */
2080 void
2081 swap(match_results& __that) noexcept
2082 {
2083 using std::swap;
2084 _Base_type::swap(__that);
2085 swap(_M_begin, __that._M_begin);
2086 }
2087 ///@}
2088
2089 private:
2090 template<typename, typename, typename>
2091 friend class regex_iterator;
2092
2093 /// @cond undocumented
2094
2095 template<typename, typename, typename, bool>
2096 friend class __detail::_Executor;
2097
2098 template<typename _Bp, typename _Ap, typename _Cp, typename _Rp>
2099 friend bool
2100 __detail::__regex_algo_impl(_Bp, _Bp, match_results<_Bp, _Ap>&,
2101 const basic_regex<_Cp, _Rp>&,
2103 __detail::_RegexExecutorPolicy, bool);
2104
2105 // Reset contents to __size unmatched sub_match objects
2106 // (plus additional objects for prefix, suffix and unmatched sub).
2107 void
2108 _M_resize(unsigned int __size)
2109 { _Unchecked::assign(__size + 3, sub_match<_Bi_iter>{}); }
2110
2111 // Set state to a failed match for the given past-the-end iterator.
2112 void
2113 _M_establish_failed_match(_Bi_iter __end)
2114 {
2115 sub_match<_Bi_iter> __sm;
2116 __sm.first = __sm.second = __end;
2117 _Unchecked::assign(3, __sm);
2118 }
2119
2120 const_reference
2121 _M_unmatched_sub() const
2122 { return _Unchecked::operator[](_Unchecked::size() - 3); }
2123
2124 sub_match<_Bi_iter>&
2125 _M_unmatched_sub()
2126 { return _Unchecked::operator[](_Unchecked::size() - 3); }
2127
2128 const_reference
2129 _M_prefix() const
2130 { return _Unchecked::operator[](_Unchecked::size() - 2); }
2131
2132 sub_match<_Bi_iter>&
2133 _M_prefix()
2134 { return _Unchecked::operator[](_Unchecked::size() - 2); }
2135
2136 const_reference
2137 _M_suffix() const
2138 { return _Unchecked::operator[](_Unchecked::size() - 1); }
2139
2140 sub_match<_Bi_iter>&
2141 _M_suffix()
2142 { return _Unchecked::operator[](_Unchecked::size() - 1); }
2143
2144 _Bi_iter _M_begin {};
2145 /// @endcond
2146 };
2147
2148 typedef match_results<const char*> cmatch;
2149 typedef match_results<string::const_iterator> smatch;
2150#ifdef _GLIBCXX_USE_WCHAR_T
2151 typedef match_results<const wchar_t*> wcmatch;
2152 typedef match_results<wstring::const_iterator> wsmatch;
2153#endif
2154
2155 // match_results comparisons
2156
2157 /**
2158 * @brief Compares two match_results for equality.
2159 * @returns true if the two objects refer to the same match,
2160 * false otherwise.
2161 *
2162 * @relates match_results
2163 */
2164 template<typename _Bi_iter, typename _Alloc>
2165 inline bool
2168 {
2169 if (__m1.ready() != __m2.ready())
2170 return false;
2171 if (!__m1.ready()) // both are not ready
2172 return true;
2173 if (__m1.empty() != __m2.empty())
2174 return false;
2175 if (__m1.empty()) // both are empty
2176 return true;
2177 return __m1.prefix() == __m2.prefix()
2178 && __m1.size() == __m2.size()
2179 && std::equal(__m1.begin(), __m1.end(), __m2.begin())
2180 && __m1.suffix() == __m2.suffix();
2181 }
2182
2183#if ! __cpp_lib_three_way_comparison
2184 /**
2185 * @brief Compares two match_results for inequality.
2186 * @returns true if the two objects do not refer to the same match,
2187 * false otherwise.
2188 *
2189 * @relates match_results
2190 */
2191 template<typename _Bi_iter, class _Alloc>
2192 inline bool
2195 { return !(__m1 == __m2); }
2196#endif
2197
2198 // [7.10.6] match_results swap
2199 /**
2200 * @brief Swaps two match results.
2201 * @param __lhs A match result.
2202 * @param __rhs A match result.
2203 *
2204 * The contents of the two match_results objects are swapped.
2205 *
2206 * @relates match_results
2207 */
2208 template<typename _Bi_iter, typename _Alloc>
2209 inline void
2211 match_results<_Bi_iter, _Alloc>& __rhs) noexcept
2212 { __lhs.swap(__rhs); }
2213
2214_GLIBCXX_END_NAMESPACE_CXX11
2215
2216 // [28.11.2] Function template regex_match
2217 /**
2218 * @name Matching, Searching, and Replacing
2219 *
2220 * @{
2221 */
2222
2223 /**
2224 * @brief Determines if there is a match between the regular expression @p e
2225 * and all of the character sequence [first, last).
2226 *
2227 * @param __s Start of the character sequence to match.
2228 * @param __e One-past-the-end of the character sequence to match.
2229 * @param __m The match results.
2230 * @param __re The regular expression.
2231 * @param __flags Controls how the regular expression is matched.
2232 *
2233 * @retval true A match exists.
2234 * @retval false Otherwise.
2235 *
2236 * @throws an exception of type regex_error.
2237 */
2238 template<typename _Bi_iter, typename _Alloc,
2239 typename _Ch_type, typename _Rx_traits>
2240 inline bool
2241 regex_match(_Bi_iter __s,
2242 _Bi_iter __e,
2247 {
2248 return __detail::__regex_algo_impl(__s, __e, __m, __re, __flags,
2249 __detail::_RegexExecutorPolicy::_S_auto, true);
2250 }
2251
2252 /**
2253 * @brief Indicates if there is a match between the regular expression @p e
2254 * and all of the character sequence [first, last).
2255 *
2256 * @param __first Beginning of the character sequence to match.
2257 * @param __last One-past-the-end of the character sequence to match.
2258 * @param __re The regular expression.
2259 * @param __flags Controls how the regular expression is matched.
2260 *
2261 * @retval true A match exists.
2262 * @retval false Otherwise.
2263 *
2264 * @throws an exception of type regex_error.
2265 */
2266 template<typename _Bi_iter, typename _Ch_type, typename _Rx_traits>
2267 inline bool
2268 regex_match(_Bi_iter __first, _Bi_iter __last,
2272 {
2274 return regex_match(__first, __last, __what, __re, __flags);
2275 }
2276
2277 /**
2278 * @brief Determines if there is a match between the regular expression @p e
2279 * and a C-style null-terminated string.
2280 *
2281 * @param __s The C-style null-terminated string to match.
2282 * @param __m The match results.
2283 * @param __re The regular expression.
2284 * @param __f Controls how the regular expression is matched.
2285 *
2286 * @retval true A match exists.
2287 * @retval false Otherwise.
2288 *
2289 * @throws an exception of type regex_error.
2290 */
2291 template<typename _Ch_type, typename _Alloc, typename _Rx_traits>
2292 inline bool
2293 regex_match(const _Ch_type* __s,
2298 { return regex_match(__s, __s + _Rx_traits::length(__s), __m, __re, __f); }
2299
2300 /**
2301 * @brief Determines if there is a match between the regular expression @p e
2302 * and a string.
2303 *
2304 * @param __s The string to match.
2305 * @param __m The match results.
2306 * @param __re The regular expression.
2307 * @param __flags Controls how the regular expression is matched.
2308 *
2309 * @retval true A match exists.
2310 * @retval false Otherwise.
2311 *
2312 * @throws an exception of type regex_error.
2313 */
2314 template<typename _Ch_traits, typename _Ch_alloc,
2315 typename _Alloc, typename _Ch_type, typename _Rx_traits>
2316 inline bool
2318 match_results<typename basic_string<_Ch_type,
2319 _Ch_traits, _Ch_alloc>::const_iterator, _Alloc>& __m,
2323 { return regex_match(__s.begin(), __s.end(), __m, __re, __flags); }
2324
2325 // _GLIBCXX_RESOLVE_LIB_DEFECTS
2326 // 2329. regex_match() with match_results should forbid temporary strings
2327 /// Prevent unsafe attempts to get match_results from a temporary string.
2328 template<typename _Ch_traits, typename _Ch_alloc,
2329 typename _Alloc, typename _Ch_type, typename _Rx_traits>
2330 bool
2332 match_results<typename basic_string<_Ch_type,
2333 _Ch_traits, _Ch_alloc>::const_iterator, _Alloc>&,
2337
2338 /**
2339 * @brief Indicates if there is a match between the regular expression @p e
2340 * and a C-style null-terminated string.
2341 *
2342 * @param __s The C-style null-terminated string to match.
2343 * @param __re The regular expression.
2344 * @param __f Controls how the regular expression is matched.
2345 *
2346 * @retval true A match exists.
2347 * @retval false Otherwise.
2348 *
2349 * @throws an exception of type regex_error.
2350 */
2351 template<typename _Ch_type, class _Rx_traits>
2352 inline bool
2353 regex_match(const _Ch_type* __s,
2357 { return regex_match(__s, __s + _Rx_traits::length(__s), __re, __f); }
2358
2359 /**
2360 * @brief Indicates if there is a match between the regular expression @p e
2361 * and a string.
2362 *
2363 * @param __s [IN] The string to match.
2364 * @param __re [IN] The regular expression.
2365 * @param __flags [IN] Controls how the regular expression is matched.
2366 *
2367 * @retval true A match exists.
2368 * @retval false Otherwise.
2369 *
2370 * @throws an exception of type regex_error.
2371 */
2372 template<typename _Ch_traits, typename _Str_allocator,
2373 typename _Ch_type, typename _Rx_traits>
2374 inline bool
2379 { return regex_match(__s.begin(), __s.end(), __re, __flags); }
2380
2381 // [7.11.3] Function template regex_search
2382 /**
2383 * Searches for a regular expression within a range.
2384 * @param __s [IN] The start of the string to search.
2385 * @param __e [IN] One-past-the-end of the string to search.
2386 * @param __m [OUT] The match results.
2387 * @param __re [IN] The regular expression to search for.
2388 * @param __flags [IN] Search policy flags.
2389 * @retval true A match was found within the string.
2390 * @retval false No match was found within the string, the content of %m is
2391 * undefined.
2392 *
2393 * @throws an exception of type regex_error.
2394 */
2395 template<typename _Bi_iter, typename _Alloc,
2396 typename _Ch_type, typename _Rx_traits>
2397 inline bool
2398 regex_search(_Bi_iter __s, _Bi_iter __e,
2403 {
2404 return __detail::__regex_algo_impl(__s, __e, __m, __re, __flags,
2405 __detail::_RegexExecutorPolicy::_S_auto, false);
2406 }
2407
2408 /**
2409 * Searches for a regular expression within a range.
2410 * @param __first [IN] The start of the string to search.
2411 * @param __last [IN] One-past-the-end of the string to search.
2412 * @param __re [IN] The regular expression to search for.
2413 * @param __flags [IN] Search policy flags.
2414 * @retval true A match was found within the string.
2415 * @retval false No match was found within the string.
2416 *
2417 * @throws an exception of type regex_error.
2418 */
2419 template<typename _Bi_iter, typename _Ch_type, typename _Rx_traits>
2420 inline bool
2421 regex_search(_Bi_iter __first, _Bi_iter __last,
2425 {
2427 return regex_search(__first, __last, __what, __re, __flags);
2428 }
2429
2430 /**
2431 * @brief Searches for a regular expression within a C-string.
2432 * @param __s [IN] A C-string to search for the regex.
2433 * @param __m [OUT] The set of regex matches.
2434 * @param __e [IN] The regex to search for in @p s.
2435 * @param __f [IN] The search flags.
2436 * @retval true A match was found within the string.
2437 * @retval false No match was found within the string, the content of %m is
2438 * undefined.
2439 *
2440 * @throws an exception of type regex_error.
2441 */
2442 template<typename _Ch_type, class _Alloc, class _Rx_traits>
2443 inline bool
2444 regex_search(const _Ch_type* __s,
2449 { return regex_search(__s, __s + _Rx_traits::length(__s), __m, __e, __f); }
2450
2451 /**
2452 * @brief Searches for a regular expression within a C-string.
2453 * @param __s [IN] The C-string to search.
2454 * @param __e [IN] The regular expression to search for.
2455 * @param __f [IN] Search policy flags.
2456 * @retval true A match was found within the string.
2457 * @retval false No match was found within the string.
2458 *
2459 * @throws an exception of type regex_error.
2460 */
2461 template<typename _Ch_type, typename _Rx_traits>
2462 inline bool
2463 regex_search(const _Ch_type* __s,
2467 { return regex_search(__s, __s + _Rx_traits::length(__s), __e, __f); }
2468
2469 /**
2470 * @brief Searches for a regular expression within a string.
2471 * @param __s [IN] The string to search.
2472 * @param __e [IN] The regular expression to search for.
2473 * @param __flags [IN] Search policy flags.
2474 * @retval true A match was found within the string.
2475 * @retval false No match was found within the string.
2476 *
2477 * @throws an exception of type regex_error.
2478 */
2479 template<typename _Ch_traits, typename _String_allocator,
2480 typename _Ch_type, typename _Rx_traits>
2481 inline bool
2482 regex_search(const basic_string<_Ch_type, _Ch_traits,
2483 _String_allocator>& __s,
2487 { return regex_search(__s.begin(), __s.end(), __e, __flags); }
2488
2489 /**
2490 * @brief Searches for a regular expression within a string.
2491 * @param __s [IN] A C++ string to search for the regex.
2492 * @param __m [OUT] The set of regex matches.
2493 * @param __e [IN] The regex to search for in @p s.
2494 * @param __f [IN] The search flags.
2495 * @retval true A match was found within the string.
2496 * @retval false No match was found within the string, the content of %m is
2497 * undefined.
2498 *
2499 * @throws an exception of type regex_error.
2500 */
2501 template<typename _Ch_traits, typename _Ch_alloc,
2502 typename _Alloc, typename _Ch_type,
2503 typename _Rx_traits>
2504 inline bool
2506 match_results<typename basic_string<_Ch_type,
2507 _Ch_traits, _Ch_alloc>::const_iterator, _Alloc>& __m,
2511 { return regex_search(__s.begin(), __s.end(), __m, __e, __f); }
2512
2513 // _GLIBCXX_RESOLVE_LIB_DEFECTS
2514 // 2329. regex_search() with match_results should forbid temporary strings
2515 /// Prevent unsafe attempts to get match_results from a temporary string.
2516 template<typename _Ch_traits, typename _Ch_alloc,
2517 typename _Alloc, typename _Ch_type,
2518 typename _Rx_traits>
2519 bool
2521 match_results<typename basic_string<_Ch_type,
2522 _Ch_traits, _Ch_alloc>::const_iterator, _Alloc>&,
2526
2527 // std [28.11.4] Function template regex_replace
2528
2529 /// @cond undocumented
2530 template<typename _Out_iter, typename _Bi_iter,
2531 typename _Rx_traits, typename _Ch_type>
2532 _Out_iter
2533 __regex_replace(_Out_iter __out, _Bi_iter __first, _Bi_iter __last,
2535 const _Ch_type* __fmt, size_t __len,
2537 /// @endcond
2538
2539 /**
2540 * @brief Search for a regular expression within a range for multiple times,
2541 and replace the matched parts through filling a format string.
2542 * @param __out [OUT] The output iterator.
2543 * @param __first [IN] The start of the string to search.
2544 * @param __last [IN] One-past-the-end of the string to search.
2545 * @param __e [IN] The regular expression to search for.
2546 * @param __fmt [IN] The format string.
2547 * @param __flags [IN] Search and replace policy flags.
2548 *
2549 * @returns __out
2550 * @throws an exception of type regex_error.
2551 */
2552 template<typename _Out_iter, typename _Bi_iter,
2553 typename _Rx_traits, typename _Ch_type,
2554 typename _St, typename _Sa>
2555 inline _Out_iter
2556 regex_replace(_Out_iter __out, _Bi_iter __first, _Bi_iter __last,
2561 {
2562 return std::__regex_replace(__out, __first, __last, __e, __fmt.c_str(),
2563 __fmt.length(), __flags);
2564 }
2565
2566 /**
2567 * @brief Search for a regular expression within a range for multiple times,
2568 and replace the matched parts through filling a format C-string.
2569 * @param __out [OUT] The output iterator.
2570 * @param __first [IN] The start of the string to search.
2571 * @param __last [IN] One-past-the-end of the string to search.
2572 * @param __e [IN] The regular expression to search for.
2573 * @param __fmt [IN] The format C-string.
2574 * @param __flags [IN] Search and replace policy flags.
2575 *
2576 * @returns __out
2577 * @throws an exception of type regex_error.
2578 */
2579 template<typename _Out_iter, typename _Bi_iter,
2580 typename _Rx_traits, typename _Ch_type>
2581 _Out_iter
2582 regex_replace(_Out_iter __out, _Bi_iter __first, _Bi_iter __last,
2584 const _Ch_type* __fmt,
2587 {
2588 return std::__regex_replace(__out, __first, __last, __e, __fmt,
2590 __flags);
2591 }
2592
2593
2594 /**
2595 * @brief Search for a regular expression within a string for multiple times,
2596 and replace the matched parts through filling a format string.
2597 * @param __s [IN] The string to search and replace.
2598 * @param __e [IN] The regular expression to search for.
2599 * @param __fmt [IN] The format string.
2600 * @param __flags [IN] Search and replace policy flags.
2601 *
2602 * @returns The string after replacing.
2603 * @throws an exception of type regex_error.
2604 */
2605 template<typename _Rx_traits, typename _Ch_type,
2606 typename _St, typename _Sa, typename _Fst, typename _Fsa>
2607 inline basic_string<_Ch_type, _St, _Sa>
2613 {
2616 __s.begin(), __s.end(), __e, __fmt, __flags);
2617 return __result;
2618 }
2619
2620 /**
2621 * @brief Search for a regular expression within a string for multiple times,
2622 and replace the matched parts through filling a format C-string.
2623 * @param __s [IN] The string to search and replace.
2624 * @param __e [IN] The regular expression to search for.
2625 * @param __fmt [IN] The format C-string.
2626 * @param __flags [IN] Search and replace policy flags.
2627 *
2628 * @returns The string after replacing.
2629 * @throws an exception of type regex_error.
2630 */
2631 template<typename _Rx_traits, typename _Ch_type,
2632 typename _St, typename _Sa>
2633 inline basic_string<_Ch_type, _St, _Sa>
2636 const _Ch_type* __fmt,
2639 {
2642 __s.begin(), __s.end(), __e, __fmt, __flags);
2643 return __result;
2644 }
2645
2646 /**
2647 * @brief Search for a regular expression within a C-string for multiple
2648 times, and replace the matched parts through filling a format string.
2649 * @param __s [IN] The C-string to search and replace.
2650 * @param __e [IN] The regular expression to search for.
2651 * @param __fmt [IN] The format string.
2652 * @param __flags [IN] Search and replace policy flags.
2653 *
2654 * @returns The string after replacing.
2655 * @throws an exception of type regex_error.
2656 */
2657 template<typename _Rx_traits, typename _Ch_type,
2658 typename _St, typename _Sa>
2659 inline basic_string<_Ch_type>
2660 regex_replace(const _Ch_type* __s,
2665 {
2666 basic_string<_Ch_type> __result;
2667 regex_replace(std::back_inserter(__result), __s,
2669 __e, __fmt, __flags);
2670 return __result;
2671 }
2672
2673 /**
2674 * @brief Search for a regular expression within a C-string for multiple
2675 times, and replace the matched parts through filling a format C-string.
2676 * @param __s [IN] The C-string to search and replace.
2677 * @param __e [IN] The regular expression to search for.
2678 * @param __fmt [IN] The format C-string.
2679 * @param __flags [IN] Search and replace policy flags.
2680 *
2681 * @returns The string after replacing.
2682 * @throws an exception of type regex_error.
2683 */
2684 template<typename _Rx_traits, typename _Ch_type>
2685 inline basic_string<_Ch_type>
2686 regex_replace(const _Ch_type* __s,
2688 const _Ch_type* __fmt,
2691 {
2692 basic_string<_Ch_type> __result;
2693 regex_replace(std::back_inserter(__result), __s,
2695 __e, __fmt, __flags);
2696 return __result;
2697 }
2698
2699 /// @}
2700
2701_GLIBCXX_BEGIN_NAMESPACE_CXX11
2702
2703 // std [28.12] Class template regex_iterator
2704 /**
2705 * An iterator adaptor that will provide repeated calls of regex_search over
2706 * a range until no more matches remain.
2707 *
2708 * @headerfile regex
2709 * @since C++11
2710 */
2711 template<typename _Bi_iter,
2712 typename _Ch_type = typename iterator_traits<_Bi_iter>::value_type,
2713 typename _Rx_traits = regex_traits<_Ch_type> >
2715 {
2716 public:
2718 typedef match_results<_Bi_iter> value_type;
2719 typedef std::ptrdiff_t difference_type;
2720 typedef const value_type* pointer;
2721 typedef const value_type& reference;
2723
2724 /**
2725 * @brief Provides a singular iterator, useful for indicating
2726 * one-past-the-end of a range.
2727 */
2728 regex_iterator() = default;
2729
2730 /**
2731 * Constructs a %regex_iterator...
2732 * @param __a [IN] The start of a text range to search.
2733 * @param __b [IN] One-past-the-end of the text range to search.
2734 * @param __re [IN] The regular expression to match.
2735 * @param __m [IN] Policy flags for match rules.
2736 */
2737 regex_iterator(_Bi_iter __a, _Bi_iter __b, const regex_type& __re,
2740 : _M_begin(__a), _M_end(__b), _M_pregex(&__re), _M_flags(__m), _M_match()
2741 {
2742 if (!regex_search(_M_begin, _M_end, _M_match, *_M_pregex, _M_flags))
2743 *this = regex_iterator();
2744 }
2745
2746 // _GLIBCXX_RESOLVE_LIB_DEFECTS
2747 // 2332. regex_iterator should forbid temporary regexes
2748 regex_iterator(_Bi_iter, _Bi_iter, const regex_type&&,
2751
2752 /// Copy constructs a %regex_iterator.
2754
2755 /// Copy assigns one %regex_iterator to another.
2757 operator=(const regex_iterator&) = default;
2758
2759 ~regex_iterator() = default;
2760
2761 /**
2762 * @brief Tests the equivalence of two regex iterators.
2763 */
2764 bool
2765 operator==(const regex_iterator&) const noexcept;
2766
2767#if __cplusplus >= 202002L
2768 // _GLIBCXX_RESOLVE_LIB_DEFECTS
2769 // 3719. Directory iterators should be usable with default sentinel
2770 bool operator==(default_sentinel_t) const noexcept
2771 { return _M_pregex == nullptr; }
2772#endif
2773
2774#if __cpp_impl_three_way_comparison < 201907L
2775 /**
2776 * @brief Tests the inequivalence of two regex iterators.
2777 */
2778 bool
2779 operator!=(const regex_iterator& __rhs) const noexcept
2780 { return !(*this == __rhs); }
2781#endif
2782
2783 /**
2784 * @brief Dereferences a %regex_iterator.
2785 */
2786 const value_type&
2787 operator*() const noexcept
2788 { return _M_match; }
2789
2790 /**
2791 * @brief Selects a %regex_iterator member.
2792 */
2793 const value_type*
2794 operator->() const noexcept
2795 { return &_M_match; }
2796
2797 /**
2798 * @brief Increments a %regex_iterator.
2799 */
2802
2803 /**
2804 * @brief Postincrements a %regex_iterator.
2805 */
2808 {
2809 auto __tmp = *this;
2810 ++(*this);
2811 return __tmp;
2812 }
2813
2814 private:
2815 _Bi_iter _M_begin {};
2816 _Bi_iter _M_end {};
2817 const regex_type* _M_pregex = nullptr;
2819 match_results<_Bi_iter> _M_match;
2820 };
2821
2822 typedef regex_iterator<const char*> cregex_iterator;
2823 typedef regex_iterator<string::const_iterator> sregex_iterator;
2824#ifdef _GLIBCXX_USE_WCHAR_T
2825 typedef regex_iterator<const wchar_t*> wcregex_iterator;
2826 typedef regex_iterator<wstring::const_iterator> wsregex_iterator;
2827#endif
2828
2829 // [7.12.2] Class template regex_token_iterator
2830 /**
2831 * Iterates over submatches in a range (or @a splits a text string).
2832 *
2833 * The purpose of this iterator is to enumerate all, or all specified,
2834 * matches of a regular expression within a text range. The dereferenced
2835 * value of an iterator of this class is a std::sub_match object.
2836 *
2837 * @headerfile regex
2838 * @since C++11
2839 */
2840 template<typename _Bi_iter,
2841 typename _Ch_type = typename iterator_traits<_Bi_iter>::value_type,
2842 typename _Rx_traits = regex_traits<_Ch_type> >
2844 {
2845 public:
2848 typedef std::ptrdiff_t difference_type;
2849 typedef const value_type* pointer;
2850 typedef const value_type& reference;
2852
2853 public:
2854 /**
2855 * @brief Default constructs a %regex_token_iterator.
2856 *
2857 * A default-constructed %regex_token_iterator is a singular iterator
2858 * that will compare equal to the one-past-the-end value for any
2859 * iterator of the same type.
2860 */
2862 : _M_position(), _M_subs(), _M_suffix(), _M_n(0), _M_result(nullptr),
2863 _M_has_m1(false)
2864 { }
2865
2866 /**
2867 * Constructs a %regex_token_iterator...
2868 * @param __a [IN] The start of the text to search.
2869 * @param __b [IN] One-past-the-end of the text to search.
2870 * @param __re [IN] The regular expression to search for.
2871 * @param __submatch [IN] Which submatch to return. There are some
2872 * special values for this parameter:
2873 * - -1 each enumerated subexpression does NOT
2874 * match the regular expression (aka field
2875 * splitting)
2876 * - 0 the entire string matching the
2877 * subexpression is returned for each match
2878 * within the text.
2879 * - >0 enumerates only the indicated
2880 * subexpression from a match within the text.
2881 * @param __m [IN] Policy flags for match rules.
2882 */
2883 regex_token_iterator(_Bi_iter __a, _Bi_iter __b, const regex_type& __re,
2884 int __submatch = 0,
2887 : _M_position(__a, __b, __re, __m), _M_subs(1, __submatch), _M_n(0)
2888 { _M_init(__a, __b); }
2889
2890 /**
2891 * Constructs a %regex_token_iterator...
2892 * @param __a [IN] The start of the text to search.
2893 * @param __b [IN] One-past-the-end of the text to search.
2894 * @param __re [IN] The regular expression to search for.
2895 * @param __submatches [IN] A list of subexpressions to return for each
2896 * regular expression match within the text.
2897 * @param __m [IN] Policy flags for match rules.
2898 */
2899 regex_token_iterator(_Bi_iter __a, _Bi_iter __b,
2900 const regex_type& __re,
2901 const std::vector<int>& __submatches,
2904 : _M_position(__a, __b, __re, __m), _M_subs(__submatches), _M_n(0)
2905 { _M_init(__a, __b); }
2906
2907 /**
2908 * Constructs a %regex_token_iterator...
2909 * @param __a [IN] The start of the text to search.
2910 * @param __b [IN] One-past-the-end of the text to search.
2911 * @param __re [IN] The regular expression to search for.
2912 * @param __submatches [IN] A list of subexpressions to return for each
2913 * regular expression match within the text.
2914 * @param __m [IN] Policy flags for match rules.
2915 */
2916 regex_token_iterator(_Bi_iter __a, _Bi_iter __b,
2917 const regex_type& __re,
2918 initializer_list<int> __submatches,
2921 : _M_position(__a, __b, __re, __m), _M_subs(__submatches), _M_n(0)
2922 { _M_init(__a, __b); }
2923
2924 /**
2925 * Constructs a %regex_token_iterator...
2926 * @param __a [IN] The start of the text to search.
2927 * @param __b [IN] One-past-the-end of the text to search.
2928 * @param __re [IN] The regular expression to search for.
2929 * @param __submatches [IN] A list of subexpressions to return for each
2930 * regular expression match within the text.
2931 * @param __m [IN] Policy flags for match rules.
2932 */
2933 template<std::size_t _Nm>
2934 regex_token_iterator(_Bi_iter __a, _Bi_iter __b,
2935 const regex_type& __re,
2936 const int (&__submatches)[_Nm],
2939 : _M_position(__a, __b, __re, __m),
2940 _M_subs(__submatches, __submatches + _Nm), _M_n(0)
2941 { _M_init(__a, __b); }
2942
2943 // _GLIBCXX_RESOLVE_LIB_DEFECTS
2944 // 2332. regex_token_iterator should forbid temporary regexes
2945 regex_token_iterator(_Bi_iter, _Bi_iter, const regex_type&&, int = 0,
2948 regex_token_iterator(_Bi_iter, _Bi_iter, const regex_type&&,
2949 const std::vector<int>&,
2952 regex_token_iterator(_Bi_iter, _Bi_iter, const regex_type&&,
2956 template <std::size_t _Nm>
2957 regex_token_iterator(_Bi_iter, _Bi_iter, const regex_type&&,
2958 const int (&)[_Nm],
2961
2962 /**
2963 * @brief Copy constructs a %regex_token_iterator.
2964 * @param __rhs [IN] A %regex_token_iterator to copy.
2965 */
2967 : _M_position(__rhs._M_position), _M_subs(__rhs._M_subs),
2968 _M_suffix(__rhs._M_suffix), _M_n(__rhs._M_n), _M_has_m1(__rhs._M_has_m1)
2969 { _M_normalize_result(); }
2970
2971 /**
2972 * @brief Assigns a %regex_token_iterator to another.
2973 * @param __rhs [IN] A %regex_token_iterator to copy.
2974 */
2977
2978 /**
2979 * @brief Compares a %regex_token_iterator to another for equality.
2980 */
2981 bool
2983
2984#if __cplusplus >= 202002L
2985 // _GLIBCXX_RESOLVE_LIB_DEFECTS
2986 // 3719. Directory iterators should be usable with default sentinel
2987 bool operator==(default_sentinel_t) const noexcept
2988 { return _M_end_of_seq(); }
2989#endif
2990
2991#if __cpp_impl_three_way_comparison < 201907L
2992 /**
2993 * @brief Compares a %regex_token_iterator to another for inequality.
2994 */
2995 bool
2996 operator!=(const regex_token_iterator& __rhs) const
2997 { return !(*this == __rhs); }
2998#endif
2999
3000 /**
3001 * @brief Dereferences a %regex_token_iterator.
3002 */
3003 const value_type&
3005 { return *_M_result; }
3006
3007 /**
3008 * @brief Selects a %regex_token_iterator member.
3009 */
3010 const value_type*
3012 { return _M_result; }
3013
3014 /**
3015 * @brief Increments a %regex_token_iterator.
3016 */
3019
3020 /**
3021 * @brief Postincrements a %regex_token_iterator.
3022 */
3025 {
3026 auto __tmp = *this;
3027 ++(*this);
3028 return __tmp;
3029 }
3030
3031 private:
3033
3034 void
3035 _M_init(_Bi_iter __a, _Bi_iter __b);
3036
3037 const value_type&
3038 _M_current_match() const
3039 {
3040 if (_M_subs[_M_n] == -1)
3041 return (*_M_position).prefix();
3042 else
3043 return (*_M_position)[_M_subs[_M_n]];
3044 }
3045
3046 constexpr bool
3047 _M_end_of_seq() const noexcept
3048 { return _M_result == nullptr; }
3049
3050 // [28.12.2.2.4]
3051 void
3052 _M_normalize_result()
3053 {
3054 if (_M_position != _Position())
3055 _M_result = &_M_current_match();
3056 else if (_M_has_m1)
3057 _M_result = &_M_suffix;
3058 else
3059 _M_result = nullptr;
3060 }
3061
3062 _Position _M_position;
3063 std::vector<int> _M_subs;
3064 value_type _M_suffix;
3065 std::size_t _M_n;
3066 const value_type* _M_result;
3067
3068 // Show whether _M_subs contains -1
3069 bool _M_has_m1;
3070 };
3071
3072 /** @brief Token iterator for C-style NULL-terminated strings. */
3074
3075 /** @brief Token iterator for standard strings. */
3077
3078#ifdef _GLIBCXX_USE_WCHAR_T
3079 /** @brief Token iterator for C-style NULL-terminated wide strings. */
3081
3082 /** @brief Token iterator for standard wide-character strings. */
3084#endif
3085
3086 ///@} // group regex
3087
3088_GLIBCXX_END_NAMESPACE_CXX11
3089_GLIBCXX_END_NAMESPACE_VERSION
3090} // namespace
3091
3092#include <bits/regex.tcc>
integral_constant< bool, true > true_type
The type used as a compile-time boolean with true value.
Definition: type_traits:82
integral_constant< bool, false > false_type
The type used as a compile-time boolean with false value.
Definition: type_traits:85
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
Definition: move.h:104
void swap(any &__x, any &__y) noexcept
Exchange the states of two any objects.
Definition: any:429
constexpr _Tp * __addressof(_Tp &__r) noexcept
Same as C++11 std::addressof.
Definition: move.h:49
constexpr const _Tp & min(const _Tp &, const _Tp &)
This does what you think it does.
Definition: stl_algobase.h:230
bool operator>=(typename iterator_traits< _Bi_iter >::value_type const &__lhs, const sub_match< _Bi_iter > &__rhs)
Tests the ordering of a character and a regular expression submatch.
Definition: regex.h:1576
sub_match< wstring::const_iterator > wssub_match
Regex submatch over a standard wide string.
Definition: regex.h:1078
bool operator!=(const sub_match< _Bi_iter > &__lhs, typename iterator_traits< _Bi_iter >::value_type const &__rhs)
Tests the inequivalence of a regular expression submatch and a character.
Definition: regex.h:1637
sub_match< string::const_iterator > ssub_match
Standard regex submatch over a standard string.
Definition: regex.h:1071
bool operator==(const __sub_match_string< _Bi_iter, _Ch_traits, _Ch_alloc > &__lhs, const sub_match< _Bi_iter > &__rhs)
Tests the equivalence of a string and a regular expression submatch.
Definition: regex.h:1189
bool operator!=(const __sub_match_string< _Bi_iter, _Ch_traits, _Ch_alloc > &__lhs, const sub_match< _Bi_iter > &__rhs)
Tests the inequivalence of a string and a regular expression submatch.
Definition: regex.h:1202
sub_match< const char * > csub_match
Standard regex submatch over a C-style null-terminated string.
Definition: regex.h:1068
regex_token_iterator< const char * > cregex_token_iterator
Token iterator for C-style NULL-terminated strings.
Definition: regex.h:3073
bool operator==(const sub_match< _Bi_iter > &__lhs, const __sub_match_string< _Bi_iter, _Ch_traits, _Ch_alloc > &__rhs)
Tests the equivalence of a regular expression submatch and a string.
Definition: regex.h:1264
bool operator>=(const __sub_match_string< _Bi_iter, _Ch_traits, _Ch_alloc > &__lhs, const sub_match< _Bi_iter > &__rhs)
Tests the ordering of a string and a regular expression submatch.
Definition: regex.h:1238
regex_token_iterator< wstring::const_iterator > wsregex_token_iterator
Token iterator for standard wide-character strings.
Definition: regex.h:3083
bool operator==(const sub_match< _Bi_iter > &__lhs, typename iterator_traits< _Bi_iter >::value_type const &__rhs)
Tests the equivalence of a regular expression submatch and a character.
Definition: regex.h:1603
bool operator>=(const sub_match< _Bi_iter > &__lhs, typename iterator_traits< _Bi_iter >::value_type const *__rhs)
Tests the ordering of a regular expression submatch and a C string.
Definition: regex.h:1499
bool operator==(const sub_match< _Bi_iter > &__lhs, typename iterator_traits< _Bi_iter >::value_type const *__rhs)
Tests the equivalence of a regular expression submatch and a C string.
Definition: regex.h:1431
bool operator!=(const sub_match< _Bi_iter > &__lhs, typename iterator_traits< _Bi_iter >::value_type const *__rhs)
Tests the inequivalence of a regular expression submatch and a string.
Definition: regex.h:1463
bool operator!=(typename iterator_traits< _Bi_iter >::value_type const *__lhs, const sub_match< _Bi_iter > &__rhs)
Tests the inequivalence of a C string and a regular expression submatch.
Definition: regex.h:1369
regex_token_iterator< const wchar_t * > wcregex_token_iterator
Token iterator for C-style NULL-terminated wide strings.
Definition: regex.h:3080
void swap(basic_regex< _Ch_type, _Rx_traits > &__lhs, basic_regex< _Ch_type, _Rx_traits > &__rhs) noexcept
Swaps the contents of two regular expression objects.
Definition: regex.h:896
bool operator!=(const match_results< _Bi_iter, _Alloc > &__m1, const match_results< _Bi_iter, _Alloc > &__m2)
Compares two match_results for inequality.
Definition: regex.h:2193
bool operator>(const sub_match< _Bi_iter > &__lhs, typename iterator_traits< _Bi_iter >::value_type const &__rhs)
Tests the ordering of a regular expression submatch and a character.
Definition: regex.h:1663
bool operator>(const sub_match< _Bi_iter > &__lhs, typename iterator_traits< _Bi_iter >::value_type const *__rhs)
Tests the ordering of a regular expression submatch and a C string.
Definition: regex.h:1487
bool operator>=(const sub_match< _Bi_iter > &__lhs, typename iterator_traits< _Bi_iter >::value_type const &__rhs)
Tests the ordering of a regular expression submatch and a character.
Definition: regex.h:1676
bool operator>(typename iterator_traits< _Bi_iter >::value_type const &__lhs, const sub_match< _Bi_iter > &__rhs)
Tests the ordering of a character and a regular expression submatch.
Definition: regex.h:1563
basic_regex< char > regex
Standard regular expressions.
Definition: regex.h:879
_Out_iter regex_replace(_Out_iter __out, _Bi_iter __first, _Bi_iter __last, const basic_regex< _Ch_type, _Rx_traits > &__e, const basic_string< _Ch_type, _St, _Sa > &__fmt, regex_constants::match_flag_type __flags=regex_constants::match_default)
Search for a regular expression within a range for multiple times, and replace the matched parts thro...
Definition: regex.h:2556
sub_match< const wchar_t * > wcsub_match
Regex submatch over a C-style null-terminated wide string.
Definition: regex.h:1075
regex_token_iterator< string::const_iterator > sregex_token_iterator
Token iterator for standard strings.
Definition: regex.h:3076
bool operator>=(const sub_match< _Bi_iter > &__lhs, const __sub_match_string< _Bi_iter, _Ch_traits, _Ch_alloc > &__rhs)
Tests the ordering of a regular expression submatch and a string.
Definition: regex.h:1331
bool regex_match(_Bi_iter __s, _Bi_iter __e, match_results< _Bi_iter, _Alloc > &__m, const basic_regex< _Ch_type, _Rx_traits > &__re, regex_constants::match_flag_type __flags=regex_constants::match_default)
Determines if there is a match between the regular expression e and all of the character sequence [fi...
Definition: regex.h:2241
bool operator==(const match_results< _Bi_iter, _Alloc > &__m1, const match_results< _Bi_iter, _Alloc > &__m2)
Compares two match_results for equality.
Definition: regex.h:2166
bool regex_search(_Bi_iter __s, _Bi_iter __e, match_results< _Bi_iter, _Alloc > &__m, const basic_regex< _Ch_type, _Rx_traits > &__re, regex_constants::match_flag_type __flags=regex_constants::match_default)
Definition: regex.h:2398
bool operator>(const sub_match< _Bi_iter > &__lhs, const __sub_match_string< _Bi_iter, _Ch_traits, _Ch_alloc > &__rhs)
Tests the ordering of a regular expression submatch and a string.
Definition: regex.h:1319
bool operator>(typename iterator_traits< _Bi_iter >::value_type const *__lhs, const sub_match< _Bi_iter > &__rhs)
Tests the ordering of a C string and a regular expression submatch.
Definition: regex.h:1393
bool operator>=(const sub_match< _BiIter > &__lhs, const sub_match< _BiIter > &__rhs)
Tests the ordering of two regular expression submatches.
Definition: regex.h:1155
bool operator>(const sub_match< _BiIter > &__lhs, const sub_match< _BiIter > &__rhs)
Tests the ordering of two regular expression submatches.
Definition: regex.h:1166
void swap(match_results< _Bi_iter, _Alloc > &__lhs, match_results< _Bi_iter, _Alloc > &__rhs) noexcept
Swaps two match results.
Definition: regex.h:2210
bool operator==(typename iterator_traits< _Bi_iter >::value_type const &__lhs, const sub_match< _Bi_iter > &__rhs)
Tests the equivalence of a character and a regular expression submatch.
Definition: regex.h:1524
bool operator>(const __sub_match_string< _Bi_iter, _Ch_traits, _Ch_alloc > &__lhs, const sub_match< _Bi_iter > &__rhs)
Tests the ordering of a string and a regular expression submatch.
Definition: regex.h:1226
bool operator!=(typename iterator_traits< _Bi_iter >::value_type const &__lhs, const sub_match< _Bi_iter > &__rhs)
Tests the inequivalence of a character and a regular expression submatch.
Definition: regex.h:1537
basic_regex< wchar_t > wregex
Standard wide-character regular expressions.
Definition: regex.h:883
bool operator==(typename iterator_traits< _Bi_iter >::value_type const *__lhs, const sub_match< _Bi_iter > &__rhs)
Tests the equivalence of a C string and a regular expression submatch.
Definition: regex.h:1356
bool operator==(const sub_match< _BiIter > &__lhs, const sub_match< _BiIter > &__rhs)
Tests the equivalence of two regular expression submatches.
Definition: regex.h:1093
bool operator!=(const sub_match< _BiIter > &__lhs, const sub_match< _BiIter > &__rhs)
Tests the inequivalence of two regular expression submatches.
Definition: regex.h:1122
bool operator!=(const sub_match< _Bi_iter > &__lhs, const __sub_match_string< _Bi_iter, _Ch_traits, _Ch_alloc > &__rhs)
Tests the inequivalence of a regular expression submatch and a string.
Definition: regex.h:1295
bool operator>=(typename iterator_traits< _Bi_iter >::value_type const *__lhs, const sub_match< _Bi_iter > &__rhs)
Tests the ordering of a C string and a regular expression submatch.
Definition: regex.h:1405
constexpr back_insert_iterator< _Container > back_inserter(_Container &__x)
ISO C++ entities toplevel namespace is std.
constexpr iterator_traits< _InputIterator >::difference_type distance(_InputIterator __first, _InputIterator __last)
A generalization of pointer arithmetic.
constexpr bitset< _Nb > operator^(const bitset< _Nb > &__x, const bitset< _Nb > &__y) noexcept
Global bitwise operations on bitsets.
Definition: bitset:1579
std::basic_ostream< _CharT, _Traits > & operator<<(std::basic_ostream< _CharT, _Traits > &__os, const bitset< _Nb > &__x)
Global I/O operators for bitsets.
Definition: bitset:1685
constexpr bitset< _Nb > operator|(const bitset< _Nb > &__x, const bitset< _Nb > &__y) noexcept
Global bitwise operations on bitsets.
Definition: bitset:1569
constexpr bitset< _Nb > operator&(const bitset< _Nb > &__x, const bitset< _Nb > &__y) noexcept
Global bitwise operations on bitsets.
Definition: bitset:1559
GNU extensions for public use.
__numeric_traits_integer< _Tp > __int_traits
Convenience alias for __numeric_traits<integer-type>.
constexpr _Iterator __base(_Iterator __it)
constexpr syntax_option_type collate
constexpr syntax_option_type ECMAScript
constexpr syntax_option_type egrep
syntax_option_type
This is a bitmask type indicating how to interpret the regex.
constexpr syntax_option_type multiline
constexpr match_flag_type match_default
constexpr syntax_option_type awk
constexpr syntax_option_type extended
constexpr syntax_option_type basic
match_flag_type
This is a bitmask type indicating regex matching rules.
constexpr syntax_option_type icase
constexpr syntax_option_type optimize
constexpr match_flag_type format_default
constexpr syntax_option_type nosubs
constexpr syntax_option_type grep
initializer_list
is_same
Definition: type_traits:1369
typename _Size< _Alloc, difference_type >::type size_type
The allocator's size type.
Basis for explicit traits specializations.
Definition: char_traits.h:324
Managing sequences of characters and character-like objects.
Definition: cow_string.h:115
const _CharT * data() const noexcept
Return const pointer to contents.
Definition: cow_string.h:2218
size_type length() const noexcept
Returns the number of characters in the string, not including any null-termination.
Definition: cow_string.h:919
size_type size() const noexcept
Returns the number of characters in the string, not including any null-termination.
Definition: cow_string.h:913
iterator begin()
Definition: cow_string.h:803
iterator end()
Definition: cow_string.h:822
const _CharT * c_str() const noexcept
Return const pointer to null-terminated contents.
Definition: cow_string.h:2206
Traits class for iterators.
Container class for localization functionality.
Facet for localized string comparison.
Primary class template ctype facet.
A regular expression.
Definition: regex.h:419
basic_regex & assign(const _Ch_type *__p, flag_type __flags=ECMAScript)
Assigns a new regular expression to a regex object from a C-style null-terminated string containing a...
Definition: regex.h:638
basic_regex & assign(const _Ch_type *__p, size_t __len, flag_type __flags=ECMAScript)
Assigns a new regular expression to a regex object from a C-style string containing a regular express...
Definition: regex.h:660
locale_type getloc() const noexcept
Gets the locale currently imbued in the regular expression object.
Definition: regex.h:779
unsigned int mark_count() const noexcept
Gets the number of marked subexpressions within the regular expression.
Definition: regex.h:745
basic_regex & assign(_InputIterator __first, _InputIterator __last, flag_type __flags=ECMAScript)
Assigns a new regular expression to a regex object.
Definition: regex.h:701
locale_type imbue(locale_type __loc)
Imbues the regular expression object with the given locale.
Definition: regex.h:767
basic_regex(const basic_regex &__rhs)=default
Copy-constructs a basic regular expression.
basic_regex & assign(initializer_list< _Ch_type > __l, flag_type __flags=ECMAScript)
Assigns a new regular expression to a regex object.
Definition: regex.h:733
basic_regex & assign(basic_regex &&__rhs) noexcept
Move-assigns one regular expression to another.
Definition: regex.h:621
flag_type flags() const noexcept
Gets the flags used to construct the regular expression or in the last call to assign().
Definition: regex.h:757
basic_regex & operator=(basic_regex &&)=default
Move-assigns one regular expression to another.
basic_regex(const _Ch_type *__p, flag_type __f=ECMAScript)
Constructs a basic regular expression from the sequence [__p, __p + char_traits<_Ch_type>::length(__p...
Definition: regex.h:472
void swap(basic_regex &__rhs) noexcept
Swaps the contents of two regular expression objects.
Definition: regex.h:789
basic_regex(const std::basic_string< _Ch_type, _Ch_traits, _Ch_alloc > &__s, flag_type __f=ECMAScript)
Constructs a basic regular expression from the string s interpreted according to the flags in f.
Definition: regex.h:519
basic_regex(_FwdIter __first, _FwdIter __last, flag_type __f=ECMAScript)
Constructs a basic regular expression from the range [first, last) interpreted according to the flags...
Definition: regex.h:538
basic_regex & operator=(const basic_regex &)=default
Assigns one regular expression to another.
basic_regex(const _Ch_type *__p, std::size_t __len, flag_type __f=ECMAScript)
Constructs a basic regular expression from the sequence [p, p + len) interpreted according to the fla...
Definition: regex.h:487
basic_regex & operator=(initializer_list< _Ch_type > __l)
Replaces a regular expression with a new one constructed from an initializer list.
Definition: regex.h:591
basic_regex & assign(const basic_string< _Ch_type, _Ch_traits, _Alloc > &__s, flag_type __flags=ECMAScript)
Assigns a new regular expression to a regex object from a string containing a regular expression patt...
Definition: regex.h:679
basic_regex(basic_regex &&__rhs) noexcept=default
Move-constructs a basic regular expression.
basic_regex(initializer_list< _Ch_type > __l, flag_type __f=ECMAScript)
Constructs a basic regular expression from an initializer list.
Definition: regex.h:550
basic_regex & operator=(const _Ch_type *__p)
Replaces a regular expression with a new one constructed from a C-style null-terminated string.
Definition: regex.h:579
basic_regex & assign(const basic_regex &__rhs) noexcept
Assigns one regular expression to another.
Definition: regex.h:612
basic_regex() noexcept
Definition: regex.h:456
basic_regex & operator=(const basic_string< _Ch_type, _Ch_traits, _Alloc > &__s)
Replaces a regular expression with a new one constructed from a string.
Definition: regex.h:602
~basic_regex()
Destroys a basic regular expression.
Definition: regex.h:556
The results of a match or search operation.
Definition: regex.h:1740
allocator_type get_allocator() const noexcept
Gets a copy of the allocator.
Definition: regex.h:2067
void swap(match_results &__that) noexcept
Swaps the contents of two match_results.
Definition: regex.h:2081
difference_type position(size_type __sub=0) const
Gets the offset of the beginning of the indicated submatch.
Definition: regex.h:1901
size_type size() const noexcept
Gets the number of matches and submatches.
Definition: regex.h:1854
_Out_iter format(_Out_iter __out, const char_type *__fmt_first, const char_type *__fmt_last, match_flag_type __flags=regex_constants::format_default) const
difference_type length(size_type __sub=0) const
Gets the length of the indicated submatch.
Definition: regex.h:1886
const_reference prefix() const
Gets a sub_match representing the match prefix.
Definition: regex.h:1946
size_type max_size() const noexcept
Gets the number of matches and submatches.
Definition: regex.h:1858
basic_string< char_type, _St, _Sa > format(const basic_string< char_type, _St, _Sa > &__fmt, match_flag_type __flags=regex_constants::format_default) const
Definition: regex.h:2033
const_reference operator[](size_type __sub) const
Gets a sub_match reference for the match or submatch.
Definition: regex.h:1929
match_results(match_results &&) noexcept=default
Move constructs a match_results.
match_results(const _Alloc &__a) noexcept
Constructs a default match_results container.
Definition: regex.h:1798
match_results(const match_results &)=default
Copy constructs a match_results.
_Out_iter format(_Out_iter __out, const basic_string< char_type, _St, _Sa > &__fmt, match_flag_type __flags=regex_constants::format_default) const
Definition: regex.h:2021
const_iterator cbegin() const noexcept
Gets an iterator to the start of the sub_match collection.
Definition: regex.h:1978
string_type str(size_type __sub=0) const
Gets the match or submatch converted to a string type.
Definition: regex.h:1914
const_iterator end() const noexcept
Gets an iterator to one-past-the-end of the collection.
Definition: regex.h:1985
const_reference suffix() const
Gets a sub_match representing the match suffix.
Definition: regex.h:1961
bool ready() const noexcept
Indicates if the match_results is ready.
Definition: regex.h:1837
bool empty() const noexcept
Indicates if the match_results contains no results.
Definition: regex.h:1867
string_type format(const char_type *__fmt, match_flag_type __flags=regex_constants::format_default) const
Definition: regex.h:2045
match_results()
Constructs a default match_results container.
Definition: regex.h:1791
const_iterator cend() const noexcept
Gets an iterator to one-past-the-end of the collection.
Definition: regex.h:1992
const_iterator begin() const noexcept
Gets an iterator to the start of the sub_match collection.
Definition: regex.h:1971
Takes a regex and an input string and does the matching.
Describes aspects of a regular expression.
Definition: regex.h:97
char_type translate(char_type __c) const
Performs the identity translation.
Definition: regex.h:200
string_type lookup_collatename(_Fwd_iter __first, _Fwd_iter __last) const
Gets a collation element by name.
char_class_type lookup_classname(_Fwd_iter __first, _Fwd_iter __last, bool __icase=false) const
Maps one or more characters to a named character classification.
static std::size_t length(const char_type *__p)
Gives the length of a C-style string starting at __p.
Definition: regex.h:189
string_type transform_primary(_Fwd_iter __first, _Fwd_iter __last) const
Gets a sort key for a character sequence, independent of case.
Definition: regex.h:266
regex_traits()
Constructs a default traits object.
Definition: regex.h:176
int value(_Ch_type __ch, int __radix) const
Converts a digit to an int.
char_type translate_nocase(char_type __c) const
Translates a character into a case-insensitive equivalent.
Definition: regex.h:213
locale_type getloc() const
Gets a copy of the current locale in use by the regex_traits object.
Definition: regex.h:389
bool isctype(_Ch_type __c, char_class_type __f) const
Determines if c is a member of an identified class.
locale_type imbue(locale_type __loc)
Imbues the regex_traits object with a copy of a new locale.
Definition: regex.h:378
string_type transform(_Fwd_iter __first, _Fwd_iter __last) const
Gets a sort key for a character sequence.
Definition: regex.h:242
difference_type length() const noexcept
Gets the length of the matching sequence.
Definition: regex.h:941
int compare(const value_type *__s) const
Compares this sub_match to a string.
Definition: regex.h:998
string_type str() const
Gets the matching sequence as a string.
Definition: regex.h:963
int compare(const sub_match &__s) const
Compares this and another matched sequence.
Definition: regex.h:980
int compare(const string_type &__s) const
Compares this sub_match to a string.
Definition: regex.h:994
const value_type * operator->() const noexcept
Selects a regex_iterator member.
Definition: regex.h:2794
regex_iterator operator++(int)
Postincrements a regex_iterator.
Definition: regex.h:2807
regex_iterator(_Bi_iter __a, _Bi_iter __b, const regex_type &__re, regex_constants::match_flag_type __m=regex_constants::match_default)
Definition: regex.h:2737
regex_iterator(const regex_iterator &)=default
Copy constructs a regex_iterator.
regex_iterator & operator=(const regex_iterator &)=default
Copy assigns one regex_iterator to another.
regex_iterator()=default
Provides a singular iterator, useful for indicating one-past-the-end of a range.
const value_type & operator*() const noexcept
Dereferences a regex_iterator.
Definition: regex.h:2787
regex_iterator & operator++()
Increments a regex_iterator.
bool operator==(const regex_iterator &) const noexcept
Tests the equivalence of two regex iterators.
regex_token_iterator(_Bi_iter __a, _Bi_iter __b, const regex_type &__re, const int(&__submatches)[_Nm], regex_constants::match_flag_type __m=regex_constants::match_default)
Definition: regex.h:2934
bool operator==(const regex_token_iterator &__rhs) const
Compares a regex_token_iterator to another for equality.
regex_token_iterator & operator++()
Increments a regex_token_iterator.
regex_token_iterator(const regex_token_iterator &__rhs)
Copy constructs a regex_token_iterator.
Definition: regex.h:2966
regex_token_iterator(_Bi_iter __a, _Bi_iter __b, const regex_type &__re, const std::vector< int > &__submatches, regex_constants::match_flag_type __m=regex_constants::match_default)
Definition: regex.h:2899
regex_token_iterator(_Bi_iter __a, _Bi_iter __b, const regex_type &__re, initializer_list< int > __submatches, regex_constants::match_flag_type __m=regex_constants::match_default)
Definition: regex.h:2916
regex_token_iterator operator++(int)
Postincrements a regex_token_iterator.
Definition: regex.h:3024
const value_type * operator->() const
Selects a regex_token_iterator member.
Definition: regex.h:3011
regex_token_iterator()
Default constructs a regex_token_iterator.
Definition: regex.h:2861
regex_token_iterator & operator=(const regex_token_iterator &__rhs)
Assigns a regex_token_iterator to another.
const value_type & operator*() const
Dereferences a regex_token_iterator.
Definition: regex.h:3004
regex_token_iterator(_Bi_iter __a, _Bi_iter __b, const regex_type &__re, int __submatch=0, regex_constants::match_flag_type __m=regex_constants::match_default)
Definition: regex.h:2883
A smart pointer with reference-counted copy semantics.
Struct holding two objects of arbitrary type.
Definition: stl_pair.h:189
Forward iterators support a superset of input iterator operations.
A standard container which offers fixed time access to individual elements in any order.
Definition: stl_vector.h:424
constexpr iterator end() noexcept
Definition: stl_vector.h:888
constexpr iterator begin() noexcept
Definition: stl_vector.h:868
constexpr void assign(size_type __n, const value_type &__val)
Assigns a given value to a vector.
Definition: stl_vector.h:803
constexpr void swap(vector &__x) noexcept
Swaps data with another vector.
Definition: stl_vector.h:1581
constexpr bool empty() const noexcept
Definition: stl_vector.h:1083
constexpr allocator_type get_allocator() const noexcept
Get a copy of the memory allocation object.
Definition: stl_vector.h:308
constexpr size_type size() const noexcept
Definition: stl_vector.h:987
constexpr reference operator[](size_type __n) noexcept
Subscript access to the data contained in the vector.
Definition: stl_vector.h:1121
constexpr size_type max_size() const noexcept
Definition: stl_vector.h:993