<span>: checked iterators became too intolerant
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 11.2k
- Forks
- 1.7k
- Avg merge
- 4d 15h
- Merged PRs (30d)
- 22
Description
Describe the bug
Checked iterators controlled by _ITERATOR_DEBUG_LEVEL provide some safe guarantee, but these assertions became more and more intolerant for programming in normal styles.
Command-line test case
std::array<std::byte, 10> a{};
std::span<std::byte> s1 = a;
std::span<std::byte> s2 = s1.subspan(1);
std::cout << s2.begin() - s1.begin(); // assertion failed while _ITERATOR_DEBUG_LEVEL >= 1
Expected behavior
Both these two span s1 and s2 came from a, hence they share the same underlying sequence.
I think this design makes iterators of the same type pointing to the same element not equivalent. (may be an LWG issue?)
From a programmer’s point of view, the code snippet above is a common requirement, especially when parsing certain data.
STL version
Microsoft Visual Studio Community 2019
Version 16.7.7
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the command-line case with _ITERATOR_DEBUG_LEVEL >= 1, focusing on std::span::begin() and checked-iterator subtraction. The issue is done when this same-sequence operation no longer asserts, with behavior covered by a regression test; no file or test path is named in the report.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100