What is the rationale for including <initializer_list>
From [dcl.init.list]
The
std::initializer_listtemplate is not predefined; if the header is not included before usingstd::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?
No one has answered this question yet.
See similar questions:
or similar: