2 ms·
Do you mean std::extent? [0] You can do the same in C if you define a macro that uses sizeof [1] This doesn't diminish the advantage of std::array, though, as
by MaxBarraclough 6y ago
Do you mean std::extent? [0] You can do the same in C if you define a macro that uses sizeof [1]
This doesn't diminish the advantage of std::array, though, as it embeds the size of the array into the object, unlike when a raw array is passed and 'decays' to a pointer.
[0] https://en.cppreference.com/w/cpp/types/extent https://en.cppreference.com/w/cpp/types/extent
[1] https://stackoverflow.com/a/4415646/ https://stackoverflow.com/a/4415646/
- saagarjha 6y agoI mean like you can pass it through a function by using the “array syntax” when defining the parameter and making the size a template parameter. Like so: template <size_t N> void foo(int bar[N]) And this gives you the size without an additional size parameter as you’d usually need in C (of course with the limitation that the parameter now has to be a compile-time sized array).