Demonstrate gslice() in valarray : Valarray « Data Structure « C++






Demonstrate gslice() in valarray

Demonstrate gslice() in valarray

#include <iostream>
#include <valarray>
using namespace std;

int main()
{
  valarray<int> valarrayObject(12), result;
  valarray<size_t> len(2), interval(2);
  unsigned int i;

  for(i = 0; i < 12; i++) 
     valarrayObject[ i ] = i;

  len[0] = 3; 
  len[1] = 3;
  interval[0] = 2; 
  interval[1] = 3;

  cout << "Contents of valarrayObject: ";
  for(i = 0; i <12; i++)
    cout << valarrayObject[i] << " "; 
  cout << endl;

  result = valarrayObject[gslice(0,len,interval)];

  cout << "Contents of result: ";
  for(i = 0; i < result.size(); i++)
    cout << result[i] << " "; 

  return 0;
}


           
       








Related examples in the same category

1.Demonstrate valarray: assign value, Demonstrate valarray: assign value,
2.Demonstrate sliceDemonstrate slice