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