I wrote up an answer to this StackOverflow question which involved summing the integers along the diagonal of a matrix. Here's the relevant part:

```
// The sum of elements along the diagonal from top-right to bottom-left
func diagonal2Sum(_ input: [[Int]]) -> Int {
input.indices
.map { input[$0].reversed()[$0] } // Use the existing `reversed()` property to do the index math for us.
.reduce(0, +)
}
```

The goal was to circumvent the need to write `input[$0][input.count - $0 - 1]`

(which was the root cause of OP's question, they forgot the `- 1`

term), by instead having `reversed()`

do the work for us.

I suggested this under the misapprehension that subscript the `ReversedCollection`

returned by `Array.reversed()`

would just do some cheap index arithmetic in constant time. Surprise, I was dead wrong!

@mattneub opened a new question on that topic, and @itaiferber explained that that this is calling another overload of `reversed()`

, `Sequence.reversed()`

, which returns an array (with the full linear-time reversing that entails).

Is there something that could be done to standard library to allow it to identify collections whose indices have the property that the "`n`

th last index is just `count - n - 1`

", and to allow a constant time reversed view into the underlying collection?