Back to Basics: Move Semantics - Nicolai Josuttis - CppCon 2021

Поделиться
HTML-код
  • Опубликовано: 4 ноя 2024

Комментарии • 65

  • @hellfirelordofevil
    @hellfirelordofevil 2 года назад +81

    A thoroughly excellent talk, this is by far the clearest and least confused explanation of C++ move semantics I have encountered. Bravo!

    • @RukshanVidurangaPerera
      @RukshanVidurangaPerera 2 года назад +2

      Yes, after so many references this is the first material which gave me a clear idea what is actually happening. Like more videos from the C++ committee.

  • @debajyotimajumder472
    @debajyotimajumder472 9 месяцев назад +6

    wow. After struggling to understand move semantics for months...I finally get it. Thank you CPPCON & Nicolai Josuttis!!

  • @ppb2374
    @ppb2374 Месяц назад

    看到一半,忍不住要给老师点个赞,讲得非常好!把move语意的引入原因,使用方法讲得透透的,谢谢

  • @MaitreBart
    @MaitreBart 2 года назад +2

    Quite a complete summary that exposes most if not all the move semantic intricacies.

  • @culturedgator
    @culturedgator 2 года назад +7

    Thank you for the talk! I am learning C++ as a novice and really enjoying these sessions!
    Very clear, with specific examples to explain the context and the value of the concept. 5/5!

  • @markbotner7878
    @markbotner7878 2 года назад +1

    I wore the spine out of his 1st edition of "The C++ Standard Library". Thanks so much for that book, it very much helped me learn how to use the C++ standard library!

  • @AA-em3lw
    @AA-em3lw 2 года назад +9

    Thank you so much for these amazing videos. I've borrowed Nicolai's book "The c++ Standard Library", You are so inspirational and give great examples, thank you Nicolai.

  • @MrHidefr
    @MrHidefr 2 года назад +4

    Thank you for explaining why std::forward exists, it makes it easy to understand what it does and when you have to use it.

  • @akuskus
    @akuskus 2 года назад +3

    Very clear, concise and meticulous talk, much appreciated.

  • @andrestone
    @andrestone 2 года назад +2

    The best talk ever on this topic.

  • @MeeroSom
    @MeeroSom 2 года назад +4

    Thank you for making these videos, Mr Josuttis.

  • @JeremyCoppin
    @JeremyCoppin Год назад +2

    Brilliantly explained. Thank you Mr Josuttis.

  • @bareminimum-mrtz
    @bareminimum-mrtz 3 месяца назад

    Thankyou so much !!!
    Finally i can understand the difference between push_back and emplace_back

  • @ivancheburan2209
    @ivancheburan2209 Год назад

    This is a perfect explanation what the move semantics is.

  • @younghsiang2509
    @younghsiang2509 2 года назад +1

    Great example! Thanks to this video, now I have better understanding on move semantics.

    • @CppCon
      @CppCon  2 года назад

      Excellent!

  • @shailendrarajput6219
    @shailendrarajput6219 Год назад

    Thank you so much for deeply understanding of the move semantic and universal forwarding.

  • @xealit
    @xealit 3 месяца назад

    18:20 on "what is the state of the moved-from object, what can be done with it" it would be more useful to say _which methods get called_ after marking an object to be moved. Firstly, move turns all calls to construction and assignment from copy to move versions. So, the move constructor and the move assignment get called whenever construction and assignment are done in the code. It does not trigger any other methods on top of those two. Hence, the moved-from object is in whatever state that was left by the two standard move methods, constructor and assignment.
    Then, it's clear how the same works with functions and methods that take an && rvalue. Move returns an rvalue of the object, which tells the rest of the code that it can do whatever it wants with the rvalue object, its content is not needed. E.g. foo(string&& str) can clear the string or modify it or leave as is, i.e. leave it in valid but unknown for the caller state.

  • @khatdubell
    @khatdubell 2 года назад +2

    55:45 , 57:00
    In C++ 20 you will use this a lot.
    Is there an actual compelling example?
    I haven’t seen much that using `auto&& c = thing()`
    Buys you over using `auto c = thing()` and then moving later instead of forwarding.
    One less move constructor call, and if it’s a copy only type will be one less copy, which is obviously good, however the trade off is much messier syntax.
    I would personally prefer the simpler, easier to read version with an extra possible copy and optimize later if it’s a performance bottle neck.
    But maybe I’m missing something?

  • @talluay3567
    @talluay3567 2 года назад +3

    53:26 I think "Jil" from the variable first will not be moved as the constructor of Cust takes const std::string& as parameter
    Good video. Give me motivation to see whats on C++20.

    • @filipp.v
      @filipp.v Год назад

      @@squarerootof2 @talluay3567 is right. Cust constructor is called in the emplace_back() by calling the placement new operator

  • @pesto801
    @pesto801 2 года назад +2

    Thank you for the nice talk! "Back to Basics" to the bone.
    Why do destructors in derived classes destroy move semantics?

  • @ohwow2074
    @ohwow2074 2 года назад

    The last part about universal reference was very useful.

  • @xealit
    @xealit 3 месяца назад

    Excellent presentation ! 👏

  • @xealit
    @xealit 3 месяца назад

    29:15 on not returning const value from a function - wasn't there a recommendation from Scott Meyers to return const value, to prevent the user from making calls on a temporary value by mistake? Maybe that was before the rvalues though!

  • @alexmomot6268
    @alexmomot6268 2 года назад +2

    Thank you Nicolai for such informative and detailed explanation of move semantics.
    It would be interesting to read your ne books as well. ;)

  • @Moriadin
    @Moriadin 2 года назад

    Excellent, clear talk and the best on the subject. thank you!

    • @CppCon
      @CppCon  2 года назад

      Glad you enjoyed it!

  • @GauravKumar-pu1eh
    @GauravKumar-pu1eh Год назад

    best explanation on move semantics

  • @PixelPulse168
    @PixelPulse168 Год назад

    the best move semantics out there.

  • @sirnawaz
    @sirnawaz 2 года назад

    11:52, instead of using `std::move()`, I think it's better to use `std::exchange()`, like:
    history.push_back(std::exchange(s, getDefaultValue()));
    That isn't only one-line implementation of `reinit()`, it is also efficient, as `std::exchange` moves the first parameter as well.

  • @motngay1niemvui
    @motngay1niemvui 2 года назад +1

    Excellent talk

  • @thestarinthesky_
    @thestarinthesky_ 6 месяцев назад

    Awesome 👏 ❤Thank you so much for sharing ❤

  • @flocela
    @flocela Год назад

    Thank you for this talk.

  • @goregeway8287
    @goregeway8287 2 года назад +2

    Well explained! Thx a lot!

  • @deepaksree6
    @deepaksree6 Год назад

    good one, got the basics thanks

  • @sadiqueali930
    @sadiqueali930 2 года назад +1

    Really informative

  • @buzzdx
    @buzzdx 2 года назад +1

    very nicely explained, thanks.

    • @CppCon
      @CppCon  2 года назад +1

      You are welcome!

  • @sociocritical
    @sociocritical 2 года назад

    great talk as always

    • @CppCon
      @CppCon  2 года назад

      Thank you very much for your comment.

  • @zoso25
    @zoso25 2 года назад

    At 53:24 why would calling std::move(first) result in a _move_? The constructor has a const std::string& for the first parameter. So shouldn't it be a copy?

  • @DiegoDagumSoftware
    @DiegoDagumSoftware 2 года назад

    Dear @CppCon, I would love to get the slide deck of this talk. Is sharing it a possibility?

  • @MichalMaruska1971
    @MichalMaruska1971 2 месяца назад

    38:14 "it's completely on the stack" .... that's not true. It is in an already allocated memory (be it on the stack or heap).

  • @yongningfan4979
    @yongningfan4979 2 года назад

    One point, on Page 22, string move semantics, string move constructor, dose s.data assigns to nullptr? I did some tests, data still is valid address. Pls correct me if I am wrong.

  • @yevhenukrainianer4781
    @yevhenukrainianer4781 2 года назад

    Brilliant explanation.

  • @simonfarre4907
    @simonfarre4907 2 года назад

    Doesn't the c++ compiler elide the destructor at 7:12? It seems as though it should.

  • @yogeshjoshi8047
    @yogeshjoshi8047 2 года назад

    At 47:00 can anyone explain why foo(std::move(x)); will call the wrong function?

  • @CallumPooleProgrammer
    @CallumPooleProgrammer 2 года назад +2

    Question:
    It's not so nice having this T&& or auto&& for a universal reference since the type is vague.
    Would it be possible to confine the type with concepts / requires T is MyClass somehow?
    Also is there any plan to 'fix' forwarding in C++23?

    • @FruchteisMitErdbeer
      @FruchteisMitErdbeer 2 года назад +1

      Sure, it's easy using concepts:
      template
      concept ref_to = std::same_as;
      Then use it like:
      void f(ref_to auto&& p) { /*...*/ }
      This takes lvalue references and rvalue references, but only to MyClass.

    • @_RMSG_
      @_RMSG_ 2 года назад

      @@FruchteisMitErdbeer It doesn't really look easy to read though

  • @myth2732
    @myth2732 Год назад

    Great Talk!!!!!

  • @mohamedhashem1938
    @mohamedhashem1938 2 года назад

    just amazing

  • @slko1000
    @slko1000 10 месяцев назад

    Nice 👌

  • @MO-fg2cm
    @MO-fg2cm 3 месяца назад

    Damn ... so much behind the scenes

  • @chair547
    @chair547 7 месяцев назад

    my life would be better if i knew less c++

  • @EvgeniiBalaukhin
    @EvgeniiBalaukhin 2 года назад

    🖖

  • @WangMiracle
    @WangMiracle 2 года назад

    how to get slide?

    • @CppCon
      @CppCon  2 года назад

      Sorry, the slides are presently unavailable. We are looking to rectify this in the future.

  • @TheDoomista
    @TheDoomista Год назад

    "some" views not supporting iteration while const is a very nasty behaviour. More so since it is non-deterministic (at least at glance). Couldn't it be solved with mutable keyword? Recommending using auto&& so stuff works doesn't seem like the best idea as it is the first step to sacrifice const correctness.. :(
    Otherwise - great talk! The more I delve into the move semantics the more they seem unfinished. The "valid but unspecified state" effectively means that unless your compiler supports use-after-move detection then you shouldn't ever move a named variable or else you risk shooting yourself in the foot. If that detection was default, then the compiler would move a lot of stuff automatically. This way, you're forced to optimize by hand a risk a bug.

  • @khatdubell
    @khatdubell 2 года назад

    21:15
    This is wrong.
    T&& where T is a template type isn’t a rvalue reference.
    Outside the context of a templates type this would be true, but, this accepts both r and l values.

    • @heldhelm
      @heldhelm 2 года назад +1

      Would it not only be a universal reference, if the template was defined for the function only, not the complete class?

  • @GeorgeTsiros
    @GeorgeTsiros Год назад

    You are ambiguous in crucial points, Nicolai. 11:30 you talk on this so much but you never explained what does _here_ mean. You repeat the word "move", that it doesn't _move_ anything, that it is a mark, etcetc, but you do not refer to the thing that matters: the _ownership_