Reputation: 419
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?
Upvotes: 5
Views: 1941
Reputation: 4061
std::span
has a constructor which takes a pointer and a size, use that:
std::span<const z>(zs, 0)
Upvotes: 6
Reputation: 62894
You need to provide a length to go along with your pointer. A null pointer points to 0 elements. Are you reassigning sz
somewhere?
An empty span
is constructed from no arguments.
std::span<const z>{}
Upvotes: 2