From deb47c0c47624b3cee6dbcc8d61be3b7672b5bd2 Mon Sep 17 00:00:00 2001 From: Neil MacIntosh Date: Mon, 20 Mar 2017 19:54:30 -0700 Subject: [PATCH] Corrected obsolete syntax in span examples. --- CppCoreGuidelines.md | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/CppCoreGuidelines.md b/CppCoreGuidelines.md index 1ac94b3..90332ef 100644 --- a/CppCoreGuidelines.md +++ b/CppCoreGuidelines.md @@ -17729,9 +17729,9 @@ Pointers should only refer to single objects, and pointer arithmetic is fragile { if (a.length() < 2) return; - int n = *a++; // OK + int n = a[0]; // OK - span q = a + 1; // OK + span q = a.subspan(1); // OK if (a.length() < 6) return; @@ -17807,6 +17807,16 @@ Dynamic accesses into arrays are difficult for both tools and humans to validate for (int i = 0; i < COUNT; ++i) av[i] = i; } + + // ALTERNATIVE Aa: Use a span and range-for + void f1a() + { + int arr[COUNT]; + span av = arr; + int i = 0; + for (auto& e : av) + e = i++; + } // ALTERNATIVE B: Use at() for access void f2()