libstdc++
regex.h
Go to the documentation of this file.
1// class template regex -*- C++ -*-
2
3// Copyright (C) 2010-2023 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>
832 basic_regex<_Ch, _Tr>::icase;
833
834 template<typename _Ch, typename _Tr>
836 basic_regex<_Ch, _Tr>::nosubs;
837
838 template<typename _Ch, typename _Tr>
840 basic_regex<_Ch, _Tr>::optimize;
841
842 template<typename _Ch, typename _Tr>
844 basic_regex<_Ch, _Tr>::collate;
845
846 template<typename _Ch, typename _Tr>
848 basic_regex<_Ch, _Tr>::ECMAScript;
849
850 template<typename _Ch, typename _Tr>
852 basic_regex<_Ch, _Tr>::basic;
853
854 template<typename _Ch, typename _Tr>
856 basic_regex<_Ch, _Tr>::extended;
857
858 template<typename _Ch, typename _Tr>
860 basic_regex<_Ch, _Tr>::awk;
861
862 template<typename _Ch, typename _Tr>
864 basic_regex<_Ch, _Tr>::grep;
865
866 template<typename _Ch, typename _Tr>
868 basic_regex<_Ch, _Tr>::egrep;
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 // _GLIBCXX_RESOLVE_LIB_DEFECTS
1830 // 2195. Missing constructors for match_results
1831
1832 match_results(const match_results& __m, const _Alloc& __a)
1833 : _Base_type(__m, __a) { }
1834
1835 match_results(match_results&& __m, const _Alloc& __a)
1836 noexcept(noexcept(_Base_type(std::move(__m), __a)))
1837 : _Base_type(std::move(__m), __a) { }
1838
1839 ///@}
1840
1841 // 28.10.2, state:
1842 /**
1843 * @brief Indicates if the %match_results is ready.
1844 * @retval true The object has a fully-established result state.
1845 * @retval false The object is not ready.
1846 */
1847 bool ready() const noexcept { return !_Unchecked::empty(); }
1848
1849 /**
1850 * @name 28.10.2 Size
1851 */
1852 ///@{
1853
1854 /**
1855 * @brief Gets the number of matches and submatches.
1856 *
1857 * The number of matches for a given regular expression will be either 0
1858 * if there was no match or mark_count() + 1 if a match was successful.
1859 * Some matches may be empty.
1860 *
1861 * @returns the number of matches found.
1862 */
1863 size_type
1864 size() const noexcept
1865 { return _Unchecked::empty() ? 0 : _Unchecked::size() - 3; }
1866
1867 size_type
1868 max_size() const noexcept
1869 { return _Unchecked::max_size() - 3; }
1870
1871 /**
1872 * @brief Indicates if the %match_results contains no results.
1873 * @retval true The %match_results object is empty.
1874 * @retval false The %match_results object is not empty.
1875 */
1876 _GLIBCXX_NODISCARD bool
1877 empty() const noexcept
1878 { return _Unchecked::size() <= 3; }
1879
1880 ///@}
1881
1882 /**
1883 * @name 28.10.4 Element Access
1884 */
1885 ///@{
1886
1887 /**
1888 * @brief Gets the length of the indicated submatch.
1889 * @param __sub indicates the submatch.
1890 * @pre ready() == true
1891 *
1892 * This function returns the length of the indicated submatch, or the
1893 * length of the entire match if @p __sub is zero (the default).
1894 */
1895 difference_type
1896 length(size_type __sub = 0) const
1897 { return (*this)[__sub].length(); }
1898
1899 /**
1900 * @brief Gets the offset of the beginning of the indicated submatch.
1901 * @param __sub indicates the submatch.
1902 * @pre ready() == true
1903 *
1904 * This function returns the offset from the beginning of the target
1905 * sequence to the beginning of the submatch, unless the value of @p __sub
1906 * is zero (the default), in which case this function returns the offset
1907 * from the beginning of the target sequence to the beginning of the
1908 * match.
1909 */
1910 difference_type
1911 position(size_type __sub = 0) const
1912 { return std::distance(_M_begin, (*this)[__sub].first); }
1913
1914 /**
1915 * @brief Gets the match or submatch converted to a string type.
1916 * @param __sub indicates the submatch.
1917 * @pre ready() == true
1918 *
1919 * This function gets the submatch (or match, if @p __sub is
1920 * zero) extracted from the target range and converted to the
1921 * associated string type.
1922 */
1923 string_type
1924 str(size_type __sub = 0) const
1925 { return string_type((*this)[__sub]); }
1926
1927 /**
1928 * @brief Gets a %sub_match reference for the match or submatch.
1929 * @param __sub indicates the submatch.
1930 * @pre ready() == true
1931 *
1932 * This function gets a reference to the indicated submatch, or
1933 * the entire match if @p __sub is zero.
1934 *
1935 * If @p __sub >= size() then this function returns a %sub_match with a
1936 * special value indicating no submatch.
1937 */
1938 const_reference
1939 operator[](size_type __sub) const
1940 {
1941 __glibcxx_assert( ready() );
1942 return __sub < size()
1943 ? _Unchecked::operator[](__sub)
1944 : _M_unmatched_sub();
1945 }
1946
1947 /**
1948 * @brief Gets a %sub_match representing the match prefix.
1949 * @pre ready() == true
1950 *
1951 * This function gets a reference to a %sub_match object representing the
1952 * part of the target range between the start of the target range and the
1953 * start of the match.
1954 */
1955 const_reference
1956 prefix() const
1957 {
1958 __glibcxx_assert( ready() );
1959 return !empty() ? _M_prefix() : _M_unmatched_sub();
1960 }
1961
1962 /**
1963 * @brief Gets a %sub_match representing the match suffix.
1964 * @pre ready() == true
1965 *
1966 * This function gets a reference to a %sub_match object representing the
1967 * part of the target range between the end of the match and the end of
1968 * the target range.
1969 */
1970 const_reference
1971 suffix() const
1972 {
1973 __glibcxx_assert( ready() );
1974 return !empty() ? _M_suffix() : _M_unmatched_sub();
1975 }
1976
1977 /**
1978 * @brief Gets an iterator to the start of the %sub_match collection.
1979 */
1980 const_iterator
1981 begin() const noexcept
1982 { return _Base_type::begin(); }
1983
1984 /**
1985 * @brief Gets an iterator to the start of the %sub_match collection.
1986 */
1987 const_iterator
1988 cbegin() const noexcept
1989 { return this->begin(); }
1990
1991 /**
1992 * @brief Gets an iterator to one-past-the-end of the collection.
1993 */
1994 const_iterator
1995 end() const noexcept
1996 { return _Base_type::end() - (_Base_type::empty() ? 0 : 3); }
1997
1998 /**
1999 * @brief Gets an iterator to one-past-the-end of the collection.
2000 */
2001 const_iterator
2002 cend() const noexcept
2003 { return this->end(); }
2004
2005 ///@}
2006
2007 /**
2008 * @name 28.10.5 Formatting
2009 *
2010 * These functions perform formatted substitution of the matched
2011 * character sequences into their target. The format specifiers and
2012 * escape sequences accepted by these functions are determined by
2013 * their @p flags parameter as documented above.
2014 */
2015 ///@{
2016
2017 /**
2018 * @pre ready() == true
2019 */
2020 template<typename _Out_iter>
2021 _Out_iter
2022 format(_Out_iter __out, const char_type* __fmt_first,
2023 const char_type* __fmt_last,
2025
2026 /**
2027 * @pre ready() == true
2028 */
2029 template<typename _Out_iter, typename _St, typename _Sa>
2030 _Out_iter
2031 format(_Out_iter __out, const basic_string<char_type, _St, _Sa>& __fmt,
2033 {
2034 return format(__out, __fmt.data(), __fmt.data() + __fmt.size(),
2035 __flags);
2036 }
2037
2038 /**
2039 * @pre ready() == true
2040 */
2041 template<typename _St, typename _Sa>
2045 {
2047 format(std::back_inserter(__result), __fmt, __flags);
2048 return __result;
2049 }
2050
2051 /**
2052 * @pre ready() == true
2053 */
2054 string_type
2055 format(const char_type* __fmt,
2057 {
2058 string_type __result;
2059 format(std::back_inserter(__result),
2060 __fmt,
2061 __fmt + char_traits<char_type>::length(__fmt),
2062 __flags);
2063 return __result;
2064 }
2065
2066 ///@}
2067
2068 /**
2069 * @name 28.10.6 Allocator
2070 */
2071 ///@{
2072
2073 /**
2074 * @brief Gets a copy of the allocator.
2075 */
2076 allocator_type
2077 get_allocator() const noexcept
2078 { return _Base_type::get_allocator(); }
2079
2080 ///@}
2081
2082 /**
2083 * @name 28.10.7 Swap
2084 */
2085 ///@{
2086
2087 /**
2088 * @brief Swaps the contents of two match_results.
2089 */
2090 void
2091 swap(match_results& __that) noexcept
2092 {
2093 using std::swap;
2094 _Base_type::swap(__that);
2095 swap(_M_begin, __that._M_begin);
2096 }
2097 ///@}
2098
2099 private:
2100 template<typename, typename, typename>
2101 friend class regex_iterator;
2102
2103 /// @cond undocumented
2104
2105 template<typename, typename, typename, bool>
2106 friend class __detail::_Executor;
2107
2108 template<typename _Bp, typename _Ap, typename _Cp, typename _Rp>
2109 friend bool
2110 __detail::__regex_algo_impl(_Bp, _Bp, match_results<_Bp, _Ap>&,
2111 const basic_regex<_Cp, _Rp>&,
2113 __detail::_RegexExecutorPolicy, bool);
2114
2115 // Reset contents to __size unmatched sub_match objects
2116 // (plus additional objects for prefix, suffix and unmatched sub).
2117 void
2118 _M_resize(unsigned int __size)
2119 { _Unchecked::assign(__size + 3, sub_match<_Bi_iter>{}); }
2120
2121 // Set state to a failed match for the given past-the-end iterator.
2122 void
2123 _M_establish_failed_match(_Bi_iter __end)
2124 {
2125 sub_match<_Bi_iter> __sm;
2126 __sm.first = __sm.second = __end;
2127 _Unchecked::assign(3, __sm);
2128 }
2129
2130 const_reference
2131 _M_unmatched_sub() const
2132 { return _Unchecked::operator[](_Unchecked::size() - 3); }
2133
2134 sub_match<_Bi_iter>&
2135 _M_unmatched_sub()
2136 { return _Unchecked::operator[](_Unchecked::size() - 3); }
2137
2138 const_reference
2139 _M_prefix() const
2140 { return _Unchecked::operator[](_Unchecked::size() - 2); }
2141
2142 sub_match<_Bi_iter>&
2143 _M_prefix()
2144 { return _Unchecked::operator[](_Unchecked::size() - 2); }
2145
2146 const_reference
2147 _M_suffix() const
2148 { return _Unchecked::operator[](_Unchecked::size() - 1); }
2149
2150 sub_match<_Bi_iter>&
2151 _M_suffix()
2152 { return _Unchecked::operator[](_Unchecked::size() - 1); }
2153
2154 _Bi_iter _M_begin {};
2155 /// @endcond
2156 };
2157
2158 typedef match_results<const char*> cmatch;
2159 typedef match_results<string::const_iterator> smatch;
2160#ifdef _GLIBCXX_USE_WCHAR_T
2161 typedef match_results<const wchar_t*> wcmatch;
2162 typedef match_results<wstring::const_iterator> wsmatch;
2163#endif
2164
2165 // match_results comparisons
2166
2167 /**
2168 * @brief Compares two match_results for equality.
2169 * @returns true if the two objects refer to the same match,
2170 * false otherwise.
2171 *
2172 * @relates match_results
2173 */
2174 template<typename _Bi_iter, typename _Alloc>
2175 inline bool
2178 {
2179 if (__m1.ready() != __m2.ready())
2180 return false;
2181 if (!__m1.ready()) // both are not ready
2182 return true;
2183 if (__m1.empty() != __m2.empty())
2184 return false;
2185 if (__m1.empty()) // both are empty
2186 return true;
2187 return __m1.prefix() == __m2.prefix()
2188 && __m1.size() == __m2.size()
2189 && std::equal(__m1.begin(), __m1.end(), __m2.begin())
2190 && __m1.suffix() == __m2.suffix();
2191 }
2192
2193#if ! __cpp_lib_three_way_comparison
2194 /**
2195 * @brief Compares two match_results for inequality.
2196 * @returns true if the two objects do not refer to the same match,
2197 * false otherwise.
2198 *
2199 * @relates match_results
2200 */
2201 template<typename _Bi_iter, class _Alloc>
2202 inline bool
2205 { return !(__m1 == __m2); }
2206#endif
2207
2208 // [7.10.6] match_results swap
2209 /**
2210 * @brief Swaps two match results.
2211 * @param __lhs A match result.
2212 * @param __rhs A match result.
2213 *
2214 * The contents of the two match_results objects are swapped.
2215 *
2216 * @relates match_results
2217 */
2218 template<typename _Bi_iter, typename _Alloc>
2219 inline void
2221 match_results<_Bi_iter, _Alloc>& __rhs) noexcept
2222 { __lhs.swap(__rhs); }
2223
2224_GLIBCXX_END_NAMESPACE_CXX11
2225
2226 // [28.11.2] Function template regex_match
2227 /**
2228 * @name Matching, Searching, and Replacing
2229 *
2230 * @{
2231 */
2232
2233 /**
2234 * @brief Determines if there is a match between the regular expression @p e
2235 * and all of the character sequence [first, last).
2236 *
2237 * @param __s Start of the character sequence to match.
2238 * @param __e One-past-the-end of the character sequence to match.
2239 * @param __m The match results.
2240 * @param __re The regular expression.
2241 * @param __flags Controls how the regular expression is matched.
2242 *
2243 * @retval true A match exists.
2244 * @retval false Otherwise.
2245 *
2246 * @throws an exception of type regex_error.
2247 */
2248 template<typename _Bi_iter, typename _Alloc,
2249 typename _Ch_type, typename _Rx_traits>
2250 inline bool
2251 regex_match(_Bi_iter __s,
2252 _Bi_iter __e,
2257 {
2258 return __detail::__regex_algo_impl(__s, __e, __m, __re, __flags,
2259 __detail::_RegexExecutorPolicy::_S_auto, true);
2260 }
2261
2262 /**
2263 * @brief Indicates if there is a match between the regular expression @p e
2264 * and all of the character sequence [first, last).
2265 *
2266 * @param __first Beginning of the character sequence to match.
2267 * @param __last One-past-the-end of the character sequence to match.
2268 * @param __re The regular expression.
2269 * @param __flags Controls how the regular expression is matched.
2270 *
2271 * @retval true A match exists.
2272 * @retval false Otherwise.
2273 *
2274 * @throws an exception of type regex_error.
2275 */
2276 template<typename _Bi_iter, typename _Ch_type, typename _Rx_traits>
2277 inline bool
2278 regex_match(_Bi_iter __first, _Bi_iter __last,
2282 {
2284 return regex_match(__first, __last, __what, __re, __flags);
2285 }
2286
2287 /**
2288 * @brief Determines if there is a match between the regular expression @p e
2289 * and a C-style null-terminated string.
2290 *
2291 * @param __s The C-style null-terminated string to match.
2292 * @param __m The match results.
2293 * @param __re The regular expression.
2294 * @param __f Controls how the regular expression is matched.
2295 *
2296 * @retval true A match exists.
2297 * @retval false Otherwise.
2298 *
2299 * @throws an exception of type regex_error.
2300 */
2301 template<typename _Ch_type, typename _Alloc, typename _Rx_traits>
2302 inline bool
2303 regex_match(const _Ch_type* __s,
2308 { return regex_match(__s, __s + _Rx_traits::length(__s), __m, __re, __f); }
2309
2310 /**
2311 * @brief Determines if there is a match between the regular expression @p e
2312 * and a string.
2313 *
2314 * @param __s The string to match.
2315 * @param __m The match results.
2316 * @param __re The regular expression.
2317 * @param __flags Controls how the regular expression is matched.
2318 *
2319 * @retval true A match exists.
2320 * @retval false Otherwise.
2321 *
2322 * @throws an exception of type regex_error.
2323 */
2324 template<typename _Ch_traits, typename _Ch_alloc,
2325 typename _Alloc, typename _Ch_type, typename _Rx_traits>
2326 inline bool
2328 match_results<typename basic_string<_Ch_type,
2329 _Ch_traits, _Ch_alloc>::const_iterator, _Alloc>& __m,
2333 { return regex_match(__s.begin(), __s.end(), __m, __re, __flags); }
2334
2335 // _GLIBCXX_RESOLVE_LIB_DEFECTS
2336 // 2329. regex_match() with match_results should forbid temporary strings
2337 /// Prevent unsafe attempts to get match_results from a temporary string.
2338 template<typename _Ch_traits, typename _Ch_alloc,
2339 typename _Alloc, typename _Ch_type, typename _Rx_traits>
2340 bool
2342 match_results<typename basic_string<_Ch_type,
2343 _Ch_traits, _Ch_alloc>::const_iterator, _Alloc>&,
2347
2348 /**
2349 * @brief Indicates if there is a match between the regular expression @p e
2350 * and a C-style null-terminated string.
2351 *
2352 * @param __s The C-style null-terminated string to match.
2353 * @param __re The regular expression.
2354 * @param __f Controls how the regular expression is matched.
2355 *
2356 * @retval true A match exists.
2357 * @retval false Otherwise.
2358 *
2359 * @throws an exception of type regex_error.
2360 */
2361 template<typename _Ch_type, class _Rx_traits>
2362 inline bool
2363 regex_match(const _Ch_type* __s,
2367 { return regex_match(__s, __s + _Rx_traits::length(__s), __re, __f); }
2368
2369 /**
2370 * @brief Indicates if there is a match between the regular expression @p e
2371 * and a string.
2372 *
2373 * @param __s [IN] The string to match.
2374 * @param __re [IN] The regular expression.
2375 * @param __flags [IN] Controls how the regular expression is matched.
2376 *
2377 * @retval true A match exists.
2378 * @retval false Otherwise.
2379 *
2380 * @throws an exception of type regex_error.
2381 */
2382 template<typename _Ch_traits, typename _Str_allocator,
2383 typename _Ch_type, typename _Rx_traits>
2384 inline bool
2389 { return regex_match(__s.begin(), __s.end(), __re, __flags); }
2390
2391 // [7.11.3] Function template regex_search
2392 /**
2393 * Searches for a regular expression within a range.
2394 * @param __s [IN] The start of the string to search.
2395 * @param __e [IN] One-past-the-end of the string to search.
2396 * @param __m [OUT] The match results.
2397 * @param __re [IN] The regular expression to search for.
2398 * @param __flags [IN] Search policy flags.
2399 * @retval true A match was found within the string.
2400 * @retval false No match was found within the string, the content of %m is
2401 * undefined.
2402 *
2403 * @throws an exception of type regex_error.
2404 */
2405 template<typename _Bi_iter, typename _Alloc,
2406 typename _Ch_type, typename _Rx_traits>
2407 inline bool
2408 regex_search(_Bi_iter __s, _Bi_iter __e,
2413 {
2414 return __detail::__regex_algo_impl(__s, __e, __m, __re, __flags,
2415 __detail::_RegexExecutorPolicy::_S_auto, false);
2416 }
2417
2418 /**
2419 * Searches for a regular expression within a range.
2420 * @param __first [IN] The start of the string to search.
2421 * @param __last [IN] One-past-the-end of the string to search.
2422 * @param __re [IN] The regular expression to search for.
2423 * @param __flags [IN] Search policy flags.
2424 * @retval true A match was found within the string.
2425 * @retval false No match was found within the string.
2426 *
2427 * @throws an exception of type regex_error.
2428 */
2429 template<typename _Bi_iter, typename _Ch_type, typename _Rx_traits>
2430 inline bool
2431 regex_search(_Bi_iter __first, _Bi_iter __last,
2435 {
2437 return regex_search(__first, __last, __what, __re, __flags);
2438 }
2439
2440 /**
2441 * @brief Searches for a regular expression within a C-string.
2442 * @param __s [IN] A C-string to search for the regex.
2443 * @param __m [OUT] The set of regex matches.
2444 * @param __e [IN] The regex to search for in @p s.
2445 * @param __f [IN] The search flags.
2446 * @retval true A match was found within the string.
2447 * @retval false No match was found within the string, the content of %m is
2448 * undefined.
2449 *
2450 * @throws an exception of type regex_error.
2451 */
2452 template<typename _Ch_type, class _Alloc, class _Rx_traits>
2453 inline bool
2454 regex_search(const _Ch_type* __s,
2459 { return regex_search(__s, __s + _Rx_traits::length(__s), __m, __e, __f); }
2460
2461 /**
2462 * @brief Searches for a regular expression within a C-string.
2463 * @param __s [IN] The C-string to search.
2464 * @param __e [IN] The regular expression to search for.
2465 * @param __f [IN] Search policy flags.
2466 * @retval true A match was found within the string.
2467 * @retval false No match was found within the string.
2468 *
2469 * @throws an exception of type regex_error.
2470 */
2471 template<typename _Ch_type, typename _Rx_traits>
2472 inline bool
2473 regex_search(const _Ch_type* __s,
2477 { return regex_search(__s, __s + _Rx_traits::length(__s), __e, __f); }
2478
2479 /**
2480 * @brief Searches for a regular expression within a string.
2481 * @param __s [IN] The string to search.
2482 * @param __e [IN] The regular expression to search for.
2483 * @param __flags [IN] Search policy flags.
2484 * @retval true A match was found within the string.
2485 * @retval false No match was found within the string.
2486 *
2487 * @throws an exception of type regex_error.
2488 */
2489 template<typename _Ch_traits, typename _String_allocator,
2490 typename _Ch_type, typename _Rx_traits>
2491 inline bool
2492 regex_search(const basic_string<_Ch_type, _Ch_traits,
2493 _String_allocator>& __s,
2497 { return regex_search(__s.begin(), __s.end(), __e, __flags); }
2498
2499 /**
2500 * @brief Searches for a regular expression within a string.
2501 * @param __s [IN] A C++ string to search for the regex.
2502 * @param __m [OUT] The set of regex matches.
2503 * @param __e [IN] The regex to search for in @p s.
2504 * @param __f [IN] The search flags.
2505 * @retval true A match was found within the string.
2506 * @retval false No match was found within the string, the content of %m is
2507 * undefined.
2508 *
2509 * @throws an exception of type regex_error.
2510 */
2511 template<typename _Ch_traits, typename _Ch_alloc,
2512 typename _Alloc, typename _Ch_type,
2513 typename _Rx_traits>
2514 inline bool
2516 match_results<typename basic_string<_Ch_type,
2517 _Ch_traits, _Ch_alloc>::const_iterator, _Alloc>& __m,
2521 { return regex_search(__s.begin(), __s.end(), __m, __e, __f); }
2522
2523 // _GLIBCXX_RESOLVE_LIB_DEFECTS
2524 // 2329. regex_search() with match_results should forbid temporary strings
2525 /// Prevent unsafe attempts to get match_results from a temporary string.
2526 template<typename _Ch_traits, typename _Ch_alloc,
2527 typename _Alloc, typename _Ch_type,
2528 typename _Rx_traits>
2529 bool
2531 match_results<typename basic_string<_Ch_type,
2532 _Ch_traits, _Ch_alloc>::const_iterator, _Alloc>&,
2536
2537 // std [28.11.4] Function template regex_replace
2538
2539 /// @cond undocumented
2540 template<typename _Out_iter, typename _Bi_iter,
2541 typename _Rx_traits, typename _Ch_type>
2542 _Out_iter
2543 __regex_replace(_Out_iter __out, _Bi_iter __first, _Bi_iter __last,
2545 const _Ch_type* __fmt, size_t __len,
2547 /// @endcond
2548
2549 /**
2550 * @brief Search for a regular expression within a range for multiple times,
2551 and replace the matched parts through filling a format string.
2552 * @param __out [OUT] The output iterator.
2553 * @param __first [IN] The start of the string to search.
2554 * @param __last [IN] One-past-the-end of the string to search.
2555 * @param __e [IN] The regular expression to search for.
2556 * @param __fmt [IN] The format string.
2557 * @param __flags [IN] Search and replace policy flags.
2558 *
2559 * @returns __out
2560 * @throws an exception of type regex_error.
2561 */
2562 template<typename _Out_iter, typename _Bi_iter,
2563 typename _Rx_traits, typename _Ch_type,
2564 typename _St, typename _Sa>
2565 inline _Out_iter
2566 regex_replace(_Out_iter __out, _Bi_iter __first, _Bi_iter __last,
2571 {
2572 return std::__regex_replace(__out, __first, __last, __e, __fmt.c_str(),
2573 __fmt.length(), __flags);
2574 }
2575
2576 /**
2577 * @brief Search for a regular expression within a range for multiple times,
2578 and replace the matched parts through filling a format C-string.
2579 * @param __out [OUT] The output iterator.
2580 * @param __first [IN] The start of the string to search.
2581 * @param __last [IN] One-past-the-end of the string to search.
2582 * @param __e [IN] The regular expression to search for.
2583 * @param __fmt [IN] The format C-string.
2584 * @param __flags [IN] Search and replace policy flags.
2585 *
2586 * @returns __out
2587 * @throws an exception of type regex_error.
2588 */
2589 template<typename _Out_iter, typename _Bi_iter,
2590 typename _Rx_traits, typename _Ch_type>
2591 _Out_iter
2592 regex_replace(_Out_iter __out, _Bi_iter __first, _Bi_iter __last,
2594 const _Ch_type* __fmt,
2597 {
2598 return std::__regex_replace(__out, __first, __last, __e, __fmt,
2600 __flags);
2601 }
2602
2603
2604 /**
2605 * @brief Search for a regular expression within a string for multiple times,
2606 and replace the matched parts through filling a format string.
2607 * @param __s [IN] The string to search and replace.
2608 * @param __e [IN] The regular expression to search for.
2609 * @param __fmt [IN] The format string.
2610 * @param __flags [IN] Search and replace policy flags.
2611 *
2612 * @returns The string after replacing.
2613 * @throws an exception of type regex_error.
2614 */
2615 template<typename _Rx_traits, typename _Ch_type,
2616 typename _St, typename _Sa, typename _Fst, typename _Fsa>
2617 inline basic_string<_Ch_type, _St, _Sa>
2623 {
2626 __s.begin(), __s.end(), __e, __fmt, __flags);
2627 return __result;
2628 }
2629
2630 /**
2631 * @brief Search for a regular expression within a string for multiple times,
2632 and replace the matched parts through filling a format C-string.
2633 * @param __s [IN] The string to search and replace.
2634 * @param __e [IN] The regular expression to search for.
2635 * @param __fmt [IN] The format C-string.
2636 * @param __flags [IN] Search and replace policy flags.
2637 *
2638 * @returns The string after replacing.
2639 * @throws an exception of type regex_error.
2640 */
2641 template<typename _Rx_traits, typename _Ch_type,
2642 typename _St, typename _Sa>
2643 inline basic_string<_Ch_type, _St, _Sa>
2646 const _Ch_type* __fmt,
2649 {
2652 __s.begin(), __s.end(), __e, __fmt, __flags);
2653 return __result;
2654 }
2655
2656 /**
2657 * @brief Search for a regular expression within a C-string for multiple
2658 times, and replace the matched parts through filling a format string.
2659 * @param __s [IN] The C-string to search and replace.
2660 * @param __e [IN] The regular expression to search for.
2661 * @param __fmt [IN] The format string.
2662 * @param __flags [IN] Search and replace policy flags.
2663 *
2664 * @returns The string after replacing.
2665 * @throws an exception of type regex_error.
2666 */
2667 template<typename _Rx_traits, typename _Ch_type,
2668 typename _St, typename _Sa>
2669 inline basic_string<_Ch_type>
2670 regex_replace(const _Ch_type* __s,
2675 {
2676 basic_string<_Ch_type> __result;
2677 regex_replace(std::back_inserter(__result), __s,
2679 __e, __fmt, __flags);
2680 return __result;
2681 }
2682
2683 /**
2684 * @brief Search for a regular expression within a C-string for multiple
2685 times, and replace the matched parts through filling a format C-string.
2686 * @param __s [IN] The C-string to search and replace.
2687 * @param __e [IN] The regular expression to search for.
2688 * @param __fmt [IN] The format C-string.
2689 * @param __flags [IN] Search and replace policy flags.
2690 *
2691 * @returns The string after replacing.
2692 * @throws an exception of type regex_error.
2693 */
2694 template<typename _Rx_traits, typename _Ch_type>
2695 inline basic_string<_Ch_type>
2696 regex_replace(const _Ch_type* __s,
2698 const _Ch_type* __fmt,
2701 {
2702 basic_string<_Ch_type> __result;
2703 regex_replace(std::back_inserter(__result), __s,
2705 __e, __fmt, __flags);
2706 return __result;
2707 }
2708
2709 /// @}
2710
2711_GLIBCXX_BEGIN_NAMESPACE_CXX11
2712
2713 // std [28.12] Class template regex_iterator
2714 /**
2715 * An iterator adaptor that will provide repeated calls of regex_search over
2716 * a range until no more matches remain.
2717 *
2718 * @headerfile regex
2719 * @since C++11
2720 */
2721 template<typename _Bi_iter,
2722 typename _Ch_type = typename iterator_traits<_Bi_iter>::value_type,
2723 typename _Rx_traits = regex_traits<_Ch_type> >
2725 {
2726 public:
2728 typedef match_results<_Bi_iter> value_type;
2729 typedef std::ptrdiff_t difference_type;
2730 typedef const value_type* pointer;
2731 typedef const value_type& reference;
2733
2734 /**
2735 * @brief Provides a singular iterator, useful for indicating
2736 * one-past-the-end of a range.
2737 */
2738 regex_iterator() = default;
2739
2740 /**
2741 * Constructs a %regex_iterator...
2742 * @param __a [IN] The start of a text range to search.
2743 * @param __b [IN] One-past-the-end of the text range to search.
2744 * @param __re [IN] The regular expression to match.
2745 * @param __m [IN] Policy flags for match rules.
2746 */
2747 regex_iterator(_Bi_iter __a, _Bi_iter __b, const regex_type& __re,
2750 : _M_begin(__a), _M_end(__b), _M_pregex(&__re), _M_flags(__m), _M_match()
2751 {
2752 if (!regex_search(_M_begin, _M_end, _M_match, *_M_pregex, _M_flags))
2753 *this = regex_iterator();
2754 }
2755
2756 // _GLIBCXX_RESOLVE_LIB_DEFECTS
2757 // 2332. regex_iterator should forbid temporary regexes
2758 regex_iterator(_Bi_iter, _Bi_iter, const regex_type&&,
2761
2762 /// Copy constructs a %regex_iterator.
2764
2765 /// Copy assigns one %regex_iterator to another.
2767 operator=(const regex_iterator&) = default;
2768
2769 ~regex_iterator() = default;
2770
2771 /**
2772 * @brief Tests the equivalence of two regex iterators.
2773 */
2774 bool
2775 operator==(const regex_iterator&) const noexcept;
2776
2777#if __cplusplus >= 202002L
2778 // _GLIBCXX_RESOLVE_LIB_DEFECTS
2779 // 3719. Directory iterators should be usable with default sentinel
2780 bool operator==(default_sentinel_t) const noexcept
2781 { return _M_pregex == nullptr; }
2782#endif
2783
2784#if __cpp_impl_three_way_comparison < 201907L
2785 /**
2786 * @brief Tests the inequivalence of two regex iterators.
2787 */
2788 bool
2789 operator!=(const regex_iterator& __rhs) const noexcept
2790 { return !(*this == __rhs); }
2791#endif
2792
2793 /**
2794 * @brief Dereferences a %regex_iterator.
2795 */
2796 const value_type&
2797 operator*() const noexcept
2798 { return _M_match; }
2799
2800 /**
2801 * @brief Selects a %regex_iterator member.
2802 */
2803 const value_type*
2804 operator->() const noexcept
2805 { return &_M_match; }
2806
2807 /**
2808 * @brief Increments a %regex_iterator.
2809 */
2812
2813 /**
2814 * @brief Postincrements a %regex_iterator.
2815 */
2818 {
2819 auto __tmp = *this;
2820 ++(*this);
2821 return __tmp;
2822 }
2823
2824 private:
2825 _Bi_iter _M_begin {};
2826 _Bi_iter _M_end {};
2827 const regex_type* _M_pregex = nullptr;
2829 match_results<_Bi_iter> _M_match;
2830 };
2831
2832 typedef regex_iterator<const char*> cregex_iterator;
2833 typedef regex_iterator<string::const_iterator> sregex_iterator;
2834#ifdef _GLIBCXX_USE_WCHAR_T
2835 typedef regex_iterator<const wchar_t*> wcregex_iterator;
2836 typedef regex_iterator<wstring::const_iterator> wsregex_iterator;
2837#endif
2838
2839 // [7.12.2] Class template regex_token_iterator
2840 /**
2841 * Iterates over submatches in a range (or @a splits a text string).
2842 *
2843 * The purpose of this iterator is to enumerate all, or all specified,
2844 * matches of a regular expression within a text range. The dereferenced
2845 * value of an iterator of this class is a std::sub_match object.
2846 *
2847 * @headerfile regex
2848 * @since C++11
2849 */
2850 template<typename _Bi_iter,
2851 typename _Ch_type = typename iterator_traits<_Bi_iter>::value_type,
2852 typename _Rx_traits = regex_traits<_Ch_type> >
2854 {
2855 public:
2858 typedef std::ptrdiff_t difference_type;
2859 typedef const value_type* pointer;
2860 typedef const value_type& reference;
2862
2863 public:
2864 /**
2865 * @brief Default constructs a %regex_token_iterator.
2866 *
2867 * A default-constructed %regex_token_iterator is a singular iterator
2868 * that will compare equal to the one-past-the-end value for any
2869 * iterator of the same type.
2870 */
2872 : _M_position(), _M_subs(), _M_suffix(), _M_n(0), _M_result(nullptr),
2873 _M_has_m1(false)
2874 { }
2875
2876 /**
2877 * Constructs a %regex_token_iterator...
2878 * @param __a [IN] The start of the text to search.
2879 * @param __b [IN] One-past-the-end of the text to search.
2880 * @param __re [IN] The regular expression to search for.
2881 * @param __submatch [IN] Which submatch to return. There are some
2882 * special values for this parameter:
2883 * - -1 each enumerated subexpression does NOT
2884 * match the regular expression (aka field
2885 * splitting)
2886 * - 0 the entire string matching the
2887 * subexpression is returned for each match
2888 * within the text.
2889 * - >0 enumerates only the indicated
2890 * subexpression from a match within the text.
2891 * @param __m [IN] Policy flags for match rules.
2892 */
2893 regex_token_iterator(_Bi_iter __a, _Bi_iter __b, const regex_type& __re,
2894 int __submatch = 0,
2897 : _M_position(__a, __b, __re, __m), _M_subs(1, __submatch), _M_n(0)
2898 { _M_init(__a, __b); }
2899
2900 /**
2901 * Constructs a %regex_token_iterator...
2902 * @param __a [IN] The start of the text to search.
2903 * @param __b [IN] One-past-the-end of the text to search.
2904 * @param __re [IN] The regular expression to search for.
2905 * @param __submatches [IN] A list of subexpressions to return for each
2906 * regular expression match within the text.
2907 * @param __m [IN] Policy flags for match rules.
2908 */
2909 regex_token_iterator(_Bi_iter __a, _Bi_iter __b,
2910 const regex_type& __re,
2911 const std::vector<int>& __submatches,
2914 : _M_position(__a, __b, __re, __m), _M_subs(__submatches), _M_n(0)
2915 { _M_init(__a, __b); }
2916
2917 /**
2918 * Constructs a %regex_token_iterator...
2919 * @param __a [IN] The start of the text to search.
2920 * @param __b [IN] One-past-the-end of the text to search.
2921 * @param __re [IN] The regular expression to search for.
2922 * @param __submatches [IN] A list of subexpressions to return for each
2923 * regular expression match within the text.
2924 * @param __m [IN] Policy flags for match rules.
2925 */
2926 regex_token_iterator(_Bi_iter __a, _Bi_iter __b,
2927 const regex_type& __re,
2928 initializer_list<int> __submatches,
2931 : _M_position(__a, __b, __re, __m), _M_subs(__submatches), _M_n(0)
2932 { _M_init(__a, __b); }
2933
2934 /**
2935 * Constructs a %regex_token_iterator...
2936 * @param __a [IN] The start of the text to search.
2937 * @param __b [IN] One-past-the-end of the text to search.
2938 * @param __re [IN] The regular expression to search for.
2939 * @param __submatches [IN] A list of subexpressions to return for each
2940 * regular expression match within the text.
2941 * @param __m [IN] Policy flags for match rules.
2942 */
2943 template<std::size_t _Nm>
2944 regex_token_iterator(_Bi_iter __a, _Bi_iter __b,
2945 const regex_type& __re,
2946 const int (&__submatches)[_Nm],
2949 : _M_position(__a, __b, __re, __m),
2950 _M_subs(__submatches, __submatches + _Nm), _M_n(0)
2951 { _M_init(__a, __b); }
2952
2953 // _GLIBCXX_RESOLVE_LIB_DEFECTS
2954 // 2332. regex_token_iterator should forbid temporary regexes
2955 regex_token_iterator(_Bi_iter, _Bi_iter, const regex_type&&, int = 0,
2958 regex_token_iterator(_Bi_iter, _Bi_iter, const regex_type&&,
2959 const std::vector<int>&,
2962 regex_token_iterator(_Bi_iter, _Bi_iter, const regex_type&&,
2966 template <std::size_t _Nm>
2967 regex_token_iterator(_Bi_iter, _Bi_iter, const regex_type&&,
2968 const int (&)[_Nm],
2971
2972 /**
2973 * @brief Copy constructs a %regex_token_iterator.
2974 * @param __rhs [IN] A %regex_token_iterator to copy.
2975 */
2977 : _M_position(__rhs._M_position), _M_subs(__rhs._M_subs),
2978 _M_suffix(__rhs._M_suffix), _M_n(__rhs._M_n), _M_has_m1(__rhs._M_has_m1)
2979 { _M_normalize_result(); }
2980
2981 /**
2982 * @brief Assigns a %regex_token_iterator to another.
2983 * @param __rhs [IN] A %regex_token_iterator to copy.
2984 */
2987
2988 /**
2989 * @brief Compares a %regex_token_iterator to another for equality.
2990 */
2991 bool
2993
2994#if __cplusplus >= 202002L
2995 // _GLIBCXX_RESOLVE_LIB_DEFECTS
2996 // 3719. Directory iterators should be usable with default sentinel
2997 bool operator==(default_sentinel_t) const noexcept
2998 { return _M_end_of_seq(); }
2999#endif
3000
3001#if __cpp_impl_three_way_comparison < 201907L
3002 /**
3003 * @brief Compares a %regex_token_iterator to another for inequality.
3004 */
3005 bool
3006 operator!=(const regex_token_iterator& __rhs) const
3007 { return !(*this == __rhs); }
3008#endif
3009
3010 /**
3011 * @brief Dereferences a %regex_token_iterator.
3012 */
3013 const value_type&
3015 { return *_M_result; }
3016
3017 /**
3018 * @brief Selects a %regex_token_iterator member.
3019 */
3020 const value_type*
3022 { return _M_result; }
3023
3024 /**
3025 * @brief Increments a %regex_token_iterator.
3026 */
3029
3030 /**
3031 * @brief Postincrements a %regex_token_iterator.
3032 */
3035 {
3036 auto __tmp = *this;
3037 ++(*this);
3038 return __tmp;
3039 }
3040
3041 private:
3043
3044 void
3045 _M_init(_Bi_iter __a, _Bi_iter __b);
3046
3047 const value_type&
3048 _M_current_match() const
3049 {
3050 if (_M_subs[_M_n] == -1)
3051 return (*_M_position).prefix();
3052 else
3053 return (*_M_position)[_M_subs[_M_n]];
3054 }
3055
3056 constexpr bool
3057 _M_end_of_seq() const noexcept
3058 { return _M_result == nullptr; }
3059
3060 // [28.12.2.2.4]
3061 void
3062 _M_normalize_result()
3063 {
3064 if (_M_position != _Position())
3065 _M_result = &_M_current_match();
3066 else if (_M_has_m1)
3067 _M_result = &_M_suffix;
3068 else
3069 _M_result = nullptr;
3070 }
3071
3072 _Position _M_position;
3073 std::vector<int> _M_subs;
3074 value_type _M_suffix;
3075 std::size_t _M_n;
3076 const value_type* _M_result;
3077
3078 // Show whether _M_subs contains -1
3079 bool _M_has_m1;
3080 };
3081
3082 /** @brief Token iterator for C-style NULL-terminated strings. */
3084
3085 /** @brief Token iterator for standard strings. */
3087
3088#ifdef _GLIBCXX_USE_WCHAR_T
3089 /** @brief Token iterator for C-style NULL-terminated wide strings. */
3091
3092 /** @brief Token iterator for standard wide-character strings. */
3094#endif
3095
3096 ///@} // group regex
3097
3098_GLIBCXX_END_NAMESPACE_CXX11
3099_GLIBCXX_END_NAMESPACE_VERSION
3100} // namespace
3101
3102#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:233
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:3083
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:3093
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:3090
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:2203
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:2566
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:3086
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:2251
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:2176
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:2408
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:2220
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:1573
std::basic_ostream< _CharT, _Traits > & operator<<(std::basic_ostream< _CharT, _Traits > &__os, const bitset< _Nb > &__x)
Global I/O operators for bitsets.
Definition: bitset:1683
constexpr bitset< _Nb > operator|(const bitset< _Nb > &__x, const bitset< _Nb > &__y) noexcept
Global bitwise operations on bitsets.
Definition: bitset:1563
constexpr bitset< _Nb > operator&(const bitset< _Nb > &__x, const bitset< _Nb > &__y) noexcept
Global bitwise operations on bitsets.
Definition: bitset:1553
GNU extensions for public use.
__numeric_traits_integer< _Tp > __int_traits
Convenience alias for __numeric_traits<integer-type>.
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:1399
typename _Size< _Alloc, difference_type >::type size_type
The allocator's size type.
Basis for explicit traits specializations.
Definition: char_traits.h:342
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:2225
size_type length() const noexcept
Returns the number of characters in the string, not including any null-termination.
Definition: cow_string.h:926
size_type size() const noexcept
Returns the number of characters in the string, not including any null-termination.
Definition: cow_string.h:914
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:2213
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:2077
void swap(match_results &__that) noexcept
Swaps the contents of two match_results.
Definition: regex.h:2091
difference_type position(size_type __sub=0) const
Gets the offset of the beginning of the indicated submatch.
Definition: regex.h:1911
size_type size() const noexcept
Gets the number of matches and submatches.
Definition: regex.h:1864
_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:1896
const_reference prefix() const
Gets a sub_match representing the match prefix.
Definition: regex.h:1956
match_results(match_results &&__m, const _Alloc &__a) noexcept(noexcept(_Base_type(std::move(__m), __a)))
Constructs a default match_results container.
Definition: regex.h:1835
size_type max_size() const noexcept
Gets the number of matches and submatches.
Definition: regex.h:1868
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:2043
const_reference operator[](size_type __sub) const
Gets a sub_match reference for the match or submatch.
Definition: regex.h:1939
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:2031
const_iterator cbegin() const noexcept
Gets an iterator to the start of the sub_match collection.
Definition: regex.h:1988
string_type str(size_type __sub=0) const
Gets the match or submatch converted to a string type.
Definition: regex.h:1924
const_iterator end() const noexcept
Gets an iterator to one-past-the-end of the collection.
Definition: regex.h:1995
const_reference suffix() const
Gets a sub_match representing the match suffix.
Definition: regex.h:1971
bool ready() const noexcept
Indicates if the match_results is ready.
Definition: regex.h:1847
bool empty() const noexcept
Indicates if the match_results contains no results.
Definition: regex.h:1877
string_type format(const char_type *__fmt, match_flag_type __flags=regex_constants::format_default) const
Definition: regex.h:2055
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:2002
const_iterator begin() const noexcept
Gets an iterator to the start of the sub_match collection.
Definition: regex.h:1981
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:2804
regex_iterator operator++(int)
Postincrements a regex_iterator.
Definition: regex.h:2817
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:2747
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:2797
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:2944
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:2976
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:2909
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:2926
regex_token_iterator operator++(int)
Postincrements a regex_token_iterator.
Definition: regex.h:3034
const value_type * operator->() const
Selects a regex_token_iterator member.
Definition: regex.h:3021
regex_token_iterator()
Default constructs a regex_token_iterator.
Definition: regex.h:2871
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:3014
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:2893
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