首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::indirect_array

Defined in header <valarray>

?

?

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)

二次

代码语言:javascript
复制
#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';
}

二次

产出:

二次

代码语言:javascript
复制
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

二次

代码语言:txt
复制
 ? cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com