As far as I understand, c++ templating works by compiling a separate class or function for every type needed. This seems logical for classes or functions that will only be called for a handful of different types / parameters, but for std::array
it seems like this could result in the same class being compiled into hundreds of different versions.
I understand the advantages of std::array
over C style arrays, but it seems like using the former would result in huge binary sizes compared to the latter if my above assumption is correct.
For example, if say in a large program we end up using 99 arrays of different sizes throughout the entire code, so that we effectively have:
int arr[1] = { ... }
int arr[2] = { ... }
int arr[...] = { ... }
int arr[99] = { ... }
int arr[100] = { ... }
Or
std::array<int, 1> arr = { ... }
std::array<int, 2> arr = { ... }
std::array<int, ...> arr = { ... }
std::array<int, 99> arr = { ... }
std::array<int, 100> arr = { ... }
Would the std::array
example end up with the entire class and all its functions being compiled into the binary 99 times?