Title
non-const copy assignment operators of helper arrays
Status
cd1
Section
[numarray]
Submitter
Martin Sebor

Created on 2007-01-20.00:00:00 last changed 164 months ago

Messages

Date: 2010-10-21.18:28:33

Proposed resolution:

Declare the copy assignment operators of all four helper array class templates const.

Specifically, make the following edits:

Change the signature in [template.slice.array] and [slice.arr.assign] as follows:


const slice_array& operator= (const slice_array&) const;

        

Change the signature in [template.gslice.array] and [gslice.array.assign] as follows:


const gslice_array& operator= (const gslice_array&) const;

        

Change the signature in [template.mask.array] and [mask.array.assign] as follows:


const mask_array& operator= (const mask_array&) const;

        

Change the signature in [template.indirect.array] and [indirect.array.assign] as follows:


const indirect_array& operator= (const indirect_array&) const;

        
Date: 2007-01-20.00:00:00

The computed and "fill" assignment operators of valarray helper array class templates (slice_array, gslice_array, mask_array, and indirect_array) are const member functions of each class template (the latter by the resolution of 123 since they have reference semantics and thus do not affect the state of the object on which they are called. However, the copy assignment operators of these class templates, which also have reference semantics, are non-const. The absence of constness opens the door to speculation about whether they really are intended to have reference semantics (existing implementations vary widely).

Pre-Kona, Martin adds:

I realized that adding the const qualifier to the functions as I suggested would break the const correctness of the classes. A few possible solutions come to mind:

  1. Add the const qualifier to the return types of these functions.
  2. Change the return type of all the functions to void to match the signatures of all the other assignment operators these classes define.
  3. Prohibit the copy assignment of these classes by declaring the copy assignment operators private (as is done and documented by some implementations).
History
Date User Action Args
2010-10-21 18:28:33adminsetmessages: + msg3240
2007-01-20 00:00:00admincreate