std::span
Hacker ApprovedArray view in Developer tools
Lets people keep a buffer pointer and its length together, reducing size mistakes, and is available in C++20. Common caveat: it is not bounds checked.
Lets people keep a buffer pointer and its length together, reducing size mistakes, and is available in C++20. Common caveat: it is not bounds checked.
21 people gave an opinion
- recommend it
- 15
- criticize it
- 6
- approval share
- 71%
Recommended in 4 of 13 months
- November 2025: recommended
- December 2025: recommended
- January 2026: not recommended
- February 2026: not recommended
- March 2026: not recommended
- April 2026: not recommended
- May 2026: recommended
- June 2026: recommended
- July 2026: not recommended
- August 2026: not recommended
- September 2026: not recommended
- October 2026: not recommended
- November 2026: not recommended (month in progress)
Why it carries the badge
- 15 people recommend itNeeds 10 or more, met.
- 2.5 recommenders for every criticNeeds 2 to 1 or better, met.
- Recommended in 4 of 13 monthsNeeds 4 or more, met.
The same three rules apply to every product, and the badge can’t be bought. How the badge works
What people say about it
The reasons people give, with the number of comments that give each one. Open a reason to read what they said.
Why people recommend it
Each mark is one comment
Keeps pointer and length together
“C++'s std::span was very convenient for fixing the issue by letting the buffer pointer and length be kept together”
Comment from 4 Nov 2025 in “This week in 1988, Robert Morris unleashed his eponymous worm” “It bind both value together and guarantee that you do not mess with the size of your buffer.”
Comment from 9 Jun 2026 in “The beauty and simplicity of the good old C-style void* in C++” “what you gain with span, in that the pointer and the length are joined together”
Comment from 9 Jun 2026 in “The beauty and simplicity of the good old C-style void* in C++” - Comment from 10 Jun 2026 in “The beauty and simplicity of the good old C-style void* in C++”
Recommended for new C++20 projects
“I now use it consistently in all new projects where I can afford to mandate C++20.”
Comment from 9 Jun 2026 in “The beauty and simplicity of the good old C-style void* in C++” “I use std::span and std::expected in every project I can”
Comment from 15 Nov 2025 in “Rust in Android: move fast and fix things” “Just use compiler option -std=c++20 and use std::span.”
Comment from 2 May 2026 in “Lib0xc: A set of C standard library-adjacent APIs for safer systems programming” Preferred over raw pointers
“That's why C++ Core Guidelines recommend to use std::span.”
Comment from 10 Jun 2026 in “The beauty and simplicity of the good old C-style void* in C++” “std::string_view or std::span should be used instead”
Comment from 25 May 2026 in “C constructs that still don't work in C++”
What people warn about
Each mark is one comment
Not bounds checked, seen as dangerous
“a type which was standardized to be pointlessly dangerous”
Comment from 10 Oct 2026 in “`123456' password used in Danish CPR data breach” “std span is not bounds checked.”
Comment from 2 May 2026 in “Lib0xc: A set of C standard library-adjacent APIs for safer systems programming” Slows builds and performance on MSVC
“Sadly the MSVC ABI makes std::span and std::string_view a pessimisation”
Comment from 9 Jun 2026 in “The beauty and simplicity of the good old C-style void* in C++” “Span will increase compilation time for no useful reason.”
Comment from 9 Jun 2026 in “The beauty and simplicity of the good old C-style void* in C++”
What people said
23 of the 24 comments that mention it, newest first. Each links to the original comment.
“a type which was standardized to be pointlessly dangerous”
“but not for std::span (until C++26) for reasons I cannot understand”
“tying the pointer and length together reduces chances for variable confusion”
“That's why C++ Core Guidelines recommend to use std::span.”
“Span lets you use a ranged for loop to iterate over the contents without worrying about exceeding the bounds”
“Span will increase compilation time for no useful reason.”
“it doesn't make the feature itself bad”
“is such a life saver in these situations”
“It bind both value together and guarantee that you do not mess with the size of your buffer.”
“Sadly the MSVC ABI makes std::span and std::string_view a pessimisation”
“For me, a bag of bytes is `std::span`.”
“std::span solves two problems here.”
“I agree with you about std::span”
“I now use it consistently in all new projects where I can afford to mandate C++20.”
“what you gain with span, in that the pointer and the length are joined together”
“A truly zero-cost abstraction which effectively saves you from a lot of troubles.”
“std::string_view or std::span should be used instead”
“std span is not bounds checked.”
“Just use compiler option -std=c++20 and use std::span.”
“I'm sure std::span is great, but I like mine better :)”
“In these applications, size and T are fixed”
“I use std::span and std::expected in every project I can”
“C++'s std::span was very convenient for fixing the issue by letting the buffer pointer and length be kept together”
Counts come from 1,795,640 Hacker News comments, November 2025 to November 2026. How we count. Report a mistake.