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

[numarray] Add standard description elements. #1215

Merged
merged 1 commit into from Feb 6, 2017

Conversation

jensmaurer
Copy link
Member

Partially addresses #1071.

This is a first step. I've only inserted description elements such as \effects and \returns and removed boilerplate introductory phrases where appropriate.

@jensmaurer jensmaurer changed the title [valarray] Add standard description elements. [numarray] Add standard description elements. Dec 13, 2016
Copy link
Member

@zygoloid zygoloid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I definitely think this is an improvement, and from a cursory investigation it looks correct, but I've not checked that every wording change continues to convey the correct normative intent. I'd like @jwakely to review this for normative correctness before going forward.

\tcode{valarray<T>}\footnote{For convenience, such objects are referred
to as ``arrays'' throughout the
remainder of~\ref{numarray}.}
Constructs a \tcode{valarray}
which has zero length.\footnote{This default constructor is essential,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

which -> that (here and below), as this is a restrictive clause.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pre-existing text... Will do.

@@ -6874,7 +6874,7 @@

\begin{itemdescr}
\pnum
\effects Same as \tcode{valarray(il.begin(), il.size())}.
\effects Equivalent to \tcode{valarray(il.begin(), il.size())}.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have been reluctant to add "Equivalent to"s in the past, since "Equivalent to" also notionally populates the other elements of the description whereas "Same as" does not; see [structure.specifications]/4.

@jwakely Can you check that the change to "Equivalent to" here doesn't have an (unintended) normative effect?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we don't go for "Equivalent to", it seems we have a hole in the specification regarding exceptions etc. for this function.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It probably should have used "Equivalent to" when this was added for C++11, but it didn't, and adding it is normative and arguably not editorial. However, since the constructor it refers to currently has no elements, and after this change would only have Effects: (which we want to refer to) and Requires: (which is satisfied) I don't see any actual normative change that would be caused by using "Equivalent to" here.

@jensmaurer
Copy link
Member Author

Updated for "which" -> "that".

Copy link
Member

@jwakely jwakely left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes to "Equivalent to" don't seem to make any normative difference. The other changes are all good improvements (my comments are mostly for pre-existing problems).

The elements of the array are initialized with the value of the first argument.
\effects
Constructs a \tcode{valarray} that has length \tcode{n}.
The elements of the array are initialized with \tcode{v}.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this be clearer if it said "Each element of the array is initialized with v" ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, also in the signature before that ("Each element of the array is value-initialized.")

\tcode{n}.
\requires
The number of values pointed to by \tcode{p} is
equal to or greater than \tcode{n}.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems a bit clunky. The form used in Clause 21 is "p points to an array of at least n elements." Although I suppose "array" has been redefined to mean "valarray" in this subclause so that might not be an improvement.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could add a cross-reference to 8.3.4 [dcl.array] after this particular "array" to disambiguate. Done.

@@ -6874,7 +6874,7 @@

\begin{itemdescr}
\pnum
\effects Same as \tcode{valarray(il.begin(), il.size())}.
\effects Equivalent to \tcode{valarray(il.begin(), il.size())}.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It probably should have used "Equivalent to" when this was added for C++11, but it didn't, and adding it is normative and arguably not editorial. However, since the constructor it refers to currently has no elements, and after this change would only have Effects: (which we want to refer to) and Requires: (which is satisfied) I don't see any actual normative change that would be caused by using "Equivalent to" here.

This property indicates an absence of aliasing and may be used to
advantage by optimizing compilers.\footnote{Compilers may take advantage
\remarks
The expression \tcode{\&a[i+j] == \&a[i] + j}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to use addressof here, but that's a separate issue.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, please.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[numeric.defns] bullet 1.9 mean that we can ignore the usual concerns leading to addressof in this case, so I think there is no issue at all.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes, not the first time I've forgotten about that provision.

hand side, the behavior is undefined.
\remarks
The appearance of an array on the left-hand side of a compound assignment
does \emph{not} invalidate references or pointers.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we emphasising "not" here at all?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed \emph (twice).

Each of these operators
performs the indicated operation on each of its elements and the
corresponding element of the argument array.
to which the indicated operator can be applied.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to be more precise in these requirements? Being able to apply the operator doesn't mean much if we don't say what types the operands are. A type could overload T::operator*=(std::string) but that doesn't mean we can use valarray<T>{} *= T{}.

Maybe something like "For each operator function, the operator that it implements is invocable with two operands of type T"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to point out that this is pre-existing text; and I think LWG failed in distant history to produce a specification for std::complex that would allow T's other than built-in floating-point types. I'm reluctant to attempt to come up with a better specification here. (Although I admit the std::complex case was probably more about trigonometric functions thatn simple stuff.)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added a slight rewording, highlighting the "two operands" issue.


\pnum
\returns \tcode{*this}.
\effects Equivalent to: \tcode{return *this = valarray(il);}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any negative effect from using "Equivalent to" here either, although it's again arguably not editorial.

@jensmaurer
Copy link
Member Author

I've updated the patch.

@jensmaurer jensmaurer assigned zygoloid and unassigned jwakely Jan 10, 2017
@jensmaurer
Copy link
Member Author

@zygoloid: Back in your front yard; @jwakely has approved the change.

@tkoeppe
Copy link
Contributor

tkoeppe commented Feb 4, 2017

@jensmaurer: rebase?

@zygoloid
Copy link
Member

zygoloid commented Feb 5, 2017

Jens, can you rebase this please? (I'm also waiting on Marshall to confirm that we're OK to do this without further LWG signoff.)

@mclow
Copy link
Contributor

mclow commented Feb 5, 2017

This looks good to me. The only place I had a concern was around (replaced) link 7266, but after a re-read I'm good with that, too. Thanks, Jens!

@jensmaurer
Copy link
Member Author

Rebased as requested.

@zygoloid zygoloid merged commit b79c419 into cplusplus:master Feb 6, 2017
@jensmaurer jensmaurer deleted the b16 branch February 6, 2017 09:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants