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

### 909. `regex_token_iterator` should use `initializer_list`

Section: 30.11.2 [re.tokiter] Status: C++11 Submitter: Daniel Krügler Opened: 2008-09-26 Last modified: 2016-01-28

Priority: Not Prioritized

View all other issues in [re.tokiter].

View all issues with C++11 status.

Discussion:

Addresses UK 319

Construction of a `regex_token_iterator` (30.11.2 [re.tokiter]/6+) usually requires the provision of a sequence of integer values, which can currently be done via a `std::vector<int>` or a C array of `int`. Since the introduction of `initializer_list` in the standard it seems much more reasonable to provide a corresponding constructor that accepts an `initializer_list<int>` instead. This could be done as a pure addition or one could even consider replacement. The author suggests the replacement strategy (A), but provides an alternative additive proposal (B) as a fall-back, because of the handiness of this range type:

[ Batavia (2009-05): ]

> We strongly recommend alternative B of the proposed resolution in order that existing code not be broken. With that understanding, move to Tentatively Ready.

Original proposed wording:

1. 1. In 30.11.2 [re.tokiter]/6 and the list 30.11.2.2 [re.tokiter.cnstr]/10-11 change the constructor declaration:

      >     template <std::size_t N>
      >     regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
      >                          const regex_type& re,
      >                          const int (&submatches)[N] initializer_list<int> submatches,
      >                          regex_constants::match_flag_type m =
      >                            regex_constants::match_default);

   2. In 30.11.2.2 [re.tokiter.cnstr]/12 change the last sentence

      > The third constructor initializes the member `subs` to hold a copy of the sequence of integer values pointed to by the iterator range `[&submatches.begin(), &submatches.end() + N)`.

2. 1. In 30.11.2 [re.tokiter]/6 and the list 30.11.2.2 [re.tokiter.cnstr]/10-11 insert the following constructor declaration between the already existing ones accepting a `std::vector` and a C array of `int`, resp.:

      >     regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
      >                          const regex_type& re,
      >                          initializer_list<int> submatches,
      >                          regex_constants::match_flag_type m =
      >                            regex_constants::match_default);

   2. In 30.11.2.2 [re.tokiter.cnstr]/12 change the last sentence

      > The third and fourth constructor initializes the member `subs` to hold a copy of the sequence of integer values pointed to by the iterator range `[&submatches,&submatches + N)` and `[submatches.begin(),submatches.end())`, respectively.

Proposed resolution:

1. […]

2. 1. In 30.11.2 [re.tokiter]/6 and the list 30.11.2.2 [re.tokiter.cnstr]/10-11 insert the following constructor declaration between the already existing ones accepting a `std::vector` and a C array of `int`, resp.:

      >     regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
      >                          const regex_type& re,
      >                          initializer_list<int> submatches,
      >                          regex_constants::match_flag_type m =
      >                            regex_constants::match_default);

   2. In 30.11.2.2 [re.tokiter.cnstr]/12 change the last sentence

      > The third and fourth constructor initializes the member `subs` to hold a copy of the sequence of integer values pointed to by the iterator range `[&submatches,&submatches + N)` and `[submatches.begin(),submatches.end())`, respectively.