15

As can be seen from https://stackoverflow.com/a/26614984/481267 the following headers are guaranteed by the standard to #include <initializer_list>:

  • Everything in [containers]
  • <utility>
  • <string>
  • <algorithm>
  • <random>
  • <valarray>
  • <regex>

Most of these headers declare at least one function that takes a std::initializer_list<E> argument, so it makes sense. However,

  • <array>, <stack>, and <queue> have no such functions, although perhaps it makes sense to treat all containers uniformly here.
  • <utility> has no such functions.
  • <iterator> does have functions with an initializer_list argument (rbegin, rend) but it's not specified to include <initializer_list>.

What is the rationale behind these exceptions?

Community
  • 1
  • 1
Brian Bi
  • 111,498
  • 10
  • 176
  • 312

1 Answers1

1

Seems like there is no explicit rationale, just that some proposals for additions to the standard were made and those proposals were accepted.

At the very end of the document N2672 Initializer List proposed wording it just says:

In 20.2 Utility components [utility] paragraph 1:

This subclause contains some basic function and class templates that are used throughout the rest of the library.

Header <utility> synopsis

     #include<initializer_list>
      namespace std {

So, the authors of the paper saw initializer_list as a utility, and so it ought to be included with the <utility> header. And therefore it is.

The paper didn't propose any changes to the <iterator> header, so none were made.

Bo Persson
  • 90,663
  • 31
  • 146
  • 203