Title
Including <initializer_list> for range-based for
Status
drafting
Section
8.6.5 [stmt.ranged]
Submitter
Richard Smith

Created on 2013-05-13.00:00:00 last changed 136 months ago

Messages

Date: 2013-09-15.00:00:00

Notes from the September, 2013 meeting:

CWG felt that this issue should be resolved by using the array variant of the range-based for implementation.

Date: 2013-05-13.00:00:00

A simple example like

  int main() {
    int k = 0;
    for (auto x : { 1, 2, 3 })
      k += x;
    return k;
  }

requires that the <initializer_list> header be included, because the expansion of the range-based for involves a declaration of the form

  auto &&__range = { 1, 2, 3 };

and a braced-init-list causes auto to be deduced as a specialization of std::initializer_list. This seems unnecessary and could be eliminated by specifying that __range has an array type for cases like this.

(It should be noted that EWG is considering a proposal to change auto deduction for cases involving braced-init-lists, so resolution of this issue should be coordinated with that effort.)

History
Date User Action Args
2013-10-14 00:00:00adminsetmessages: + msg4625
2013-10-14 00:00:00adminsetstatus: open -> drafting
2013-05-13 00:00:00admincreate