Skip to content

dyn_array_iterator cannot convert to const_iterator #1269

Closed

Description

@lenamonj

dyn_array_iterator<T> declares operator dyn_array_iterator<const T>(), but the conversion builds the target through dyn_array_iterator<const T>'s private state constructor, and that specialization befriends only gsl::dyn_array. Every use of the conversion is an access error, so iterator never converts to const_iterator:

gsl::dyn_array<int> a{1, 2, 3};
gsl::dyn_array<int>::const_iterator it = a.begin();   // error: constructor is private
bool b = a.cend() == a.end();                          // same

Reproduces on main (417ef68) with GCC 15 at C++14, 17 and 20. gsl::span's span_iterator avoids this by befriending its own specializations (template <class> friend class span_iterator;).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions