Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::mask_array

      From cppreference.com
      <cpp‎ |numeric‎ |valarray
       
       
       
      std::valarray
      Member functions
      Non-member functions
      Helper classes
      mask_array
      Deduction guides(C++17)
       
       
      Defined in header<valarray>
      template<class T>class mask_array;

      std::mask_array is a helper template used by thevalarray subscript operator withstd::valarray<bool> argument. It has reference semantics and provides access to the subset of the valarray consisting of the elements whose indices correspond totrue values in thestd::valarray<bool> mask.

      Contents

      [edit]Member types

      Type Definition
      value_typeT

      [edit]Member functions

      constructs amask_array
      (public member function)[edit]
      destroys amask_array
      (public member function)[edit]
      assigns contents
      (public member function)[edit]
      performs arithmetic operation on the array referred by mask.
      (public member function)[edit]

      [edit]Example

      Run this code
      #include <iostream>#include <valarray> void println(auto rem,constauto& data){for(std::cout<< rem;int n: data)std::cout<< n<<' ';std::cout<<'\n';} int main(){std::valarray<int> data{0,1,2,3,4,5,6,7,8,9};     println("Initial valarray: ", data);     data[data>5]=-1;// the type of data>5 is std::valarray<bool>// the type of data[data>5] is std::mask_array<int>     println("After v[v>5]=-1:  ", data);}

      Output:

      Initial valarray: 0 1 2 3 4 5 6 7 8 9After v[v>5]=-1:  0 1 2 3 4 5 -1 -1 -1 -1

      [edit]See also

      convenience alias template forbasic_simd_mask that can specify its width
      (alias template)[edit]
      (parallelism TS v2)
      data-parallel type with the element type bool
      (class template)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/numeric/valarray/mask_array&oldid=178690"

      [8]ページ先頭

      ©2009-2025 Movatter.jp