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