Improve smart pointers section.

This commit is contained in:
Anthony Calandra
2020-02-22 17:51:14 -05:00
parent df6400cbb8
commit b12ea9fc7f
2 changed files with 4 additions and 4 deletions

View File

@@ -761,9 +761,9 @@ static_assert(std::is_same<std::conditional<true, int, double>::type, int>::valu
``` ```
### Smart pointers ### Smart pointers
C++11 introduces new smart(er) pointers: `std::unique_ptr`, `std::shared_ptr`, `std::weak_ptr`. `std::auto_ptr` now becomes deprecated and then eventually removed in C++17. C++11 introduces new smart pointers: `std::unique_ptr`, `std::shared_ptr`, `std::weak_ptr`. `std::auto_ptr` now becomes deprecated and then eventually removed in C++17.
`std::unique_ptr` is a non-copyable, movable smart pointer that properly manages arrays and STL containers. **Note: Prefer using the `std::make_X` helper functions as opposed to using constructors. See the sections for [std::make_unique](#stdmake_unique) and [std::make_shared](#stdmake_shared).** `std::unique_ptr` is a non-copyable, movable pointer that manages its own heap-allocated memory. **Note: Prefer using the `std::make_X` helper functions as opposed to using constructors. See the sections for [std::make_unique](#stdmake_unique) and [std::make_shared](#stdmake_shared).**
```c++ ```c++
std::unique_ptr<Foo> p1 { new Foo{} }; // `p1` owns `Foo` std::unique_ptr<Foo> p1 { new Foo{} }; // `p1` owns `Foo`
if (p1) { if (p1) {

View File

@@ -1867,9 +1867,9 @@ static_assert(std::is_same<std::conditional<true, int, double>::type, int>::valu
``` ```
### Smart pointers ### Smart pointers
C++11 introduces new smart(er) pointers: `std::unique_ptr`, `std::shared_ptr`, `std::weak_ptr`. `std::auto_ptr` now becomes deprecated and then eventually removed in C++17. C++11 introduces new smart pointers: `std::unique_ptr`, `std::shared_ptr`, `std::weak_ptr`. `std::auto_ptr` now becomes deprecated and then eventually removed in C++17.
`std::unique_ptr` is a non-copyable, movable smart pointer that properly manages arrays and STL containers. **Note: Prefer using the `std::make_X` helper functions as opposed to using constructors. See the sections for [std::make_unique](#stdmake_unique) and [std::make_shared](#stdmake_shared).** `std::unique_ptr` is a non-copyable, movable pointer that manages its own heap-allocated memory. **Note: Prefer using the `std::make_X` helper functions as opposed to using constructors. See the sections for [std::make_unique](#stdmake_unique) and [std::make_shared](#stdmake_shared).**
```c++ ```c++
std::unique_ptr<Foo> p1 {new Foo{}}; // `p1` owns `Foo` std::unique_ptr<Foo> p1 {new Foo{}}; // `p1` owns `Foo`
if (p1) { if (p1) {