Skip to content
This repository has been archived by the owner on Jan 19, 2024. It is now read-only.

Commit

Permalink
Add alias for const_iterator
Browse files Browse the repository at this point in the history
Older generic code (e.g. before auto) might require
const_iterator, so provide it as an alias to iterator.
  • Loading branch information
clechasseur committed Nov 21, 2017
1 parent 46982ee commit eaab580
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/coveo/enumerable/enumerable.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ class enumerable
// Forward declaration of iterator class.
class iterator;

// Even though begin() and end() are already const, some might want
// to use const_iterator, to let's create an alias.
typedef iterator const_iterator;

private:
next_delegate zero_; // Next delegate which we will clone to iterate sequence.
size_delegate size_; // Optional size delegate.
Expand Down Expand Up @@ -105,9 +109,16 @@ class enumerable
iterator begin() const {
return iterator(*this, false);
}
iterator cbegin() const {
return begin();
}

iterator end() const {
return iterator(*this, true);
}
iterator cend() const {
return end();
}

// Access to size of sequence
bool has_fast_size() const {
Expand Down
6 changes: 6 additions & 0 deletions tests/coveo/enumerable/enumerable_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ void validate_sequence(const coveo::enumerable<T>& seq, const C& expected, bool
COVEO_ASSERT(obj == *eit++);
}
COVEO_ASSERT(eit == eend);
eit = std::begin(expected);
for (auto sit = seq.cbegin(), send = seq.cend(); sit != send; ++sit) {
COVEO_ASSERT(eit != eend);
COVEO_ASSERT(*sit == *eit++);
}
COVEO_ASSERT(eit == eend);
COVEO_ASSERT(seq.has_fast_size() == fast_size);
COVEO_ASSERT(seq.size() == expected.size());
}
Expand Down

0 comments on commit eaab580

Please sign in to comment.