30 Regular expressions library [re]

30.9 Class template sub_­match [re.submatch]

Class template sub_­match denotes the sequence of characters matched by a particular marked sub-expression.
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;
    };
}

30.9.1 Members [re.submatch.members]

constexpr sub_match();
Effects: Value-initializes the pair base class subobject and the member matched.
difference_type length() const;
Returns: matched ? distance(first, second) : 0.
operator string_type() const;
Returns: matched ? string_­type(first, second) : string_­type().
string_type str() const;
Returns: matched ? string_­type(first, second) : string_­type().
int compare(const sub_match& s) const;
Returns: str().compare(s.str()).
int compare(const string_type& s) const;
Returns: str().compare(s).
int compare(const value_type* s) const;
Returns: str().compare(s).

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

Let SM-CAT(I) be
compare_three_way_result_t<basic_string<typename iterator_traits<I>::value_type>>
template<class BiIter> bool operator==(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
Returns: lhs.compare(rhs) == 0.
template<class BiIter> auto operator<=>(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
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);
Returns:
lhs.compare(typename sub_match<BiIter>::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);
Returns:
static_cast<SM-CAT(BiIter)>(lhs.compare(
    typename sub_match<BiIter>::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);
Returns: lhs.compare(rhs) == 0.
template<class BiIter> auto operator<=>(const sub_match<BiIter>& lhs, const typename iterator_traits<BiIter>::value_type* rhs);
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);
Returns: lhs.compare(typename sub_­match<BiIter>​::​string_­type(1, rhs)) == 0.
template<class BiIter> auto operator<=>(const sub_match<BiIter>& lhs, const typename iterator_traits<BiIter>::value_type& rhs);
Returns:
static_cast<SM-CAT(BiIter)>(lhs.compare(
    typename sub_match<BiIter>::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);
Returns: os << m.str().