Boost logo

Boost :

From: Vinnie Falco (vinnie.falco_at_[hidden])
Date: 2024-12-06 18:06:07


On Fri, Dec 6, 2024 at 9:12 AM Peter Dimov via Boost <boost_at_[hidden]>
wrote:

> The purpose of span is to replace pointer arguments. If your function
> takes
> ...
> void f2( unsigned char p[4] );
> you use
> void f2( span<unsigned char, 4> p );
>

This is quite informative, thank you. For my entire career I have avoided
passing C-style arrays because of ignorance of how they work. Is it a copy?
Is it just a pointer? Does the compiler know the extent? And so on. I don't
like the look of function signatures which accept language arrays, because
they do not quite work the same way as other types.

The fixed extent span here does two things: first, it inserts a runtime
> check that the extent of the passed span is >= 4.
> ...
> Since it's statically known that 0<4, 1<4, 2<4, 3<4, these accesses don't
> cause any asserts to be inserted.

This is a strong rationale for using a span-like type in the signatures for
those implementation functions.

Thanks


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk