From 024f1a05dc12683e9a4fee33ec4b2b9d13404db0 Mon Sep 17 00:00:00 2001 From: hsutter Date: Tue, 2 Jul 2019 14:29:25 -0700 Subject: [PATCH] Restored accidentally overwritten editorial changes --- CppCoreGuidelines.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/CppCoreGuidelines.md b/CppCoreGuidelines.md index 18b41f0..aaaf8b7 100644 --- a/CppCoreGuidelines.md +++ b/CppCoreGuidelines.md @@ -6658,7 +6658,7 @@ resource management problems. return sv; } - A user can reasonably assume that returning a standard-like container is cheap. +A user can reasonably assume that returning a standard-like container is cheap. ##### Enforcement @@ -7904,12 +7904,12 @@ Avoid resource leaks. ##### Reason - `make_unique` gives a more concise statement of the construction. +`make_unique` gives a more concise statement of the construction. It also ensures exception safety in complex expressions. ##### Example - unique_ptr p {new{7}}; // OK: but repetitive + unique_ptr p {new Foo{7}}; // OK: but repetitive auto q = make_unique(7); // Better: no repetition of Foo @@ -7935,14 +7935,14 @@ It also ensures exception safety in complex expressions. ##### Reason - `make_shared` gives a more concise statement of the construction. +`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{7}}; + shared_ptr p {new Bar{7}}; auto q = make_shared(7); // Better: no repetition of Bar; one object } @@ -8473,7 +8473,7 @@ So far, so good, but we can easily misuse the `union`: cout << v.x << '\n'; // BAD, undefined behavior: v holds a double, but we read it as an int Note that the type error happened without any explicit cast. -When we tested that program the last value printed was `1683627180` which it the integer value for the bit pattern for `987.654`. +When we tested that program the last value printed was `1683627180` which is the integer value for the bit pattern for `987.654`. What we have here is an "invisible" type error that happens to give a result that could easily look innocent. And, talking about "invisible", this code produced no output: @@ -8727,7 +8727,7 @@ Switching on an enumeration is common and the compiler can warn against unusual } } -Such off-by-one switch`statements are often the results of an added enumerator and insufficient testing. +Such off-by-one `switch`statements are often the results of an added enumerator and insufficient testing. ##### Enforcement @@ -10717,7 +10717,7 @@ Use `={...}` if you really want an `initializer_list` `={}` gives copy initialization whereas `{}` gives direct initialization. Like the distinction between copy-initialization and direct-initialization itself, this can lead to surprises. -`{}` accepts `explicit` constructors; `={}` does not`. For example: +`{}` accepts `explicit` constructors; `={}` does not. For example: struct Z { explicit Z() {} }; -- 2.11.4.GIT