Closed Bug 1139993 Opened 9 years ago Closed 9 years ago

Add VectorBase::ConstRange that only gives out `const T&` entries

Categories

(Core :: MFBT, defect)

x86
macOS
defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla39
Tracking Status
firefox39 --- fixed

People

(Reporter: fitzgen, Assigned: fitzgen)

References

Details

Attachments

(1 file, 1 obsolete file)

VectorBase::Range gives out `T&`, but for cases where consumers shouldn't be able to modify entries, only read them, it doesn't provide any nice guarantees. We should have a VectorBase::ConstRange that only gives out `const T&` entries.

Is there a better (standard-ish for this type of thing?) name than ConstRange?
Comment on attachment 8573439 [details] [diff] [review]
Add VectorBase::ConstRange that gives out |const T&| entries

Review of attachment 8573439 [details] [diff] [review]:
-----------------------------------------------------------------

::: mfbt/Vector.h
@@ +492,5 @@
> +    {
> +      MOZ_ASSERT(aCur <= aEnd);
> +    }
> +
> +  public:

Either include ConstRange() {}, or (more likely) remove Range() {} from the class just above.

@@ +496,5 @@
> +  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; }

Why no popCopyFront?  Seems like it should be fine to include, it's not mutating any members, just making copies of them.
Attachment #8573439 - Flags: review?(jwalden+bmo) → review+
https://hg.mozilla.org/mozilla-central/rev/9da55484cc2d
Status: ASSIGNED → RESOLVED
Closed: 9 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla39
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: