This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of Dup status.

77. Valarray operator[] const returning value

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

Priority: Not Prioritized

View all other issues in [valarray.access].

View all issues with Dup status.

Duplicate of: 389

Discussion:

valarray:

    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.

Rationale:

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." 28.6.2.4 [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.