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

[std.iterator.tags] Reword iterator tag description #6840

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Eisenwave
Copy link
Contributor

Related to #5641.

This section has a few issues:

  1. It contains wording "so that the function can select". This doesn't make much sense, since a function simply exists and never selects in itself. The intent is presumably that a function call selects the most efficient algorithm. That's how tag dispatch works anyway.

  2. The wording contains "compile time", which isn't a concept that really exists in C++. It is better to talk about overload resolution.

@jwakely
Copy link
Member

jwakely commented Mar 1, 2024

I disagree with the first point. A function such as std::distance can indeed select the best algorithm, by making a function call using the tag. That is, distance(a, b) calls distance_impl(a, b, cat(a)). Or maybe it instead does:

if constexpr (derived_from<cat_t<decltype(a)>, random_access_iterator_tag>)
  return b - a;

This selects the optimal implementation without a function call.

@Eisenwave
Copy link
Contributor Author

Hmm, I guess you could view it that way as well. The way I see it, it still wouldn't be that the function selects the algorithm per-se, but the if constexpr block would end up calling the desired function directly by discarding all other options.

In practical terms, I'd also call if constexpr a form of "implementation selection" though. Perhaps the first part can be reverted and we can keep just 2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants