Skip to content

<span>: checked iterators became too intolerant #1435

@PragmaTwice

Description

@PragmaTwice

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    LWG issue neededA wording defect that should be submitted to LWG as a new issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions