From 05c44d23abd2ae9454bdeb3c134983eae4c905e6 Mon Sep 17 00:00:00 2001 From: Seulgi Kim Date: Sun, 8 Oct 2017 00:00:04 +0900 Subject: [PATCH 1/3] Fix typos in example. --- CppCoreGuidelines.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CppCoreGuidelines.md b/CppCoreGuidelines.md index 2bd16cc..2688f1c 100644 --- a/CppCoreGuidelines.md +++ b/CppCoreGuidelines.md @@ -1021,7 +1021,7 @@ Time and space that you spend well to achieve a goal (e.g., speed of development x.ch = 'a'; x.s = string(n); // give x.s space for *p for (int i = 0; i < x.s.size(); ++i) x.s[i] = buf[i]; // copy buf into x.s - delete buf; + delete[] buf; return x; } @@ -16243,7 +16243,7 @@ and should be used only as building blocks for meaningful concepts, rather than template concept Addable = has_plus; // bad; insufficient - template auto algo(const N& a, const N& b) // use two numbers + template auto plus(const N& a, const N& b) // use two numbers { // ... return a + b; @@ -16273,7 +16273,7 @@ The ability to specify a meaningful semantics is a defining characteristic of a && has_multiply && has_divide; - template auto algo(const N& a, const N& b) // use two numbers + template auto plus(const N& a, const N& b) // use two numbers { // ... return a + b; From 17f76d0258786c3d013e1c527666767d6ea2be54 Mon Sep 17 00:00:00 2001 From: Andrew Pardoe Date: Mon, 23 Oct 2017 11:20:37 -0700 Subject: [PATCH 2/3] Update CppCoreGuidelines.md --- CppCoreGuidelines.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/CppCoreGuidelines.md b/CppCoreGuidelines.md index 2688f1c..187f929 100644 --- a/CppCoreGuidelines.md +++ b/CppCoreGuidelines.md @@ -16243,7 +16243,7 @@ and should be used only as building blocks for meaningful concepts, rather than template concept Addable = has_plus; // bad; insufficient - template auto plus(const N& a, const N& b) // use two numbers + template auto algo(const N& a, const N& b) // use two numbers { // ... return a + b; @@ -16273,7 +16273,7 @@ The ability to specify a meaningful semantics is a defining characteristic of a && has_multiply && has_divide; - template auto plus(const N& a, const N& b) // use two numbers + template auto algo(const N& a, const N& b) // use two numbers { // ... return a + b; @@ -16281,11 +16281,11 @@ The ability to specify a meaningful semantics is a defining characteristic of a int x = 7; int y = 9; - auto z = plus(x, y); // z = 18 + auto z = algo(x, y); // z = 18 string xx = "7"; string yy = "9"; - auto zz = plus(xx, yy); // error: string is not a Number + auto zz = algo(xx, yy); // error: string is not a Number ##### Note From 19d7fb14214eb92907c0c37df5e8c08ed9362b70 Mon Sep 17 00:00:00 2001 From: Andrew Pardoe Date: Mon, 23 Oct 2017 11:22:02 -0700 Subject: [PATCH 3/3] Update CppCoreGuidelines.md --- CppCoreGuidelines.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CppCoreGuidelines.md b/CppCoreGuidelines.md index 187f929..e67da73 100644 --- a/CppCoreGuidelines.md +++ b/CppCoreGuidelines.md @@ -16251,11 +16251,11 @@ and should be used only as building blocks for meaningful concepts, rather than int x = 7; int y = 9; - auto z = plus(x, y); // z = 16 + auto z = algo(x, y); // z = 16 string xx = "7"; string yy = "9"; - auto zz = plus(xx, yy); // zz = "79" + auto zz = algo(xx, yy); // zz = "79" Maybe the concatenation was expected. More likely, it was an accident. Defining minus equivalently would give dramatically different sets of accepted types. This `Addable` violates the mathematical rule that addition is supposed to be commutative: `a+b == b+a`.