3 ms·
And probably never will, because C++ compatibility with C beyond what was done initially, is to one be close as possible but not at the expense of better altern
by pjmlp 1y ago
And probably never will, because C++ compatibility with C beyond what was done initially, is to one be close as possible but not at the expense of better alternatives that the language already offers.
Thus std::array, std::span, std::string, std::string_view, std::vector, with hardned options turned on.
For the static thing, the right way in C++ is to use a template parameter,
template<typename T, int size>
int foo(T (&ary)[size]) {
return size;
}
-- https://godbolt.org/z/MhccKWocE https://godbolt.org/z/MhccKWocE
If you want to get fancy, you might make use of concepts, or constexpr to validate size at compile time.
- loeg 1y agoI guess. I think it's mostly not a very useful part of C, so it doesn't see much adoption in C anyway. In these applications, size and T are fixed -- you'd just take `std::span<uint8_t, XCHACHA20POLY1305_NONCE_SIZE>` rather than templating.