Back to Basics: Smart Pointers - Rainer Grimm - CppCon 2020

Veröffentlicht am: 01 Januar 1970
auf dem Kanal: CppCon
32,239
735

https://cppcon.org/
https://github.com/CppCon/CppCon2020/...
---
From the library's perspective, an essential feature in C++11 was smart pointers.

Since C++11, we have four different smart pointer: std::auto_ptr, std::unique_ptr, std::shared_pointer, and std::weak_ptr. With C++17 std::auto_ptr was removed and with C++20, we get an std::atomic<std::shared_ptr>, and std::atomic<std::weak_ptr>.

Each smart pointer models a specific ownership semantic and has a particular purpose. The crucial question is, therefore: When should you use which smart pointer? The answer to this question becomes more sophisticated when you think about the arguments or the return value of a function. You have to answer the following question for the function arguments:

What does it mean to take the function arguments by pointer, by std::unique_ptr, or by std::shared_ptr?
Should the function take the smart pointer by value or by reference?
Should the argument be const or not?

The answers to those questions are not the end of the story. When you have a factory function creating something, the question immediately arises: Should the factory function return its product by a pointer, by std::unique_ptr, or by std::shared_ptr?

Smart pointers are more than pointers decorated with smartness. Smart pointer models ownership semantic. Understanding the ownership semantic of smart pointers is the main topic of my talk and, therefore, your takeaway.

---
Rainer works as a software architect, team lead, and instructor since 1999. In 2002, he created a further education round at his company. He gives seminars since 2002. Rainer's first seminars were about proprietary management software, but seminars for Python and C++ followed immediately. In his spare time, Rainer likes to write articles about C++, Python, and Haskell. He also likes to speak at conferences. Rainer publishes weekly on his English Modernes Cpp and the German blog, hosted by Heise Developer.
Since 2016 he is an independent instructor giving seminars about modern C++ and Python. Rainer published several books in various languages to modern C++ and concurrency, in particular. Due to his profession, Rainer always searches for the best way to teach modern C++.

---
Work at Hudson River Trading (HRT): https://tinyurl.com/safxfctf
---

Streamed & Edited by Digital Medium Ltd - events.digital-medium.co.ukevents@digital-medium.co.uk

*-----*
Register Now For CppCon 2022: https://cppcon.org/registration/
*-----*


Auf dieser Seite können Sie das Online-Video Back to Basics: Smart Pointers - Rainer Grimm - CppCon 2020 mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer CppCon 01 Januar 1970 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 32,239 Mal angesehen und es wurde von 735 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!