How can I make a3
compile?
int main()
{
int a1[] = { 1, 2, 3 };
std::array<int, 3> a2 = { 1, 2, 3 };
std::array<int> a3 = { 1, 2, 3 };
}
It's very inconvenient, and brittle, to hard-code the size of the array when using an initialization list, especially long ones. Is there any work around? I hope so otherwise I'm disappointed because I hate C arrays and std::array
is supposed to be their replacement.
make_array()
function. – Geigerauto a3 = std::to_array<int>({3, 2, 1});
– Trench