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

116 lines
5.0 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.

[template.indirect.array]
# 29 Numerics library [[numerics]](./#numerics)
## 29.6 Numeric arrays [[numarray]](numarray#template.indirect.array)
### 29.6.9 Class template indirect_array [template.indirect.array]
#### [29.6.9.1](#overview) Overview [[template.indirect.array.overview]](template.indirect.array.overview)
[🔗](#lib:indirect_array)
namespace std {template<class T> class indirect_array {public:using value_type = T; void operator= (const valarray<T>&) const; void operator*= (const valarray<T>&) const; void operator/= (const valarray<T>&) const; void operator%= (const valarray<T>&) const; void operator+= (const valarray<T>&) const; void operator-= (const valarray<T>&) const; void operator^= (const valarray<T>&) const; void operator&= (const valarray<T>&) const; void operator|= (const valarray<T>&) const; void operator<<=(const valarray<T>&) const; void operator>>=(const valarray<T>&) const;
indirect_array(const indirect_array&); ~indirect_array(); const indirect_array& operator=(const indirect_array&) const; void operator=(const T&) const;
indirect_array() = delete; // as implied by declaring copy constructor above};}
[1](#overview-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L9029)
This template is a helper template used by the indirect subscript operator
[🔗](#lib:operator%5b%5d,indirect_array)
`indirect_array<T> valarray<T>::operator[](const valarray<size_t>&);
`
[2](#overview-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L9036)
It has reference semantics to a subset of an array specified by anindirect_array[.](#overview-2.sentence-1)
Thus, the expressiona[indirect] = b; has the effect of assigning the elements ofb to the elements ina whose indices appear inindirect[.](#overview-2.sentence-2)
#### [29.6.9.2](#indirect.array.assign) Assignment [[indirect.array.assign]](indirect.array.assign)
[🔗](#lib:operator=,indirect_array)
`void operator=(const valarray<T>&) const;
const indirect_array& operator=(const indirect_array&) const;
`
[1](#indirect.array.assign-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L9057)
These assignment operators have reference semantics, assigning the values
of the argument array elements to selected elements of thevalarray<T> object to which it refers[.](#indirect.array.assign-1.sentence-1)
[2](#indirect.array.assign-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L9063)
If theindirect_array specifies an element in thevalarray<T> object to which it refers more than once, the behavior is undefined[.](#indirect.array.assign-2.sentence-1)
[3](#indirect.array.assign-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L9071)
[*Example [1](#indirect.array.assign-example-1)*:
int addr[] = {2, 3, 1, 4, 4};
valarray<size_t> indirect(addr, 5);
valarray<double> a(0., 10), b(1., 5);
a[indirect] = b; results in undefined behavior since element 4 is specified twice in the
indirection[.](#indirect.array.assign-3.sentence-1)
— *end example*]
#### [29.6.9.3](#indirect.array.comp.assign) Compound assignment [[indirect.array.comp.assign]](indirect.array.comp.assign)
[🔗](#lib:operator*=,indirect_array)
`void operator*= (const valarray<T>&) const;
void operator/= (const valarray<T>&) const;
void operator%= (const valarray<T>&) const;
void operator+= (const valarray<T>&) const;
void operator-= (const valarray<T>&) const;
void operator^= (const valarray<T>&) const;
void operator&= (const valarray<T>&) const;
void operator|= (const valarray<T>&) const;
void operator<<=(const valarray<T>&) const;
void operator>>=(const valarray<T>&) const;
`
[1](#indirect.array.comp.assign-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L9110)
These compound assignments have reference semantics, applying the indicated
operation to the elements of the argument array and selected elements of thevalarray<T> object to which theindirect_array object refers[.](#indirect.array.comp.assign-1.sentence-1)
[2](#indirect.array.comp.assign-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L9118)
If theindirect_array specifies an element in thevalarray<T> object to which it refers more than once,
the behavior is undefined[.](#indirect.array.comp.assign-2.sentence-1)
#### [29.6.9.4](#indirect.array.fill) Fill function [[indirect.array.fill]](indirect.array.fill)
[🔗](#lib:operator=,indirect_array_)
`void operator=(const T&) const;
`
[1](#indirect.array.fill-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L9136)
This function has reference semantics, assigning the value of its argument
to the elements of thevalarray<T> object to which theindirect_array object refers[.](#indirect.array.fill-1.sentence-1)