What is the rationale for including <initializer_list>

From [dcl.init.list]

The std​::​initializer_list template is not predefined; if the header is not included before using std​::​initializer_list - even an implicit use in which the type is not named, the program is poorly formed.

Since std​::​initializer_list is compiled in any case by the compiler, why is it not considered as the syntax of the first class of the language?

My thoughts on some features and its counter-arguments:

Namespace pollution

It can be solved in the same way as std::size_t , including only the header introduces an identifier .

Note that auto sz = sizeof(0); well-formed, even without the inclusion of any headers, unlike auto il = {1, 2, 3}; poorly formed.

Assembly overhead

libstdC ++ implementation of std::initializer_list is literally less than 50 lines, regardless of other headers. How big can the invoice be?

+7
c ++
source share

No one has answered this question yet.

See similar questions:

60
Does `sizeof` * * really evaluate` std :: size_t`? Maybe this?

or similar:

8499
What is the "->" operator in C ++?
3076
What are the differences between a pointer variable and a reference variable in C ++?
2387
What does an explicit keyword mean?
2101
What is the difference between #include <filename> and #include "filename"?
1994
What are the basic rules and idioms for operator overloading?
1911
What is the rule of three?
1717
What is the idiom of copy and swap?
1564
What is semantics of movement?
1391
What is a lambda expression in C ++ 11?
2
Implicit use of initializer_list

All Articles