Clearly, std :: initializer_list is not an actual container. The standard clearly defines what you can and cannot do with std :: initializer_list.
But why does the language retain the ability to do stupid things, for example, assign a temporary std :: initializer_list to another , when it could be easily blocked using = delete the move destination operator in std :: initializer_list?
Here is an example of the code that compiles:
void foo(std::initializer_list<int> v) {
std::cout << *v.begin() << std::endl;
}
int main() {
int a = 1, b = 2, c = 3;
auto val = {a, b, c};
foo(val);
int i = 7;
val = {i};
foo(val);
}
Exit , courtesy of @nwp:
1
-365092848
source
share