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.
Click to open in Compiler Explorer.
Leave a comment