mirror of
https://github.com/isocpp/CppCoreGuidelines.git
synced 2025-12-17 04:44:34 +03:00
Corrected obsolete syntax in span examples.
This commit is contained in:
@@ -17729,9 +17729,9 @@ Pointers should only refer to single objects, and pointer arithmetic is fragile
|
|||||||
{
|
{
|
||||||
if (a.length() < 2) return;
|
if (a.length() < 2) return;
|
||||||
|
|
||||||
int n = *a++; // OK
|
int n = a[0]; // OK
|
||||||
|
|
||||||
span<int> q = a + 1; // OK
|
span<int> q = a.subspan(1); // OK
|
||||||
|
|
||||||
if (a.length() < 6) return;
|
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)
|
for (int i = 0; i < COUNT; ++i)
|
||||||
av[i] = i;
|
av[i] = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ALTERNATIVE Aa: Use a span and range-for
|
||||||
|
void f1a()
|
||||||
|
{
|
||||||
|
int arr[COUNT];
|
||||||
|
span<int,COUNT> av = arr;
|
||||||
|
int i = 0;
|
||||||
|
for (auto& e : av)
|
||||||
|
e = i++;
|
||||||
|
}
|
||||||
|
|
||||||
// ALTERNATIVE B: Use at() for access
|
// ALTERNATIVE B: Use at() for access
|
||||||
void f2()
|
void f2()
|
||||||
|
|||||||
Reference in New Issue
Block a user