Title
Inconsistent basic_regex construction and assignment from iterator range
Status
new
Section
[re.regex.construct]
Submitter
Jonathan Wakely

Created on 2021-10-31.00:00:00 last changed 3 weeks ago

Messages

Date: 2021-10-31.00:00:00

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.

History
Date User Action Args
2021-10-31 00:00:00admincreate