[PyTorch] Allow const T& access to ListElementReference when possible (#83177)
`IValue` can provide const reference access to `Tensor`,
`std::string`, and `IValue`. Fixing this allows iterating over
`c10::List`s of these types without copies.
This was flagged on #67964 back in February; never found someone to
implement it so I just did it myself while going over my TODO list
after returning from vacation yesterday.
Note that we still need `ListElementReference::get()` because this
support does not work for `List<optional<Tensor>>`.
Differential Revision: [D38579022](https://our.internmc.facebook.com/intern/diff/D38579022/)
Pull Request resolved: https://github.com/pytorch/pytorch/pull/83177
Approved by: https://github.com/ezyang