[PATCH] D144503: [ADT] Allow `llvm::enumerate` to enumerate over multiple ranges
Jakub Kuderski via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 7 08:11:59 PST 2023
kuhar added a comment.
In D144503#4174097 <https://reviews.llvm.org/D144503#4174097>, @dblaikie wrote:
>> Because the enumerate_result returned on dereference is a temporary, enumeration result can no longer be used through an lvalue ref.
>
> Is it valid to have a value-returning iterator? (what about op->, which needs a pointer returned?) I thought that wasn't valid for most iterator categories
This is already the case with other iterators returned from `zip`* functions -- their reference type is the same as value type (tuple of references). Other common iterators that return values that come to my mind are `SafeIntIterator` (from `llvm::seq` and `llvm::iota_range`), `vector<bool>::iterator` (reference wrapper). If I understand '[forward.iterators]' correctly, this seems fine as long as `reference` is *some* reference type convertible to the value type:
> — if X is a mutable iterator, reference is a reference to T; if X is a constant iterator, reference is a reference to const T,
> — the expressions in Table 97 are valid and have the indicated semantics, and
In table 97:
> Expression | Return type
> *r++ | reference
And in '[input.iterators]:
> A class or pointer type X satisfies the requirements of an input iterator for the value type T if X satisfies the
> Iterator (27.2.2) and EqualityComparable (Table 20) requirements and the expressions in Table 95 are
> valid and have the indicated semantics.
In table 95:
> Expression | Return type
> *a | reference, convertible to T
Right now, `enumerate` is returns only `forward_iterator`s, but we should be able to make it bidirectional and probably random in the future without having to change the iterator reference type (provided that all nested iterators have the required categories).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D144503/new/
https://reviews.llvm.org/D144503
More information about the llvm-commits
mailing list