# Safe Random Access Collection Element

**URL:** <https://forums.swift.org/t/safe-random-access-collection-element/36509>\
**Category:** Pitches\
**Created:** [May 15, 2020, 9:03am UTC](https://forums.swift.org/t/safe-random-access-collection-element/36509 "2020-05-15T09:03:35Z")\
**Posts on this page:** 1\
**Showing post:** 12

<div class="post-metadata">

**Author:** ![Jens](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/jens/32/12903_2.png) [@Jens](https://forums.swift.org/u/Jens)\
**Post date:** [May 15, 2020, 6:54pm UTC](https://forums.swift.org/t/safe-random-access-collection-element/36509/12 "2020-05-15T18:54:02Z")

</div>

This has already been mentioned but I think it's worth repeating: If this failable subscript should ever be added to the stdlib, the label cannot be "safe" or "checked", because that would be misleading and confusing, ie:

> [@Add accessor with bounds check to Array](https://forums.swift.org/t/add-accessor-with-bounds-check-to-array/16871/24):
>
> Both `arr[checked:]` and `arr[safe:]` imply that the existing unlabeled subscript is _unchecked_ and _unsafe_ , which is incorrect.
> 
> The existing unlabeled subscript is both _safe_ and _checked_ . It is _safe_ (in the sense Swift uses the word) because it _checks_ whether the given index is within bounds and traps otherwise.
> 
> An unsafe or unchecked version of the subscript would not do any bounds check (for efficiency I guess) and have undefined behavior for out of bounds indices.

* * *

I have never felt the need for this failable subscript myself, and have no strong opinion on whether it should be added or not.

---

_[View the full topic](https://forums.swift.org/t/safe-random-access-collection-element/36509)._
