Convert TensorIterator to use function_ref, a lightweight alternative to std::function. (#26592)
Summary:
function_ref is pulled over from LLVM. It is to callables what StringRef is to strings.
This allows it to be substantially lighter weight, particularly in code size. That comes
at the cost of not being usable in situations where the callable's lifetime is shorter
than the function_ref. This means it is suitable for callback-like scenarios, but not
for situations where the callable needs to be stored. In converting TensorIterator,
I only encountered one situation that required refactoring to comply with function_ref's
constraints.
In my local Release build, this reduces the size of libtorch by 4MB, from 70MB->66MB.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/26592
Differential Revision: D17516202
fbshipit-source-id: 267476891f767f4827a4d38149f70e5035c56c48