cplusplus / cplusplus/draft

[alg.random.shuffle] ranges::shuffle - "exactly" or "at most" for number of swaps?

Open
#5,636 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TeX
Stars
221
Forks
813
Avg merge
16h 4m
Merged PRs (30d)
36

Description

In [alg.random.shuffle] section, for ranges::shuffle, the standard states that the complexity is exactly (last - first) - 1) swaps. In some other algorithms, the wording of at most for the number of swaps is used.

Should we change the wording for ranges::shuffle to say at most instead of exactly for the number of swaps? It would be nice for a standard library implementation to perform fewer swaps than required where possible and still be conforming. If not, can someone provide clarity on why there must be exactly this number of swaps in all cases?

This came up during discussion in the libc++ implementation of ranges::shuffle here

Contributor guide

No contributing guide indexed for this repository

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

Start with the [alg.random.shuffle] section and review the linked libc++ discussion in D130321. Compare the standard's use of “exactly” with “at most” in other algorithms, then determine whether the wording should change or whether the required swap count needs clarification. Done means recording a resolved standards decision.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
documentation
Issue type
Documentation
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.