In the follwoing code:
#include <iostream>
#include <vector>
int main()
{
std::cout<<"Hello World";
std::vector<std::vector<int>> v;
while(v.size() <= 2){
v.insert(v.begin(),{}); //1
std::cout << "!";
}
return 0;
}
The output is getting increasingly aggressive with every iteration, because the v.size() never increases, despite the insert operation.
However, when the initializer_list has an element in it, or replaced with a temporary, the cycle runs as many times as expected.
...
v.insert(v.begin(),{0}); //1
...
...
v.insert(v.begin(),std::vector<int>()); //1
...
Why is that? Shouldn't there be a compile error if implicit conversion fails?