C++ From Scratch: std::span

Поділитися
Вставка
  • Опубліковано 18 гру 2024

КОМЕНТАРІ • 18

  • @UsernameUsername0000
    @UsernameUsername0000 2 роки тому +4

    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!

  • @zmweb4828
    @zmweb4828 11 місяців тому +1

    Currently reading through Bjarne Stroustrup's "A Tour of C++" and this video really cleared up some confusion I had. Thanks Nick!

  • @quant-prep2843
    @quant-prep2843 2 роки тому +6

    Hey man could you please make a detailed video on c++ memory order and atomic?

    • @NotesByNick
      @NotesByNick  2 роки тому +4

      Will be covering more advanced memory topics when we get into parallel programming + threads!

    • @quant-prep2843
      @quant-prep2843 2 роки тому +2

      @@NotesByNick really excited! honestly your way of teaching C++ is so much elegant and intuitive! most underrated C++ channel ever

    • @NotesByNick
      @NotesByNick  2 роки тому +1

      @@quant-prep2843 thanks! Glad you think so :^)

  • @bpeachey1475
    @bpeachey1475 Рік тому +1

    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?

    • @NotesByNick
      @NotesByNick  Рік тому

      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

  • @MrSebaleme
    @MrSebaleme Рік тому +2

    Really cool video!! You are quite a gifted popularizer

  • @engdoretto
    @engdoretto 2 роки тому +3

    You're a great teacher....thanks a lot!!!

  • @shipweck6253
    @shipweck6253 9 місяців тому

    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?

  • @closerlookcrime
    @closerlookcrime Рік тому +1

    Thanks.

  • @thomas_m3092
    @thomas_m3092 2 роки тому +1

    Might be worth mentioning that std::span is readonly.

    • @NotesByNick
      @NotesByNick  2 роки тому

      Not sure what you mean - you can modify the underlying memory of a span - godbolt.org/z/MhsxdWqnM

    • @NotesByNick
      @NotesByNick  2 роки тому +5

      Maybe you’re thinking of std::string_view? (Which is read only)

  • @CharlvandeMerwe
    @CharlvandeMerwe 5 місяців тому

    Is that how we're supposed to pronounce "std"? I don't like it 😂. I prefer pronouncing it as "standard".