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

251 lines
7.7 KiB
Markdown
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

[re.submatch]
# 28 Text processing library [[text]](./#text)
## 28.6 Regular expressions library [[re]](re#submatch)
### 28.6.8 Class template sub_match [re.submatch]
#### [28.6.8.1](#general) General [[re.submatch.general]](re.submatch.general)
[1](#general-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L10835)
Class template sub_match denotes the sequence of characters matched
by a particular marked sub-expression[.](#general-1.sentence-1)
namespace std {template<class BidirectionalIterator>class sub_match : public pair<BidirectionalIterator, BidirectionalIterator> {public:using value_type =typename iterator_traits<BidirectionalIterator>::value_type; using difference_type =typename iterator_traits<BidirectionalIterator>::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) Members [[re.submatch.members]](re.submatch.members)
[🔗](#lib:sub_match,constructor)
`constexpr sub_match();
`
[1](#members-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L10878)
*Effects*: Value-initializes the pair base class subobject and the membermatched[.](#members-1.sentence-1)
[🔗](#lib:sub_match,length)
`difference_type length() const;
`
[2](#members-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L10890)
*Returns*: matched ? distance(first, second) : 0[.](#members-2.sentence-1)
[🔗](#lib:operator_basic_string,sub_match)
`operator string_type() const;
`
[3](#members-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L10901)
*Returns*: matched ? string_type(first, second) : string_type()[.](#members-3.sentence-1)
[🔗](#lib:sub_match,str)
`string_type str() const;
`
[4](#members-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L10912)
*Returns*: matched ? string_type(first, second) : string_type()[.](#members-4.sentence-1)
[🔗](#lib:sub_match,compare)
`int compare(const sub_match& s) const;
`
[5](#members-5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L10923)
*Returns*: str().compare(s.str())[.](#members-5.sentence-1)
[🔗](#lib:sub_match,compare_)
`int compare(const string_type& s) const;
`
[6](#members-6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L10934)
*Returns*: str().compare(s)[.](#members-6.sentence-1)
[🔗](#lib:sub_match,compare__)
`int compare(const value_type* s) const;
`
[7](#members-7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L10945)
*Returns*: str().compare(s)[.](#members-7.sentence-1)
[🔗](#lib:sub_match,swap)
`void swap(sub_match& s) noexcept(see below);
`
[8](#members-8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L10956)
*Preconditions*: BidirectionalIterator meets
the *Cpp17Swappable* requirements ([[swappable.requirements]](swappable.requirements "16.4.4.3Swappable requirements"))[.](#members-8.sentence-1)
[9](#members-9)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L10961)
*Effects*: Equivalent to:this->pair<BidirectionalIterator, BidirectionalIterator>::swap(s);
std::swap(matched, s.matched);
[10](#members-10)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L10969)
*Remarks*: The exception specification is equivalent tois_nothrow_swappable_v<BidirectionalIterator>[.](#members-10.sentence-1)
#### [28.6.8.3](#op) Non-member operators [[re.submatch.op]](re.submatch.op)
[1](#op-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L10977)
Let *SM-CAT*(I) becompare_three_way_result_t<basic_string<typename iterator_traits<I>::value_type>>
[🔗](#lib:sub_match,operator==)
`template<class BiIter>
bool operator==(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
`
[2](#op-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L10990)
*Returns*: lhs.compare(rhs) == 0[.](#op-2.sentence-1)
[🔗](#lib:sub_match,operator%3c=%3e)
`template<class BiIter>
auto operator<=>(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
`
[3](#op-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L11002)
*Returns*: static_cast<*SM-CAT*(BiIter)>(lhs.compare(rhs) <=> 0)[.](#op-3.sentence-1)
[🔗](#lib:operator==,sub_match_)
`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](#op-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L11016)
*Returns*: lhs.compare(typename sub_match<BiIter>::string_type(rhs.data(), rhs.size())) == 0
[🔗](#lib:operator%3c=%3e,sub_match_)
`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](#op-5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L11032)
*Returns*: static_cast<*SM-CAT*(BiIter)>(lhs.compare(typename sub_match<BiIter>::string_type(rhs.data(), rhs.size()))<=> 0)
[🔗](#lib:sub_match,operator==__)
`template<class BiIter>
bool operator==(const sub_match<BiIter>& lhs,
const typename iterator_traits<BiIter>::value_type* rhs);
`
[6](#op-6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L11050)
*Returns*: lhs.compare(rhs) == 0[.](#op-6.sentence-1)
[🔗](#lib:sub_match,operator%3c=%3e__)
`template<class BiIter>
auto operator<=>(const sub_match<BiIter>& lhs,
const typename iterator_traits<BiIter>::value_type* rhs);
`
[7](#op-7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L11063)
*Returns*: static_cast<*SM-CAT*(BiIter)>(lhs.compare(rhs) <=> 0)[.](#op-7.sentence-1)
[🔗](#lib:sub_match,operator==___)
`template<class BiIter>
bool operator==(const sub_match<BiIter>& lhs,
const typename iterator_traits<BiIter>::value_type& rhs);
`
[8](#op-8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L11076)
*Returns*: lhs.compare(typename sub_match<BiIter>::string_type(1, rhs)) == 0[.](#op-8.sentence-1)
[🔗](#lib:sub_match,operator%3c=%3e___)
`template<class BiIter>
auto operator<=>(const sub_match<BiIter>& lhs,
const typename iterator_traits<BiIter>::value_type& rhs);
`
[9](#op-9)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L11089)
*Returns*: static_cast<*SM-CAT*(BiIter)>(lhs.compare(typename sub_match<BiIter>::string_type(1, rhs))<=> 0)
[🔗](#lib:basic_ostream)
`template<class charT, class ST, class BiIter>
basic_ostream<charT, ST>&
operator<<(basic_ostream<charT, ST>& os, const sub_match<BiIter>& m);
`
[10](#op-10)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L11108)
*Returns*: os << m.str()[.](#op-10.sentence-1)