mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1139993 - Add VectorBase::ConstRange that gives out |const T&| entries. r=Waldo
This commit is contained in:
parent
eab815bb2e
commit
c2d50838e1
@ -473,7 +473,6 @@ public:
|
||||
}
|
||||
|
||||
public:
|
||||
Range() {}
|
||||
bool empty() const { return mCur == mEnd; }
|
||||
size_t remain() const { return PointerRangeSize(mCur, mEnd); }
|
||||
T& front() const { MOZ_ASSERT(!empty()); return *mCur; }
|
||||
@ -481,7 +480,28 @@ public:
|
||||
T popCopyFront() { MOZ_ASSERT(!empty()); return *mCur++; }
|
||||
};
|
||||
|
||||
class ConstRange
|
||||
{
|
||||
friend class VectorBase;
|
||||
const T* mCur;
|
||||
const T* mEnd;
|
||||
ConstRange(const T* aCur, const T* aEnd)
|
||||
: mCur(aCur)
|
||||
, mEnd(aEnd)
|
||||
{
|
||||
MOZ_ASSERT(aCur <= aEnd);
|
||||
}
|
||||
|
||||
public:
|
||||
bool empty() const { return mCur == mEnd; }
|
||||
size_t remain() const { return PointerRangeSize(mCur, mEnd); }
|
||||
const T& front() const { MOZ_ASSERT(!empty()); return *mCur; }
|
||||
void popFront() { MOZ_ASSERT(!empty()); ++mCur; }
|
||||
T popCopyFront() { MOZ_ASSERT(!empty()); return *mCur++; }
|
||||
};
|
||||
|
||||
Range all() { return Range(begin(), end()); }
|
||||
ConstRange all() const { return ConstRange(begin(), end()); }
|
||||
|
||||
/* mutators */
|
||||
|
||||
|
@ -14,6 +14,7 @@ using mozilla::Vector;
|
||||
struct mozilla::detail::VectorTesting
|
||||
{
|
||||
static void testReserved();
|
||||
static void testConstRange();
|
||||
};
|
||||
|
||||
void
|
||||
@ -75,8 +76,31 @@ mozilla::detail::VectorTesting::testReserved()
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
mozilla::detail::VectorTesting::testConstRange()
|
||||
{
|
||||
#ifdef DEBUG
|
||||
Vector<int> vec;
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
MOZ_RELEASE_ASSERT(vec.append(i));
|
||||
}
|
||||
|
||||
const auto &vecRef = vec;
|
||||
|
||||
Vector<int>::ConstRange range = vecRef.all();
|
||||
for (int i = 0; i < 10; i++) {
|
||||
MOZ_RELEASE_ASSERT(!range.empty());
|
||||
MOZ_RELEASE_ASSERT(range.front() == i);
|
||||
range.popFront();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
VectorTesting::testReserved();
|
||||
VectorTesting::testConstRange();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user