I know that the below code-block compiles
#include<initializer_list>
int main()
{
std::initializer_list<int> li = {1,2,3,4};
}
I can't understand why this also compiles
#include<iostream>
int main()
{
std::initializer_list<int> li = {1,2,3,4};
}
Is <initializer_list>
included in <iostream>
? According to this, it doesn't seem to be. Could this be a machine/compiler dependent thing?
Is
<initializer_list>
included in<iostream>
?
It is not specified nor guaranteed to be.
But also, it is not guaranteed to not be included. Any standard header may include any other standard header, or system header. You should not rely on such transitive inclusion because another (version of the) standard library might not have such inclusion. Same generally applies to all third party headers as well. Only rely on a transitive inclusion if it is documented and guaranteed.