C++ Object Lifetime: From Start to Finish - Thamara Andrade - CppCon 2023

Sdílet
Vložit
  • čas přidán 6. 02. 2024
  • cppcon.org/
    ---
    C++ Object Lifetime: From Start to Finish - Thamara Andrade - CppCon 2023
    github.com/CppCon/CppCon2023
    Object lifetime is one of the core concepts of C++ and understanding it is critical to write correct and efficient code.
    This talk provides an overview of an object's lifetime, rules for extending it, as well as pitfalls when dealing with temporary objects.
    Whether you are a seasoned C++ programmer or just starting out, this talk will provide you with valuable insights into one of the most fundamental aspects of the language.
    ---
    Thamara Andrade
    Principal Software Engineer working for 10+ years with C++ and adventuring into new technologies through open-source projects. Always engaged in projects aiming to enhance women's presence in the tech world.
    ---
    Videos Filmed & Edited by Bash Films: www.BashFilms.com
    CZcams Channel Managed by Digital Medium Ltd: events.digital-medium.co.uk
    ---
    Registration for CppCon: cppcon.org/registration/
    #cppcon #cppprogramming #cpp
  • Věda a technologie

Komentáře • 12

  • @Rayornick
    @Rayornick Před 3 měsíci

    57:50 as I can see it's will use copy constructor if we returning variable created out getFoo() scope (member of class for example) and use rvo optimization if it's was created inside of scope of getFoo()

  • @AlfredoCorrea
    @AlfredoCorrea Před 3 měsíci +4

    I find lifetime extension one of the most mysterious corners of the language. I don’t complain, because I use it all the time, but it is, at the least, inconsistent and incidentally shaky for generic code . For example, why not lifetime extension by T&? (BTW, there is lifetime extension by T&&, not mentioned here, which is even stranger). In generic code, one might use T const& t = f(); as an optimization in case f returns a reference. But if f returns a different type, even by reference, then the line may construct a T (and likely allocate or copy data) giving a surprise degradation in performance in that generic expression and, more insidious, produce a different semantic for the expression.

    • @Rayornick
      @Rayornick Před 3 měsíci +1

      "But if f returns a different type, even by reference, then the line may construct a T (and likely allocate or copy data) giving a surprise degradation in performance in that generic expression and, more insidious, produce a different semantic for the expression."
      gcc have -Wdangling-reference which can help to catch such cases.

    • @AlfredoCorrea
      @AlfredoCorrea Před 3 měsíci

      @Rayornick Thanks, the semantic problem happens when the object of the different type is copied (into the “const&”) so it is not the dangling case. Still the warning can help of course.

    • @kuhluhOG
      @kuhluhOG Před měsícem

      Shouldn't it also be possible for "T const& t = f();" to also create a dangling reference?

  • @abuyoyo31
    @abuyoyo31 Před 3 měsíci

    45:39 : How is it that in the first loop range1 is an rvalue reference "vector &&," and in the second loop range1 is "const vector&" ?

  • @yifanliu4401
    @yifanliu4401 Před 3 měsíci +1

    😢

  • @anon_y_mousse
    @anon_y_mousse Před 3 měsíci

    I still don't know why the committee had to make the rules so complex. I made the rules significantly simpler for my own language. As for pronouncing std, I say standard. Saying stood or stud or whatever single syllable pronunciation that people use just sounds wrong, and referring to each letter of an abbreviation as though it's an acronym when it's not, is also wrong. I only hope that whatever they've come up with for modules is as intelligent as some other languages have done things, whereby you import into a namespace of your choice, so you can import whole cloth into your current namespace or into one that's named how you like it. I'm personally tired of how C++ does it, either always adding a `using` somewhere or std:: in front of everything.

  • @TheNovakon
    @TheNovakon Před 3 měsíci +2

    That feeling when I know C++ better than the speaker 😀

  • @about2mount
    @about2mount Před 3 měsíci

    Of all the syntax chosen for and within C++ why the hell did they ever decide to use STD instead of SSD? Ask yourselves which is easier to type. using namespace ssd; or ssd::string var or ssd::endl;

    • @9uiop
      @9uiop Před 3 měsíci

      Yeah, nonsense decision by the C++ Ssandards Committee

    • @abhinavk0929
      @abhinavk0929 Před 3 měsíci +1

      that's a peculiar question, i'm more curious about why you recomment ssd, why not something else?