diff --git a/CppCoreGuidelines.md b/CppCoreGuidelines.md index e7767bee388b6281d1d40e7c2c1cfa6c076675da..15372f76bea884d22118ace1ab5d19a2d8175f48 100644 --- a/CppCoreGuidelines.md +++ b/CppCoreGuidelines.md @@ -8040,25 +8040,7 @@ It also ensures exception safety in complex expressions. ### C.151: Use `make_shared()` to construct objects owned by `shared_ptr`s -##### Reason - -`make_shared` gives a more concise statement of the construction. -It also gives an opportunity to eliminate a separate allocation for the reference counts, by placing the `shared_ptr`'s use counts next to its object. - -##### Example - - void test() - { - // OK: but repetitive; and separate allocations for the Bar and shared_ptr's use count - shared_ptr p {new Bar{7}}; - - auto q = make_shared(7); // Better: no repetition of Bar; one object - } - -##### Enforcement - -* Flag the repetitive usage of template specialization list`` -* Flag variables declared to be `shared_ptr` +See [R.22](#Rr-make_shared) ### C.152: Never assign a pointer to an array of derived class objects to a pointer to its base @@ -9573,7 +9555,8 @@ This is more efficient: ##### Reason -If you first make an object and then give it to a `shared_ptr` constructor, you (most likely) do one more allocation (and later deallocation) than if you use `make_shared()` because the reference counts must be allocated separately from the object. +`make_shared` gives a more concise statement of the construction. +It also gives an opportunity to eliminate a separate allocation for the reference counts, by placing the `shared_ptr`'s use counts next to its object. ##### Example