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

Поділитися
Вставка
  • Опубліковано 9 лип 2024
  • cppcon.org/
    github.com/CppCon/CppCon2021
    ---
    Move semantics, introduced with C++11, has become a hallmark of modern C++ programming. However, it also complicates the language in some ways. For thisu reason it is key to understand move semantics (it purpose, its basic rules, and how to use them in practice).
    This session teaches the basics of C++ move semantics. Based on the basic principles, it motivates and explains move semantics so that you as an application programmer you can use move semantics correctly und understand its use better.
    ---
    Nicolai Josuttis
    Nicolai Josuttis (www.josuttis.com) is well known in the programming community because he not only speaks and writes with authority (being the (co-)author of the world-wide best sellers The C++ Standard Library (www.cppstdlib.com), C++ Templates (www.tmplbook.com), C++17 - The Complete Guide (www.cppstd17.com), C++ Move Semantics - The Complete Guide (www.cppmove.com), and SOA in Practice), but is also an innovative presenter, having talked at various conferences and events.
    He has been an active member of the C++ standards committee for more than 20 years.
    ---
    Videos Streamed & Edited by Digital Medium: online.digital-medium.co.uk
    *--*
  • Наука та технологія

КОМЕНТАРІ • 58

  • @hellfirelordofevil
    @hellfirelordofevil 2 роки тому +73

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

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

      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 5 місяців тому +3

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

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

    Thank you for making these videos, Mr Josuttis.

  • @akuskus
    @akuskus 2 роки тому +2

    Very clear, concise and meticulous talk, much appreciated.

  • @culturedgator
    @culturedgator 2 роки тому +6

    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!

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

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

  • @AA-em3lw
    @AA-em3lw 2 роки тому +7

    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.

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

    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!

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

    Brilliantly explained. Thank you Mr Josuttis.

  • @andrestone
    @andrestone 2 роки тому +2

    The best talk ever on this topic.

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

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

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

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

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

    This is a perfect explanation what the move semantics is.

  • @goregeway8287
    @goregeway8287 2 роки тому +2

    Well explained! Thx a lot!

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

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

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

      Excellent!

  • @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!

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

    Thank you for this talk.

  • @thestarinthesky_
    @thestarinthesky_ 2 місяці тому

    Awesome 👏 ❤Thank you so much for sharing ❤

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

    Brilliant explanation.

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

    The last part about universal reference was very useful.

  • @GauravKumar-pu1eh
    @GauravKumar-pu1eh Рік тому

    best explanation on move semantics

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

    Excellent talk

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

    the best move semantics out there.

  • @deepaksree6
    @deepaksree6 8 місяців тому

    good one, got the basics thanks

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

    Really informative

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

    Great Talk!!!!!

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

    just amazing

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

    great talk as always

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

      Thank you very much for your comment.

  • @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?

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

    very nicely explained, thanks.

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

      You are welcome!

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

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

  • @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?

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

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

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

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

  • @slko1000
    @slko1000 6 місяців тому

    Nice 👌

  • @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?

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

    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.

  • @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 11 місяців тому

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

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

    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.

  • @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_ Рік тому

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

  • @chair547
    @chair547 3 місяці тому

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

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

    🖖

  • @user-yn8ic4bw7q
    @user-yn8ic4bw7q 2 роки тому

    how to get slide?

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

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

  • @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?

  • @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.

  • @GeorgeTsiros
    @GeorgeTsiros 10 місяців тому

    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_