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
Conversation
There was a problem hiding this 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.
source/numerics.tex
Outdated
\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, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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())}. |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Updated for "which" -> "that". |
There was a problem hiding this 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).
source/numerics.tex
Outdated
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}. |
There was a problem hiding this comment.
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
" ?
There was a problem hiding this comment.
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.")
source/numerics.tex
Outdated
\tcode{n}. | ||
\requires | ||
The number of values pointed to by \tcode{p} is | ||
equal to or greater than \tcode{n}. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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())}. |
There was a problem hiding this comment.
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} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, please.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
source/numerics.tex
Outdated
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. |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed \emph (twice).
source/numerics.tex
Outdated
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. |
There was a problem hiding this comment.
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
"
There was a problem hiding this comment.
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.)
There was a problem hiding this comment.
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);} |
There was a problem hiding this comment.
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.
I've updated the patch. |
@jensmaurer: rebase? |
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.) |
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! |
Partially addresses cplusplus#1071.
Rebased as requested. |
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.