Files
2025-10-25 03:02:53 +03:00

67 lines
2.3 KiB
Markdown
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

[valarray.access]
# 29 Numerics library [[numerics]](./#numerics)
## 29.6 Numeric arrays [[numarray]](numarray#valarray.access)
### 29.6.2 Class template valarray [[template.valarray]](template.valarray#valarray.access)
#### 29.6.2.4 Element access [valarray.access]
[🔗](#lib:operator%5b%5d,valarray)
`const T& operator[](size_t n) const;
T& operator[](size_t n);
`
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L7577)
*Hardened preconditions*: n < size() is true[.](#1.sentence-1)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L7581)
*Returns*: A reference to the corresponding element of the array[.](#2.sentence-1)
[*Note [1](#note-1)*:
The expression (a[i] = q, a[i]) == q evaluates to true for any non-constant valarray<T> a,
any T q, and for any size_t i such that the value of i is less than the length of a[.](#2.sentence-2)
— *end note*]
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L7591)
*Remarks*: The expression addressof(a[i + j]) == addressof(a[i]) + j evaluates to true for all size_t i and size_t j such that i + j < a.size()[.](#3.sentence-1)
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L7597)
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 j such that i < a.size() and j < b.size()[.](#4.sentence-1)
[*Note [2](#note-2)*:
This property indicates an absence of aliasing and can be used to
advantage by optimizing compilers[.](#4.sentence-2)
Compilers can take advantage
of inlining, constant propagation, loop fusion,
tracking of pointers obtained fromoperator new,
and other techniques to generate efficientvalarrays[.](#4.sentence-3)
— *end note*]
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L7614)
The reference returned by the subscript operator for an array shall
be valid until the member function[resize(size_t, T)](valarray.members#lib:valarray,resize "29.6.2.8Member functions[valarray.members]") is called for that array or until the lifetime of
that array ends, whichever happens first[.](#5.sentence-1)