Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert a nullptr to std::span

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?

like image 695
TeenyTinySparkles Avatar asked Mar 02 '23 01:03

TeenyTinySparkles


1 Answers

std::span has a constructor which takes a pointer and a size, use that:

std::span<const z>(zs, 0)

like image 182
Mestkon Avatar answered Mar 12 '23 05:03

Mestkon