What is the difference between passing span <T> and std :: array as arguments?
In his C ++ Fundamentals , Bjarne Stroustrup recommends using span when passing arrays by reference. Why not just pass the std :: array object?
+6
1 answer
Passing
std::arrayby value will copy them. The point ofgsl::spanis that the function that takes them refers to an existing dataset.gsl::spanis capable of accepting arrays with specific runtime sizes.std::arrayis fixed at compile time.gsl::spandoesn't care which type belongs to the array; it's just a pointer + size. Thus, thespaninterface can be passed fromstd::vector,QVectorand many other types. Thestd::arraybased interface requires you to use this specific container.
+10