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

3630. Inconsistent basic_regex construction and assignment from iterator range

Section: 32.7.2 [re.regex.construct] Status: New Submitter: Jonathan Wakely Opened: 2021-10-31 Last modified: 2022-01-29

Priority: 4

View other active issues in [re.regex.construct].

View all other issues in [re.regex.construct].

View all issues with New status.

Discussion:

We have:

template<class ForwardIterator>
  basic_regex(ForwardIterator first, ForwardIterator last,
              flag_type f = regex_constants::ECMAScript);

and:

template<class InputIterator>
  basic_regex& assign(InputIterator first, InputIterator last,
                          flag_type f = regex_constants::ECMAScript);

Ignoring the lack of proper requirements (which is LWG 3341), why does the constructor take forward iterators, but the assign function takes input iterators? Why could construction from input iterators not be implemented as simply assign(first, last, f)?

The current constructor signature is the result of N2409 which was resolving LWG 682. It looks like the assign function should have been changed at the same time, to keep them consistent. I see no reason why they can't both take input iterators. The meta-programming needed to avoid an additional string copy for the input iterator case is trivial with if constexpr and C++20 iterator concepts.

[2022-01-29; Reflector poll]

Set priority to 4 after reflector poll.

Proposed resolution: