std::indirect_array
性病::间接[医]列阵
Defined in header | | |
---|---|---|
template< class T > class indirect_array; | | |
std::gslice_array是由std::indirect_array下标运算符。它具有对间接数组%28指定的数组子集的引用语义。std::valarray<std::size_t>对象%29。
成员类型
Type | Definition |
---|---|
value_type | T |
成员函数
(constructor) | constructs a indirect_array (public member function) |
---|---|
(destructor) | destroys a indirect_array (public member function) |
operator= | assigns contents (public member function) |
operator+=operator-=operator*=operator/=operator%=operator&=operator|=operator^=operator<<=operator>>= | performs arithmetic operation on the array referred by indirect array. (public member function) |
例
二次
#include <iostream>
#include <valarray>
int main()
{
std::valarray<int> data = {0,1,2,3,4,5,6,7,8,9};
std::valarray<std::size_t> idx = {0,2,4,6,8};
std::cout << "Original valarray: ";
for(int n: data) std::cout << n << ' ';
std::cout << '\n';
data[idx] += data[idx]; // double the values at indexes 'idx'
// the type of data[idx] is std::indirect_array<int>
std::cout << "After indirect modification: ";
for(int n: data) std::cout << n << ' ';
std::cout << '\n';
}
二次
产出:
二次
Original valarray: 0 1 2 3 4 5 6 7 8 9
After indirect modification: 0 1 4 3 8 5 12 7 16 9
二次
© cppreference.com
在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。