[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 {templateclass sub_match : public pair {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; 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.3 Swappable requirements"))[.](#members-8.sentence-1) [9](#members-9) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L10961) *Effects*: Equivalent to:this->pair::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[.](#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::value_type>> [🔗](#lib:sub_match,operator==) `template bool operator==(const sub_match& lhs, const sub_match& 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 auto operator<=>(const sub_match& lhs, const sub_match& 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 bool operator==( const sub_match& lhs, const basic_string::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::string_type(rhs.data(), rhs.size())) == 0 [🔗](#lib:operator%3c=%3e,sub_match_) `template auto operator<=>( const sub_match& lhs, const basic_string::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::string_type(rhs.data(), rhs.size()))<=> 0) [🔗](#lib:sub_match,operator==__) `template bool operator==(const sub_match& lhs, const typename iterator_traits::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 auto operator<=>(const sub_match& lhs, const typename iterator_traits::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 bool operator==(const sub_match& lhs, const typename iterator_traits::value_type& rhs); ` [8](#op-8) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L11076) *Returns*: lhs.compare(typename sub_match​::​string_type(1, rhs)) == 0[.](#op-8.sentence-1) [🔗](#lib:sub_match,operator%3c=%3e___) `template auto operator<=>(const sub_match& lhs, const typename iterator_traits::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::string_type(1, rhs))<=> 0) [🔗](#lib:basic_ostream) `template basic_ostream& operator<<(basic_ostream& os, const sub_match& m); ` [10](#op-10) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L11108) *Returns*: os << m.str()[.](#op-10.sentence-1)