From 3b29134985c6d52fe96952971ff1fdee27b15f71 Mon Sep 17 00:00:00 2001 From: Michael Park Date: Thu, 10 Dec 2015 07:22:57 -0500 Subject: [PATCH 1/2] P.1: The index result of a `std::find`-like loop needs to be initialized to -1. --- CppCoreGuidelines.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CppCoreGuidelines.md b/CppCoreGuidelines.md index 5b3ccab..11b2645 100644 --- a/CppCoreGuidelines.md +++ b/CppCoreGuidelines.md @@ -370,7 +370,7 @@ The second version leaves the reader guessing and opens more possibilities for u string val; cin >> val; // ... - int index = 0; // bad + int index = -1; // bad for (int i = 0; i < v.size(); ++i) if (v[i] == val) { index = i; From a26d6c98d54b9f2e33334415639f0789e4af8d8b Mon Sep 17 00:00:00 2001 From: Michael Park Date: Thu, 10 Dec 2015 07:23:41 -0500 Subject: [PATCH 2/2] P.1: Fixed incorrect use of `std::find`. --- CppCoreGuidelines.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CppCoreGuidelines.md b/CppCoreGuidelines.md index 11b2645..2ed28a0 100644 --- a/CppCoreGuidelines.md +++ b/CppCoreGuidelines.md @@ -387,7 +387,7 @@ A much clearer expression of intent would be: string val; cin >> val; // ... - auto p = find(v, val); // better + auto p = find(begin(v), end(v), val); // better // ... }