mirror of
https://github.com/isocpp/CppCoreGuidelines.git
synced 2024-03-22 13:30:58 +08:00
Merge pull request #593 from ubique/span-c-style-traversal-example
Fix span C-style traversal example
This commit is contained in:
commit
27dc740789
|
@ -2672,7 +2672,7 @@ A `span` represents a range of elements, but how do we manipulate elements of th
|
||||||
void f(span<int> s)
|
void f(span<int> s)
|
||||||
{
|
{
|
||||||
for (int x : s) cout << x << '\n'; // range traversal (guaranteed correct)
|
for (int x : s) cout << x << '\n'; // range traversal (guaranteed correct)
|
||||||
for (int i = 0; i < s.size(); ++i) cout << x << '\n'; // C-style traversal (potentially checked)
|
for (int i = 0; i < s.size(); ++i) cout << s[i] << '\n'; // C-style traversal (potentially checked)
|
||||||
s[7] = 9; // random access (potentially checked)
|
s[7] = 9; // random access (potentially checked)
|
||||||
std::sort(&s[0], &s[s.size() / 2]); // extract pointers (potentially checked)
|
std::sort(&s[0], &s[s.size() / 2]); // extract pointers (potentially checked)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user