Title
std::valarray move-assignment
Status
c++14
Section
[valarray.assign]
Submitter
Paolo Carlini

Created on 2011-05-05.00:00:00 last changed 130 months ago

Messages

Date: 2012-11-03.04:16:46

Proposed resolution:

This wording is relative to the FDIS.

In [valarray.assign] update as follows:

valarray<T>& operator=(valarray<T>&& v) noexcept;

3 Effects: *this obtains the value of v. If the length of v is not equal to the length of *this, resizes *this to make the two arrays the same length, as if by calling resize(v.size()), before performing the assignment.The value of v after the assignment is not specified.

4 Complexity: ConstantLinear.

Date: 2012-11-03.04:16:46

[ 2012, Portland: applied to WP ]

Date: 2012-11-03.04:16:46

[ 2012, Kona ]

Move to Ready.

Some discussion on the types supported by valarray concludes that the wording is trying to say something similar to the core wording for trivial types, but significantly predates it, and does allow for types with non-trivial destructors. Howard notes that the only reason for linear complexity, rather than constant, is to support types with non-trivial destructors.

AJM suggests replacing the word 'value' with 'state', but straw poll prefers moving forward with the current wording, 5 to 2.

Date: 2012-08-05.16:44:00

Yesterday I noticed that the language we have in the FDIS about std::valarray move assignment is inconsistent with the resolution of LWG 675. Indeed, we guarantee constant complexity (vs linear complexity). We also want it to be noexcept, that is more subtle, but again it's at variance with all the containers.

Also, even if we suppose that LWG 675 applies only to the containers proper, I don't think the current "as if by calling resize(v.size())" is internally consistent with the noexcept requirement.

So, what do we really want for std::valarray? Shall we maybe just strike or fix the as-if, consider it some sort of pasto from the copy-assignment text, thus keep the noexcept and constant complexity requirements (essentially the whole operation would boild down to a swap of POD data members). Or LWG 675 should be explicitly extended to std::valarray too? In that case both noexcept and constant complexity would go, I think, and the operation would boil down to the moral equivalent of clear() (which doesn't really exist in this case) + swap?

Howard: I agree the current wording is incorrect. The complexity should be linear in size() (not v.size()) because the first thing this operator needs to do is resize(0) (or clear() as you put it).

I think we can keep the noexcept.

As for proper wording, here's a first suggestion:

Effects: *this obtains the value of v. The value of v after the assignment is not specified.

Complexity: linear.

See also reflector discussion starting with c++std-lib-30690.

History
Date User Action Args
2014-02-20 13:20:35adminsetstatus: wp -> c++14
2012-11-03 04:16:46adminsetmessages: + msg6264
2012-11-03 04:16:46adminsetmessages: + msg6263
2012-10-25 12:46:45adminsetstatus: voting -> wp
2012-10-16 15:35:12adminsetstatus: ready -> voting
2012-02-12 18:36:43adminsetstatus: new -> ready
2011-11-21 23:58:03adminsetmessages: + msg5883
2011-05-05 00:00:00admincreate