Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::mask_array<T>::operator=

      From cppreference.com
      <cpp‎ |numeric‎ |valarray‎ |mask array

      [edit template]
       
       
       
      std::valarray
      Member functions
      Non-member functions
      Helper classes
      Deduction guides(C++17)
       
       
      void operator=(const T& value)const;
      (1)
      void operator=(conststd::valarray<T>& val_arr)const;
      (2)
      const mask_array& operator=(const mask_array& other_arr)const;
      (3)

      Assigns values to all referred elements.

      1) Assignsvalue to all of the elements.
      2) Assigns the elements ofval_arr to the referred to elements of*this.
      3) Assigns the selected elements fromother_arr to the referred to elements of*this.

      Contents

      [edit]Parameters

      value - a value to assign to all of the referred elements
      val_arr -std::valarray to assign
      other_arr -std::mask_array to assign

      [edit]Return value

      1,2) (none)
      3)*this

      [edit]Example

      Run this code
      #include <iomanip>#include <iostream>#include <valarray> void print(std::valarray<int>const& v){for(int e: v)std::cout<<std::setw(2)<< e<<' ';std::cout<<'\n';} int main(){constauto init={1,2,3,4,5,6,7,8};std::valarray<int> v;     v= init;    v[(v%2)==0]=0;// (1)    print(v);     v= init;    v[(v%2)==1]=std::valarray<int>{-1,-2,-3,-4};// (2)    print(v);     v= init;    v[(v%2)==0]= v[(v%2)==1];// (3)    print(v);}

      Output:

       1  0  3  0  5  0  7  0 -1  2 -2  4 -3  6 -4  8  1  1  3  3  5  5  7  7

      [edit]Defect reports

      The following behavior-changing defect reports were applied retroactively to previously published C++ standards.

      DRApplied toBehavior as publishedCorrect behavior
      LWG 123C++98overload (2) was non-constmade const
      LWG 253C++98the copy assignment operator was privatemade public
      LWG 621C++98the copy assignment operator was non-constmade const
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/numeric/valarray/mask_array/operator%3D&oldid=120734"

      [8]ページ先頭

      ©2009-2025 Movatter.jp