[re.results.general]

# 28 Text processing library [[text]](./#text)

## 28.6 Regular expressions library [[re]](re#results.general)

### 28.6.9 Class template match_results [[re.results]](re.results#general)

#### 28.6.9.1 General [re.results.general]

[1](#1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L11116)

Class template match_results denotes a collection of character
sequences representing the result of a regular expression
match[.](#1.sentence-1)

Storage for the collection is allocated and freed as necessary
by the member functions of class template match_results[.](#1.sentence-2)

[2](#2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L11123)

The class template match_results meets the requirements of an
allocator-aware container ([[container.alloc.reqmts]](container.alloc.reqmts "23.2.2.5 Allocator-aware containers")) and of
a sequence container ([[container.requirements.general]](container.requirements.general "23.2.2 General containers"), [[sequence.reqmts]](sequence.reqmts "23.2.4 Sequence containers"))
except that only
copy assignment,
move assignment, and
operations defined for const-qualified sequence containers
are supported and
that the semantics of the comparison operator functions are different from those
required for a container[.](#2.sentence-1)

[3](#3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L11137)

A default-constructed match_results object has no fully established result state[.](#3.sentence-1)

A
match result is [*ready*](futures.state#def:ready "32.10.5 Shared state [futures.state]") when, as a consequence of a completed regular expression match
modifying such an object, its result state becomes fully established[.](#3.sentence-2)

The effects of calling
most member functions from a match_results object that is not ready are undefined[.](#3.sentence-3)

[4](#4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L11143)

The sub_match object stored at index 0 represents sub-expression 0,
i.e., the whole match[.](#4.sentence-1)

In this case the sub_match membermatched is always true[.](#4.sentence-2)

The sub_match object stored at index n denotes what matched the marked
sub-expression n within the matched expression[.](#4.sentence-3)

If the
sub-expression n participated in a regular expression
match then the sub_match member matched evaluates to true, and
members first and second denote the range of characters
[first, second) which formed that
match[.](#4.sentence-4)

Otherwise matched is false, and members first and second point to the end of the sequence
that was searched[.](#4.sentence-5)

[*Note [1](#note-1)*:

The sub_match objects representing
different sub-expressions that did not participate in a regular expression
match need not be distinct[.](#4.sentence-6)

â *end note*]

namespace std {template<class BidirectionalIterator, class Allocator = allocator<sub_match<BidirectionalIterator>>>class match_results {public:using value_type = sub_match<BidirectionalIterator>; using const_reference = const value_type&; using reference = value_type&; using const_iterator = *implementation-defined*; using iterator = const_iterator; using difference_type =typename iterator_traits<BidirectionalIterator>::difference_type; using size_type = typename allocator_traits<Allocator>::size_type; using allocator_type = Allocator; using char_type =typename iterator_traits<BidirectionalIterator>::value_type; using string_type = basic_string<char_type>; // [[re.results.const]](re.results.const "28.6.9.2 Constructors"), construct/copy/destroy match_results() : match_results(Allocator()) {}explicit match_results(const Allocator& a);
 match_results(const match_results& m);
 match_results(const match_results& m, const Allocator& a);
 match_results(match_results&& m) noexcept;
 match_results(match_results&& m, const Allocator& a);
 match_results& operator=(const match_results& m);
 match_results& operator=(match_results&& m); ~match_results(); // [[re.results.state]](re.results.state "28.6.9.3 State"), statebool ready() const; // [[re.results.size]](re.results.size "28.6.9.4 Size"), size size_type size() const;
 size_type max_size() const; bool empty() const; // [[re.results.acc]](re.results.acc "28.6.9.5 Element access"), element access difference_type length(size_type sub = 0) const;
 difference_type position(size_type sub = 0) const;
 string_type str(size_type sub = 0) const;
 const_reference operator[](size_type n) const;

 const_reference prefix() const;
 const_reference suffix() const;
 const_iterator begin() const;
 const_iterator end() const;
 const_iterator cbegin() const;
 const_iterator cend() const; // [[re.results.form]](re.results.form "28.6.9.6 Formatting"), formattemplate<class OutputIter> OutputIter
 format(OutputIter out, const char_type* fmt_first, const char_type* fmt_last,
 regex_constants::match_flag_type flags = regex_constants::format_default) const; template<class OutputIter, class ST, class SA> OutputIter
 format(OutputIter out, const basic_string<char_type, ST, SA>& fmt,
 regex_constants::match_flag_type flags = regex_constants::format_default) const; template<class ST, class SA> basic_string<char_type, ST, SA> format(const basic_string<char_type, ST, SA>& fmt,
 regex_constants::match_flag_type flags = regex_constants::format_default) const;
 string_type
 format(const char_type* fmt,
 regex_constants::match_flag_type flags = regex_constants::format_default) const; // [[re.results.all]](re.results.all "28.6.9.7 Allocator"), allocator allocator_type get_allocator() const; // [[re.results.swap]](re.results.swap "28.6.9.8 Swap"), swapvoid swap(match_results& that); };}
