CppCon 2015: Neil MacIntosh “Evolving array_view and string_view for safe C++ code"
Why Stack Overflow recommends it
Stack Overflow users link it when explaining the origin of gsl::span (formerly array_view), how it differs from earlier proposals, and why it fails fast on out-of-bounds access.
Recommended by 1 people across 1 different months, 2015 to 2016.
What it is
A one-hour CppCon 2015 talk by Neil MacIntosh of Microsoft on evolving array_view and string_view into safer types for C++, along with related types like not_null. It uses examples from large commercial codebases to show how these zero-overhead types remove whole classes of memory defects by construction.
What people said
Recommends Bjarne Stroustrup · 2016-01 · Stack Overflow · on “What's the difference between span and array_view in the gsl library?”
This was a talk on resources and dangling pointers. span and the GSL was a side issue. Have a look at Neil MacIntosh's CppCon 2015 talk: “Evolving array_view and string_view for safe C++ code" [this video] and/or have a look at the GSL source: [LINK] . We are also working on a formal (standard style) specification.
Cites Matthias Kauer · 2015-11 · Stack Overflow · on “C++: setting constness of pointer based on template parameter”
[this video] (presentation from cppcon) Consider what is being said after 58:55 or so. It's very short and I cannot really judge how legitimate it is although the person seems credible to me. But yeah, I'm very, very far from this process, so chances are I misunderstood this. Regarding the rest of your suggestions. It may be obvious to you, but could you spell out that ```auto view = View (array)``` is the usage you propose? I hear your warning regarding ```const``` of the type and the view. I hear your warning regarding const view (array).
Cites kometen · 2016-02 · Stack Overflow · on “Why I do not get errors when I initialize an array container with more elements than the size of the array?”
If you implement it using Microsoft's GSL span it will fail fast [this video] as promised by Neil Macintosh. So maybe not desirable in either case but with this approach the program terminates and indicates an issue worth investigating. array<int, 3> a; a[0] = 0; a[1] = 1; a[2] = 2; a[3] = 3; a[4] = 4; for (auto& i : a) { cout << i << endl; } gsl::span<int, 3> s = a; s[0] = 10; s[1] = 11; s[2] = 12; // s[3] = 13; for (auto& i : s) { cout << i << endl; } outputs 0 1 2 10 11 12 Uncommenting s[3] = 13 compiles but fails. 0 1 2 libc++abi.dylib: terminating zsh: abort ./gsl_span