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

std::mask_array

Defined in header <valarray>

?

?

template< class T > class mask_array;

?

?

std::mask_array是由valArray下标运算符带着std::valarray<bool>争论。它具有引用语义,并提供对由索引对应于true中的值。std::valarray<bool>面具。

成员类型

Type

Definition

value_type

T

成员函数

(constructor)

constructs a mask_array (public member function)

(destructor)

destroys a mask_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 mask. (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::cout << "Initial valarray: ";
    for(int n: data) std::cout << n << ' ';
    std::cout << '\n';
 
    data[data > 5] = -1;
    // the type of data>5 is std::valarray<bool>
    // the type of data[data>5] is std::mask_array<int>
 
    std::cout << "After v[v>5]=-1:  ";
    for(int n: data) std::cout << n << ' ';
    std::cout << '\n';
}

二次

产出:

二次

代码语言:javascript
复制
Initial valarray: 0 1 2 3 4 5 6 7 8 9 
After v[v>5]=-1:  0 1 2 3 4 5 -1 -1 -1 -1

二次

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

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

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com