From [dcl.init.list]
The template
std::initializer_list
is not predefined; if the header <initializer_list> is not included prior to a use ofstd::initializer_list
— even an implicit use in which the type is not named — the program is ill-formed.
Since std::initializer_list
is special-cased by the compiler anyway, why is it not treated as a first-class syntax of the language?
My thoughts on some possibilities and its counter-arguments:
Could be solved just like std::size_t
, the inclusion of the header only introduces the identifier.
Note how auto sz = sizeof(0);
is well-formed even without the inclusion of any headers, as opposed to auto il = {1, 2, 3};
being ill-formed.
libstdc++ implementation of std::initializer_list
is literally less than 50 lines with no dependency on other headers. How big of overhead can that be?
It seems that there is no rational behind it. Maybe at the time there was an hope that further language resolutions and modifications allow an implementation, but this doesn't seems real now.
In any case further reading about the argument can be found here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With