forked from OSchip/llvm-project
Fix iterator_adaptor_base/enumerator_iter to allow composition of llvm::enumerate with llvm::make_filter_range
* Properly specify reference type in enumerator_iter * Fix constness of iterator_adaptor_base::operator* Differential Revision: https://reviews.llvm.org/D112981
This commit is contained in:
parent
ca0ed40e00
commit
ba7a6b314f
|
@ -1907,8 +1907,7 @@ class enumerator_iter
|
|||
: public iterator_facade_base<
|
||||
enumerator_iter<R>, std::forward_iterator_tag, result_pair<R>,
|
||||
typename std::iterator_traits<IterOfRange<R>>::difference_type,
|
||||
typename std::iterator_traits<IterOfRange<R>>::pointer,
|
||||
typename std::iterator_traits<IterOfRange<R>>::reference> {
|
||||
typename std::iterator_traits<IterOfRange<R>>::pointer> {
|
||||
using result_type = result_pair<R>;
|
||||
|
||||
public:
|
||||
|
|
|
@ -296,7 +296,8 @@ public:
|
|||
return LHS.I < RHS.I;
|
||||
}
|
||||
|
||||
ReferenceT operator*() const { return *I; }
|
||||
const ReferenceT operator*() const { return *I; }
|
||||
ReferenceT operator*() { return *I; }
|
||||
};
|
||||
|
||||
/// An iterator type that allows iterating over the pointees via some
|
||||
|
|
|
@ -178,6 +178,16 @@ TEST(FilterIteratorTest, Lambda) {
|
|||
EXPECT_EQ((SmallVector<int, 3>{1, 3, 5}), Actual);
|
||||
}
|
||||
|
||||
TEST(FilterIteratorTest, Enumerate) {
|
||||
auto IsOdd = [](auto N) { return N.value() % 2 == 1; };
|
||||
int A[] = {0, 1, 2, 3, 4, 5, 6};
|
||||
auto Enumerate = llvm::enumerate(A);
|
||||
SmallVector<int> Actual;
|
||||
for (auto IndexedValue : make_filter_range(Enumerate, IsOdd))
|
||||
Actual.push_back(IndexedValue.value());
|
||||
EXPECT_EQ((SmallVector<int, 3>{1, 3, 5}), Actual);
|
||||
}
|
||||
|
||||
TEST(FilterIteratorTest, CallableObject) {
|
||||
int Counter = 0;
|
||||
struct Callable {
|
||||
|
|
Loading…
Reference in New Issue