Initializing an array with a initializer_list? [duplicate] Initializing an array with a initializer_list? [duplicate] arrays arrays

Initializing an array with a initializer_list? [duplicate]


Not in this case. You can initialize array with a list-initializer

std::array<int, 2> a{1,2};

but you cannot initialize array with initializer_list, since array is just an aggregate type with only the default and copy constructor.

You can just leave the array empty and then copy the contents of the initializer_list into it.