I have a const z* zs = nullptr;
I want to convert zs
to std::span
When I try to do std::span<const z>(zs)
I get an error saying
error: no matching function for call to ‘std::span::span(const z* const&)’
How do I convert to zs to std::span
I tried std::span<const z>(zs[0])
it seems to compile. Is that way correct?
span
overnullptr
to behave? This seems broken by design. – Synesthesia*(zs + 0)
wherezs = nullptr
) is undefined behavior. That's why you have no error from the compiler. – Snorkelnullptr
- the problem is that a span has to know how many elements to span over. Pointers, by design, do not store any such information. The question is, why do you want to do this conversion? If you simply want to have a zero-length span, then there is no reason to set up a pointer in the first place. – Tarsia