Skip to content

Replace boilerplate for deciding iterator_category of a view adaptor's iterator #4692

Open
@jwakely

Description

@jwakely

Several iterator types for view adaptors have wording like this (from [range.filter.iterator]):

iterator::iterator_category is defined as follows:

  • Let C denote the type iterator_traits<iterator_t<V>>::iterator_category.
  • If C models derived_from<bidirectional_iterator_tag>, then iterator_category denotes bidirectional_iterator_tag.
  • Otherwise, if C models derived_from<forward_iterator_tag>, then iterator_category denotes forward_iterator_tag.
  • Otherwise, iterator_category denotes C.

We could avoid the repetition with an exposition-only helper along the lines of:

template<class C, class... Cats>
  struct floor-cat
 { using type = C; };
template<class C, class Cat, class... Cats>
  struct floor-cat
  : conditional<derived_from<C, Cat>, Cat, floor-cat<C, Cats...>>
 { };
template<class T, class... Cats>
  using floor-cat-t = typename floor-cat<T, Cats...>::type;

And then define iterator::iterator_category for the example above as floor-cat<iterator_traits<iterator_t<V>>::iterator_category, bidirectional_iterator_tag, forward_iterator_tag>.

Activity

added
lwgIssue must be reviewed by LWG.
on Jun 11, 2021
JohelEGP

JohelEGP commented on Sep 3, 2022

@JohelEGP
Contributor

Ping for the de-duplication train.

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

    lwgIssue must be reviewed by LWG.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @jwakely@JohelEGP

        Issue actions

          Replace boilerplate for deciding iterator_category of a view adaptor's iterator · Issue #4692 · cplusplus/draft