[valarray.access] (original) (raw)
29 Numerics library [numerics]
29.6 Numeric arrays [numarray]
29.6.2 Class template valarray [template.valarray]
29.6.2.4 Element access [valarray.access]
const T& operator[](size_t n) const; T& operator[](size_t n);
Hardened preconditions: n < size() is true.
Returns: A reference to the corresponding element of the array.
[Note 1:
The expression (a[i] = q, a[i]) == qevaluates to true for any non-constant valarray<T> a, any T q, and for any size_t isuch that the value of i is less than the length of a.
— _end note_]
Remarks: The expression addressof(a[i+j]) == addressof(a[i]) + jevaluates to true for all size_t i and size_t jsuch that i+j < a.size().
The expression addressof(a[i]) != addressof(b[j])evaluates to true for any two arraysa and b and for anysize_t i and size_t jsuch that i < a.size()and j < b.size().
[Note 2:
This property indicates an absence of aliasing and can be used to advantage by optimizing compilers.
Compilers can take advantage of inlining, constant propagation, loop fusion, tracking of pointers obtained fromoperator new, and other techniques to generate efficientvalarrays.
— _end note_]
The reference returned by the subscript operator for an array shall be valid until the member functionresize(size_t, T) is called for that array or until the lifetime of that array ends, whichever happens first.