Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Exactly n" for negative n #497

Closed
timsong-cpp opened this issue Jul 22, 2017 · 1 comment
Closed

"Exactly n" for negative n #497

timsong-cpp opened this issue Jul 22, 2017 · 1 comment

Comments

@timsong-cpp
Copy link
Contributor

copy_n and generate_n allow negative n values but then specify the complexity as "exactly n". fill_n handles this correctly.

@CaseyCarter
Copy link
Collaborator

CaseyCarter commented Jul 22, 2017

D4684 [structure.specifications]/1 specifies that:

The detailed specifications of each entity defined in Clauses 7–12 follow the conventions established by
ISO/IEC 14882:2014 §17.5.1.4.

N4140 [structure.specifications] para 6 and 7:

6 If the formulation of a complexity requirement calls for a negative number of operations, the actual requirement is zero operations.

7 Complexity requirements specified in the library clauses are upper bounds, and implementations that provide better complexity guarantees satisfy the requirements.

So the specifications of copy_n and generate_n are sensible, albeit confusing. I think we can clean them up editorially. (Actually looks at copy_n) Correction, we can clean up fill_n and generate_n editorially, copy_n is just plain broken.

Proposed Resolution

Change [alg.fill] as follows:

-2 Returns: fill returns last. fill_n returns first + n for non-negative values of n and first
-  for negative values.
+2 Returns: last, where last is first + max(n, 0) for fill_n.
-3 Complexity: Exactly last - first, n, or 0 assignments, respectively.
+3 Complexity: Exactly last - first assignments.

Change [alg.generate] as follows:

 2 Returns: last, where last is first + max(n, 0) for generate_n.
-3 Complexity: Exactly last - first or n evaluations of invoke(gen) and assignments,
-  respectively.
+3 Complexity: Exactly last - first evaluations of invoke(gen) and assignments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants