Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jwakely opened this issue Jun 11, 2021 · 1 comment
Labels
lwg Issue must be reviewed by LWG.

Comments

@jwakely
Copy link
Member

jwakely commented Jun 11, 2021

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>.

@jwakely jwakely added the lwg Issue must be reviewed by LWG. label Jun 11, 2021
@JohelEGP
Copy link
Contributor

JohelEGP commented Sep 3, 2022

Ping for the de-duplication train.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lwg Issue must be reviewed by LWG.
Projects
None yet
Development

No branches or pull requests

2 participants