|
|
|
|
|
by drivebyhooting
9 days ago
|
|
The problem is not the size of the span template, it’s putting whatever logic into a header file instead of a sealed compilation unit. In a void* function prototype, whatever network code or gnarly dependency is all shielded behind a compilation unit.
If you make it a template function the compiler will have to (re)process a lot of code.
You could make the interface templatized in a header file and have the actual implementation use void * or char * pointer. That would recover good compiler performance. I don’t think span provides much if any safety for the implementer of the library function. I’m also not convinced it’s more ergonomic for the caller. |
|
std::span provides multiple ways of safely accessing data. For one, it provides an contiguous iterator, so you get access to the algorithms library basically for free. Second, you get safer accessors to the data inside, such as at, and even [] can be protected through contracts. Finally, even if you don't care about/can use these features, tying the pointer and length together reduces chances for variable confusion.