77. Valarray operator[] const returning value

Section: [valarray.access] Status: Dup Submitter: Levente Farkas Opened: 1998-09-09 Last modified: 2016-01-28 10:19:27 UTC

Priority: Not Prioritized

View all other issues in [valarray.access].

View all issues with Dup status.

Duplicate of: 389



    T operator[] (size_t) const;

why not

    const T& operator[] (size_t) const;

as in vector ???

One can't copy even from a const valarray eg:

    memcpy(ptr, &v[0], v.size() * sizeof(double));

[I] find this bug in valarray is very difficult.


The LWG believes that the interface was deliberately designed that way. That is what valarray was designed to do; that's where the "value array" name comes from. LWG members further comment that "we don't want valarray to be a full STL container." [valarray.access] specifies properties that indicate "an absence of aliasing" for non-constant arrays; this allows optimizations, including special hardware optimizations, that are not otherwise possible.