Skip to content

<ranges>: filter_view/transform_view::_Iterator_base shadowing #1418

Description

filter_view and transform_view have nested _Iterator_base:

STL/stl/inc/ranges

Lines 853 to 864 in 2b4cf99

class filter_view : public _Cached_position_t<forward_range<_Vw>, _Vw, filter_view<_Vw, _Pr>> {
// clang-format on
private:
/* [[no_unique_address]] */ _Vw _Range{};
/* [[no_unique_address]] */ _Semiregular_box<_Pr> _Pred{};
template <class _Traits> // TRANSITION, LWG-3289
struct _Iterator_base {};
// clang-format off
template <class _Traits>
requires _Has_member_iterator_category<_Traits>
struct _Iterator_base<_Traits> {

STL/stl/inc/ranges

Lines 1130 to 1144 in 2b4cf99

class transform_view : public view_interface<transform_view<_Vw, _Fn>> {
// clang-format on
private:
/* [[no_unique_address]] */ _Vw _Range{};
/* [[no_unique_address]] */ _Semiregular_box<_Fn> _Fun{};
template <bool _Const>
class _Sentinel;
template <class _Traits, class _Base> // TRANSITION, LWG-3289
struct _Iterator_base {};
// clang-format off
template <class _Traits, class _Base>
requires _Has_member_iterator_category<_Traits>
struct _Iterator_base<_Traits, _Base> {

This shadows the STL-wide _Iterator_base (which is very important because it powers iterator debugging):

STL/stl/inc/xmemory

Lines 1234 to 1240 in 2b4cf99

#if _ITERATOR_DEBUG_LEVEL == 0
using _Container_base = _Container_base0;
using _Iterator_base = _Iterator_base0;
#else // _ITERATOR_DEBUG_LEVEL == 0
using _Container_base = _Container_base12;
using _Iterator_base = _Iterator_base12;
#endif // _ITERATOR_DEBUG_LEVEL == 0

I strongly believe that this shadowing is confusing and should be avoided by renaming the nested structs.

Activity

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

    enhancementSomething can be improvedfixedSomething works now, yay!rangesC++20/23 ranges

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions