C++11 introduces an uniform syntax for initialising containers with contained values.
Works with all types of containers, for example with std::vector, std::map, std::set, std::list and std::string.
It uses the same syntax we are used for C arrays and structs.
Before C++11
void foo(std::vector<int>);
std::vector<int> vi;
vi.push_back(42);
vi.push_back(-1);
foo(vi);Since C++11
void foo(std::vector<int>);
std::vector<int> vi = {42, -1};
foo(vi);
//////////
foo({42, -1});One limitation (still present in C++20), is that the type requires a copy-constructor.
There is work going on to remove this limitation.