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 27 months ago

Messages

Date: 2022-01-15.00:00:00

[ 2022-01-29; Reflector poll ]

Set priority to 4 after reflector poll.

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
2022-01-29 22:29:35adminsetmessages: + msg12298
2021-10-31 00:00:00admincreate