There was a clear lack of coverage of std::span on UA-cam. Your older video about spans helped me complete a project about a month back. Glad to see a newer one now! Thank you!
So a span does not own the underlying data, so there's no way to take ownership of the underlying memory directly from a span (e.g., if you took a span of part of a vector, the vector still owns the underlying memory, and you can't steal it away through the span). If you want to copy the data, somewhere else, that's perfectly fine (but that's not transferring/taking ownership, that creating a copy) Cheers, --Nick
can you talk about how to template std::span? i tried the obvious method: template void print_span(std::span _span_); and it didn't work. I would have to explicitly construct a std::span at the call site (print_span{vec}). This isn't too bad but I don't understand why it cant implicitly convert to a std::span without me having to manually construct one, which might lead to a copy of the span being made, since I am constructing the span at the call site and also passing it to the function, meaning it probably copies itself. Then I would have to pass it by rvalue reference or const reference, which ultimately defeats the purpose of using span. Is there a simple way to template std::span without having to explicitly construct it at the call site?
There was a clear lack of coverage of std::span on UA-cam. Your older video about spans helped me complete a project about a month back. Glad to see a newer one now! Thank you!
Currently reading through Bjarne Stroustrup's "A Tour of C++" and this video really cleared up some confusion I had. Thanks Nick!
Hey man could you please make a detailed video on c++ memory order and atomic?
Will be covering more advanced memory topics when we get into parallel programming + threads!
@@NotesByNick really excited! honestly your way of teaching C++ is so much elegant and intuitive! most underrated C++ channel ever
@@quant-prep2843 thanks! Glad you think so :^)
Thanks for the video, it's good stuff. How would one go about copying data from a span and thus transfering or taking ownership of it?
So a span does not own the underlying data, so there's no way to take ownership of the underlying memory directly from a span (e.g., if you took a span of part of a vector, the vector still owns the underlying memory, and you can't steal it away through the span).
If you want to copy the data, somewhere else, that's perfectly fine (but that's not transferring/taking ownership, that creating a copy)
Cheers,
--Nick
Really cool video!! You are quite a gifted popularizer
You're a great teacher....thanks a lot!!!
Thank you for watching! :^)
can you talk about how to template std::span? i tried the obvious method:
template
void print_span(std::span _span_);
and it didn't work. I would have to explicitly construct a std::span at the call site (print_span{vec}). This isn't too bad but I don't understand why it cant implicitly convert to a std::span without me having to manually construct one, which might lead to a copy of the span being made, since I am constructing the span at the call site and also passing it to the function, meaning it probably copies itself. Then I would have to pass it by rvalue reference or const reference, which ultimately defeats the purpose of using span.
Is there a simple way to template std::span without having to explicitly construct it at the call site?
Thanks.
Might be worth mentioning that std::span is readonly.
Not sure what you mean - you can modify the underlying memory of a span - godbolt.org/z/MhsxdWqnM
Maybe you’re thinking of std::string_view? (Which is read only)
Is that how we're supposed to pronounce "std"? I don't like it 😂. I prefer pronouncing it as "standard".