This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of C++17 status.

2589. match_results can't satisfy the requirements of a container

Section: 32.9 [re.results] Status: C++17 Submitter: S. B. Tam Opened: 2016-01-24 Last modified: 2017-07-30

Priority: 3

View all other issues in [re.results].

View all issues with C++17 status.

Discussion:

N4567 32.9 [re.results] p2 mentions

The class template match_results shall satisfy the requirements of an allocator-aware container and of a sequence container, as specifed in 23.2.3, except that only operations defined for const-qualified sequence containers are supported.

However, this is impossible because match_results has a operator== whose semantics differs from the one required in Table 95 — "Container requirements".

Table 95 requires that a == b is an equivalence relation and means equal(a.begin(), a.end(), b.begin(), b.end()). But for match_results, a == b and equal(a.begin(), a.end(), b.begin(), b.end()) can give different results. For example:

#include <iostream>
#include <regex>
#include <string>
#include <algorithm>

int main()
{
  std::regex re("a*");
  std::string target("baaab");
  std::smatch a;

  std::regex_search(target, a, re);

  std::string target2("raaau");
  std::smatch b;

  std::regex_search(target2, b, re);

  std::cout << std::boolalpha;
  std::cout << (a == b) << '\n'; // false
  std::cout << std::equal(a.begin(), a.end(), b.begin(), b.end()) << '\n'; // true
}

[2016-02, Issues Telecon]

Marshall: The submitter is absolutely right, but the proposed resolution is insufficient. We should avoid "shall", for once.
Jonathan: This is NAD, because the container comparison functions say "unless otherwise stated", 23.3.1p14 and table 97.
Ville: wrong, table 95 is relevant for ==.
Jonathan: good point

2016-05: Marshall cleans up the wording around the change

[2016-08 - Chicago]

Thurs AM: Moved to Tentatively Ready

Previous resolution [SUPERSEDED]:

This wording is relative to N4567.

  1. Change 32.9 [re.results] p2 as indicated:

    -2- The class template match_results shall satisfy the requirements of an allocator-aware container and of a sequence container, as specified in 23.2.3, except that only operations defined for const-qualified sequence containers are supported and that the semantics of comparison functions are different from those required for a container.

Proposed resolution:

This wording is relative to N4567.

  1. Change 32.9 [re.results] p2 as indicated:

    -2- The class template match_results shall satisfysatisfies the requirements of an allocator-aware container and of a sequence container, as specified in (23.2.3), except that only operations defined for const-qualified sequence containers are supported and the semantics of comparison functions are different from those required for a container.

[Drafting note: (Post-Issaquah) Due to the outdated N4567 wording the project editor accepted the following merge suggestion into N4606 wording: — end drafting note]

This wording is relative to N4606.

  1. Change 32.9 [re.results] p2 as indicated:

    -2- The class template match_results satisfies the requirements of an allocator-aware container and of a sequence container, as specified in (24.2.2.1 [container.requirements.general] and, 24.2.4 [sequence.reqmts]) respectively, except that only operations defined for const-qualified sequence containers are supported and the semantics of comparison functions are different from those required for a container.