4 ms·
std::array will instantiate function templates for all used array sizes, lengthen compilation time, and be hard to use across separately-compiled code without p
by yakubin 5y ago
std::array will instantiate function templates for all used array sizes, lengthen compilation time, and be hard to use across separately-compiled code without putting code into headers. It has its uses, but more often I'd prefer T[N] with bounds-checking, and, in another world, a builtin variably-sized, non-resizable array type; basically a sort of absl::FixedArray[1], but with the semantics of operator[] and at() reversed, so that bounds-checking is the default. Sadly, nothing like that is included in the standard, so won't be a lingua-franca.
[1]: <https://github.com/abseil/abseil-cpp/blob/master/absl/container/fixed_array.h https://github.com/abseil/abseil-cpp/blob/master/absl/contai...>
- pjmlp 5y agoOn Visual Studio it is relatively easy to enable bounds checking for operator[](). https://docs.microsoft.com/en-us/visualstudio/debugger/how-to-use-native-run-time-checks?view=vs-2019 https://docs.microsoft.com/en-us/visualstudio/debugger/how-t... That is the thing, the standard doesn't require bounds checking for operator()[], while it does require for at(), but it doesn't forbid it either, it is up to the implementations.