In the 2010's, when std::span was not yet standardized, the C++ Core Guidelines project got started. It quickly developed a small library of constructs which authors found they need to recommend in order to be able to abide by the guidelines - the guidelines support library (GSL) (link is to Microsoft's implementation). Among other things, the GSL includes a span class: gsl::span<T>. Eventually, in 2020, std::span was officially standardized.
Recently, as I mentioned std::span to someone, they told me:
std::span is a trap, gsl::span should be used instead
what could they have meant? Isn't std::span supposed to be basically the same thing as gsl::span? I mean, after all, it's basically just a structure with a pointer and a size_t, and some convenience methods, isn't it?
From the GSL span class' documentation page (emphasis mine):
The only difference between
gsl::spanandstd::spanis thatgsl::spanstrictly enforces runtime bounds checking. Any violations of the bounds check results in termination of the program.
and the same goes for the two span classes' iterators.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With