Files
cppdraft_translate/cppdraft/re/submatch.md
2025-10-25 03:02:53 +03:00

7.7 KiB
Raw Blame History

[re.submatch]

28 Text processing library [text]

28.6 Regular expressions library [re]

28.6.8 Class template sub_match [re.submatch]

28.6.8.1 General [re.submatch.general]

1

#

Class template sub_match denotes the sequence of characters matched by a particular marked sub-expression.

namespace std {templateclass sub_match : public pair<BidirectionalIterator, BidirectionalIterator> {public:using value_type =typename iterator_traits::value_type; using difference_type =typename iterator_traits::difference_type; using iterator = BidirectionalIterator; using string_type = basic_string<value_type>; bool matched; constexpr sub_match();

difference_type length() const; operator string_type() const; string_type str() const; int compare(const sub_match& s) const; int compare(const string_type& s) const; int compare(const value_type* s) const; void swap(sub_match& s) noexcept(see below); };}

28.6.8.2 Members [re.submatch.members]

🔗

constexpr sub_match();

1

#

Effects: Value-initializes the pair base class subobject and the membermatched.

🔗

difference_type length() const;

2

#

Returns: matched ? distance(first, second) : 0.

🔗

operator string_type() const;

3

#

Returns: matched ? string_type(first, second) : string_type().

🔗

string_type str() const;

4

#

Returns: matched ? string_type(first, second) : string_type().

🔗

int compare(const sub_match& s) const;

5

#

Returns: str().compare(s.str()).

🔗

int compare(const string_type& s) const;

6

#

Returns: str().compare(s).

🔗

int compare(const value_type* s) const;

7

#

Returns: str().compare(s).

🔗

void swap(sub_match& s) noexcept(see below);

8

#

Preconditions: BidirectionalIterator meets the Cpp17Swappable requirements ([swappable.requirements]).

9

#

Effects: Equivalent to:this->pair<BidirectionalIterator, BidirectionalIterator>::swap(s); std::swap(matched, s.matched);

10

#

Remarks: The exception specification is equivalent tois_nothrow_swappable_v.

28.6.8.3 Non-member operators [re.submatch.op]

1

#

Let SM-CAT(I) becompare_three_way_result_t<basic_string<typename iterator_traits::value_type>>

🔗

template<class BiIter> bool operator==(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);

2

#

Returns: lhs.compare(rhs) == 0.

🔗

template<class BiIter> auto operator<=>(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);

3

#

Returns: static_cast<SM-CAT(BiIter)>(lhs.compare(rhs) <=> 0).

🔗

template<class BiIter, class ST, class SA> bool operator==( const sub_match<BiIter>& lhs, const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);

4

#

Returns: lhs.compare(typename sub_match::string_type(rhs.data(), rhs.size())) == 0

🔗

template<class BiIter, class ST, class SA> auto operator<=>( const sub_match<BiIter>& lhs, const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);

5

#

Returns: static_cast<SM-CAT(BiIter)>(lhs.compare(typename sub_match::string_type(rhs.data(), rhs.size()))<=> 0)

🔗

template<class BiIter> bool operator==(const sub_match<BiIter>& lhs, const typename iterator_traits<BiIter>::value_type* rhs);

6

#

Returns: lhs.compare(rhs) == 0.

🔗

template<class BiIter> auto operator<=>(const sub_match<BiIter>& lhs, const typename iterator_traits<BiIter>::value_type* rhs);

7

#

Returns: static_cast<SM-CAT(BiIter)>(lhs.compare(rhs) <=> 0).

🔗

template<class BiIter> bool operator==(const sub_match<BiIter>& lhs, const typename iterator_traits<BiIter>::value_type& rhs);

8

#

Returns: lhs.compare(typename sub_match::string_type(1, rhs)) == 0.

🔗

template<class BiIter> auto operator<=>(const sub_match<BiIter>& lhs, const typename iterator_traits<BiIter>::value_type& rhs);

9

#

Returns: static_cast<SM-CAT(BiIter)>(lhs.compare(typename sub_match::string_type(1, rhs))<=> 0)

🔗

template<class charT, class ST, class BiIter> basic_ostream<charT, ST>& operator<<(basic_ostream<charT, ST>& os, const sub_match<BiIter>& m);

10

#

Returns: os << m.str().