microsoft / microsoft/STL

`<algorithm>`: Avoid extra range traversals from `ranges::next(iterator, sentinel)`

Open
#1,775 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

performance
Dominant language
C++
Stars
11.2k
Forks
1.7k
Avg merge
4d 15h
Merged PRs (30d)
22

Description

ranges::advance(iterator, sentinel) and consequently ranges::next(iterator, sentinel) are O(1) when sentinel can be assigned to iterator, or when iterator's type models random_access_iterator and sentinel and iterator's types together model sized_sentinel_for. Otherwise, these overloads of ranges::advance and ranges::next are O(N).

There are occurrences these expressions in the Ranges code that are fine/efficient when O(1), but not great when O(N). Audit and investigate if some of these could be improved by replacing an approach that needs the final iterator with one that is purely forward.

(<algorithm> is the primary offender, but this also applies to Ranges code in <xutility>, <memory>, and possibly <xmemory>.)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Search the Ranges implementations in first, then audit corresponding uses in , , and possibly . Review each ranges::advance(iterator, sentinel) and ranges::next(iterator, sentinel) occurrence for avoidable O(N) traversal. Done means improving applicable cases with a forward-only approach while preserving existing behavior and validating the affected library tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
performance
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.