Skip to content

dyn_array_iterator lacks the random access iterator operators it declares #1270

Closed

Description

@lenamonj

dyn_array_iterator declares iterator_category = std::random_access_iterator_tag but supplies none of operator<, operator>, operator<=, operator>=, operator-> or n + it, and its default constructor exists only when __cpp_lib_ranges is defined. Any algorithm that relies on the declared category fails to compile:

gsl::dyn_array<int> a{3, 1, 2};
std::sort(a.begin(), a.end());        // error: no match for operator<
bool b = a.begin() < a.end();          // same
gsl::dyn_array<int>::iterator it{};    // error before C++20

Reproduces on main (417ef68) with GCC 15 at C++14, 17 and 20 (the default constructor case at 14 and 17). A default constructor is part of the forward iterator requirements in every standard the library supports, and the relational operators, -> and n + it are part of the random access requirements.

Activity

  1. carsonRadtke commented on Sep 10, 2026

    @carsonRadtke
    Member

    Thanks for reporting this issue! This was definitely an oversight, and it prevents gsl::dyn_array from being turned into a std::span. I appreciate you putting up a PR to resolve the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type: BugIndicates a bug or error

    Type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions