Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

std::span is a trap, gsl::span should be used instead, unless one is willing to enable checked collections on the respective compiler.

As for the rest, the point stands regarding portable code across various C++ compilers.

I agree on the co-routines, while I know C# co-routines relatively well, and the C++/CX stuff that was used as inspiration for Microsoft's initial proposal, they are a bit of a mess, when key WG21 members also don't fully grasp how they have to be implemented, and we need two hour sessions on C++ conferences to go through "hello world" kind of implementations.



> std::span is a trap, gsl::span should be used instead

It's not a trap if you weren't expecting bounds checking.

> we need two hour sessions on C++ conferences to go through "hello world" kind of implementations.

After one hour it became clear to me I am going to stay away from that stuff until either it becomes much more usable (unlikely TBH) or someone forces me to use it...


std::span is no more a trap than the rest of C++'s standard library in that regard. Are you also eschewing std::vector and std::string? std::string_view, std::array?

I suppose C++26 brings std::span::at, although exceptions are a different can of worms.


Some errors are too late to fix, span was originally bounds checked when proposed.

Pre-C++98 compiler frameworks used bounds checking by default.

And yes, if I am calling the shots, bounds checking are enabled in release builds.

Never has been a problem other than performance cargo cult folks.

Thankfully governments are making this less of discussion.


> And yes, if I am calling the shots, bounds checking are enabled in release builds.

No disagreement there. But I'd prefer to turn it on across the board via compiler flag rather than pull in a special library for it and remember to use that library consistently. And if that's the case, I don't see std::span as any more problematic on this front than the rest of the standard library.

(Yes, I know, GSL isn't really a special library on Windows. But anywhere else, it is.)


>various C++ compilers

Which compilers? I'd bet there are compilers that are still stuck at c++98.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: