Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::slice_array<T>::operator=

      From cppreference.com
      <cpp‎ |numeric‎ |valarray‎ |slice 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 slice_array& operator=(const slice_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::slice_array to assign

      [edit]Return value

      1,2) (none)
      3)*this

      [edit]Example

      Run this code
      #include <iostream>#include <valarray> void print(charconst* remark,std::valarray<int>const& v={}){std::cout<< remark;if(v.size()!=0){std::cout<<':';for(int e: v)std::cout<<' '<< e;}std::cout<<'\n';} int main(){std::valarray<int> v1{1,2,3,4,5,6,7,8};std::slice_array<int> s1= v1[std::slice(1,4,2)];    print("v1", v1);    print("s1", s1);     print("\n(1) operator=( const T& )");    print("s1 = 42");    s1=42;// (1)    print("s1", s1);    print("v1", v1);     print("\n(2) operator=( const std::valarray<T>& )");std::valarray<int> v2{10,11,12,13,14,15};    print("v2", v2);    print("s1 = v2");    s1= v2;// (2)    print("s1", s1);    print("v1", v1);     print("\n(3) operator=( const slice_array& )");    v1={1,2,3,4,5,6,7,8};std::slice_array<int> s2= v1[std::slice(0,4,1)];std::slice_array<int> s3= v2[std::slice(1,4,1)];    print("v1", v1);    print("v2", v2);    print("s2", s2);    print("s3", s3);    print("s2 = s3");    s2= s3;// (3) Note: LHS and RHS must have same size.    print("s2", s2);    print("v1", v1);}

      Output:

      v1: 1 2 3 4 5 6 7 8s1: 2 4 6 8 (1) operator=( const T& )s1 = 42s1: 42 42 42 42v1: 1 42 3 42 5 42 7 42 (2) operator=( const std::valarray<T>& )v2: 10 11 12 13 14 15s1 = v2s1: 10 11 12 13v1: 1 10 3 11 5 12 7 13 (3) operator=( const slice_array& )v1: 1 2 3 4 5 6 7 8v2: 10 11 12 13 14 15s2: 1 2 3 4s3: 11 12 13 14s2 = s3s2: 11 12 13 14v1: 11 12 13 14 5 6 7 8

      [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/slice_array/operator%3D&oldid=120737"

      [8]ページ先頭

      ©2009-2025 Movatter.jp