Daily bit(e) of C++ | std::advance, std::distance
Daily bit(e) of C++ #256, Generic functions for advancing iterators and measuring distance between iterators: std::advance, std::distance.
When implementing generic code that should operate on top of ranges, the std::advance and std::distance utilities can help.
Both utilities provide constant complexity for random access ranges and fallback to linear operations.