C++ Object Lifetime: From Start to Finish - Thamara Andrade - CppCon 2023
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
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()
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.
"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.
@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.
Shouldn't it also be possible for "T const& t = f();" to also create a dangling reference?
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&" ?
😢
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.
That feeling when I know C++ better than the speaker 😀
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;
Yeah, nonsense decision by the C++ Ssandards Committee
that's a peculiar question, i'm more curious about why you recomment ssd, why not something else?