There can be no general answer to this question.
For a function, to say that it accepts span<T> means that it takes a continuous array of values ββwithout any form of transfer of ownership. If this description does not give a reasonable idea of ββwhat is happening, then it should not accept span<T> .
For instance:
What should I do if the function checks to see if the buffer crosses an area in my memory space that, say, is mapped to a file?
This is not like span<T> . It looks like you should have a simple aggregate with a name that allows you to understand what this means:
struct memory_region { void* p; size_t size_in_bytes; };
You can even give it a member function to test intersections. If you are creating a system to work with such areas of memory, I would recommend a more encapsulated class type with constructors, etc.
What type of function should consider what the data means. Preferably this meaning will be in a general sense, but at least he should say what it means for the function in question.
One more thing:
or span<uint8_t> etc. would imply that foo really expects characters
No, it will not. Although uint8_t almost certainly be the same size as an unsigned char , this does not mean that one would expect to pass an array of characters to any function that accepts span<uint8_t> . If this function wanted to advertise that it accepted characters, it would use an unsigned char .
I wanted to say that span<whatever> would mean a function to expect whatever .
Yes, the span requirement is that the actual array T given size is passed to it.
source share