Use the simpler RandomAccessIterator difference rather than std::distance.
Add some comments about time complexity.