class template
<regex>

std::sub_match

template <class BidirectionalIterator>class sub_match : public pair <BidirectionalIterator, BidirectionalIterator>;
Sub-expression match
Stores each of the individual matches of a match_results object filled by one of the regex algorithms regex_match or regex_search, or by the regex iterators (regex_iterator and regex_token_iterator).

These matches are sequences of characters. But objects of this class do not store the sequence of characters itself, but instead, the class derives from pair to hold a pair of bidirectional iterators to the initial and past-the-end characters of a sequence, and provides reference semantics to this sequence.

This class adds to the data inherited by pair a public member variable of type bool, named matched. This member holds the state of the object (either matched or not matched). Objects constructed with its default constructor will have this member set to false, while objects part of a match_results object will have it set to true.

Objects of this type can be converted to string objects (or the appropriate basic_string type), and, when compared, behave as such. They also have a length member that behaves like its string counterpart.

Four instantiations of this basic class exist in the standard header <regex> for the most common cases:
1
2
3
4
typedef sub_match<const char*> csub_match;
typedef sub_match<const wchar_t*> wcsub_match;
typedef sub_match<string::const_iterator> ssub_match;
typedef sub_match<wstring::const_iterator> wssub_match;


Template parameters

BidirectionalIterator
A bidirectional iterator type that iterates on a sequence of characters.

Template instantiations


Member types

The following aliases are member types of sub_match:

member typedefinitionnotes
value_typeiterator_traits<BidirectionalIterator>::value_typeType of the characters in the sequence.
string_typebasic_string<value_type>Type of string for the characters type.
iteratorBidirectionalIteratorThe template parameter
difference_typeiterator_traits<BidirectionalIterator>::size_typeusually the same as ptrdiff_t
first_typeBidirectionalIteratorsame as iterator (inherited from pair).
second_typeBidirectionalIteratorsame as iterator (inherited from pair).

Member functions


The class also inherits member swap from pair.