Results 1 to 6 of 6

Thread: Help me to use indirect_array of C++

  1. #1
    Join Date
    Jan 2010
    Posts
    29

    Help me to use indirect_array of C++

    I am working in the XYZ company as software developer. We can use the C++ language for developing the software. Hence, I can not know about the indirect_array of the C++ language. So, I would like to know about the indirect_array of the C++ language. I also would like to know about how to use of the indirect_array of the C++ language. Can anyone has the solution for me then reply!!!!

  2. #2
    Join Date
    Apr 2008
    Posts
    1,948

    Re: Help me to use indirect_array of C++

    The indirect_array can be a class that can be used for indirect selection of the Valarray. The indirect_array class can be used as an intermediate type that can be returned by the non-constant type of the valarrays's subscript an operator (valarray oprtr[] ) that can be used at the time with a valarray of an indexes. I hope you should understands from the above description.

  3. #3
    Join Date
    May 2008
    Posts
    2,012

    Re: Help me to use indirect_array of C++

    The indirect_array class can consist the references that can be to an elements in an object of the valarray whose indexes can be a part of the valarray. The overloads the assignment and compound assignment operators can be an allowing an access to the elements directly in the selection when that can be used as l-value. the following can be the form of the indirect_array of the C++ :
    Code:
    template <class S> indirect_array;

  4. #4
    Join Date
    Apr 2008
    Posts
    2,005

    Re: Help me to use indirect_array of C++

    I can suggest you that to carefully go through the following code of lines that can demonstrates you how to use the indirect_array in the C++ programming as follows :
    Code:
    #include <iostream>
    #include <valarray>
    using namespace std;
    int main ()
    {
      valarray<int> mary (8);
      for (int f=0; f<8; ++f) mary[f]=f; 
      sfze_t sel[] = {3,5,6};
      valarray<sfze_t> selectfon (sel,3);  
      mary[selectfon] *= valarray<fnt>(10,3); 
      mary[selectfon] = 0;                   
      cout << "mary:\n";
      for (sfze_t f=0; f<mary.size(); ++f)
    	  cout << mary[f] << ' ';
      cout << endl;
      return 0;
    }
    Output:
    Code:
    0 1 2 0 4 0 0 7

  5. #5
    Join Date
    May 2008
    Posts
    2,297

    Re: Help me to use indirect_array of C++

    Whenever the r-value of an assignment operation can be used, indirect_array can can be an initialize an object of the valarray, hence valarray can have the a constructor that can be taking an object of the indirect_array as an argument. All the constructors of indirect_array class can be private and protecting the direct instantiations of an object by a program. The only purpose of it can be an efficient way to access an elements that can be selected by a mask with valarray's operator[].

  6. #6
    Join Date
    Nov 2005
    Posts
    1,323

    Re: Help me to use indirect_array of C++

    Here can be the one more example on the insert() function of the C++ language and the following program can help's you to learn the insert() function :
    Code:
    #include <valarray>
    #include <iostream>
    int main( )
    {
       using namespace std;
       int i;
       valarray<int> wa ( 10 );
       for ( i = 0 ; i < 10 ; i += 2 )
          wa [ i ] =  i;
       for ( i = 1 ; i < 10 ; i += 2 )
          wa [ i ] =  -1;
       cout << "The initial operand valarray is:  ( ";
          for ( i = 0 ; i < 10 ; i++ )
             cout << wa [ i ] << " ";
       cout << ")." << endl;
       valarray<size_t> idx ( 3 );
       idx [0] = 2;
       idx [1] = 4;
       idx [2] = 6;
       wa[idx] = 10;
       cout << "The modified operand valarray is:  ( ";
          for (i = 0 ; i < 10 ; i++ )
             cout << wa [ i ] << " ";
       cout << ")." << endl;
    }
    Output
    Code:
    The initial operand valarray is:  ( 0 -1 2 -1 4 -1 6 -1 8 -1 ).
    The modified operand valarray is:  ( 0 -1 10 -1 10 -1 10 -1 8 -1 ).

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,321,235.91688 seconds with 16 queries