In his C++ Core Guidelines, Bjarne Stroustrup recommends using span when passing arrays by reference. Why not just pass a std::array object?
Passing std::array
by value would be copying them. The point of gsl::span
is that the function taking them is referencing an existing array of data.
gsl::span
is capable of taking arrays of runtime-defined sizes. std::array
is fixed at compile-time.
gsl::span
does not care what type owns the array; it's just a pointer+size. So a span
-based interface can be fed data from std::vector
, QVector
, and many other types. A std::array
based interface requires that you use that specific container.
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