.\" ident @(#)gslice_array.3 .\" Standard Template Library .\" $$RW_INSERT_HEADER "slyrs.man" .TH gslice_array 3C++ "02 Apr 1998" "Rogue Wave Software" "-" .ce2 Standard C++ Library Copyright 1998, Rogue Wave Software, Inc. .SH NAME \f2gslice_array\fP \ - A numeric array class used to represent a BLAS-like slice from a valarray. .SH SYNOPSIS .br #include .br template .br class gslice_array ; .SH DESCRIPTION gslice_array creates a gslice view into a valarray. gslice_arrays are only produced by applying the gslice subscript operator to a valarray. The elements in a gslice_array are references to selected elements in the valarray (so changing an element in the gslice_array really changes the corresponding element in the valarray). A gslice_array does not itself hold any distinct elements. The template cannot be instantiated directly since all its constructors are private. However, you can copy a gslice_array to a valarray using either the valarray copy constructor or the assignment operator. Reference semantics are lost at that point. .SH INTERFACE .br template class gslice_array { .br public: .br .RE .RS 2 // types .RE .RS 1 typedef T value_type; .RE .RS 0 .RE .RS 2 // destructor .br ~gslice_array(); .RE .RS 0 .RE .RS 2 // public assignment .RE .RS 1 void operator= (const valarray& array) const; .RE .RS 2 // computed assignment .RE .RS 1 void operator*= (const valarray& array) const; .br void operator/= (const valarray& array) const; .br void operator%= (const valarray& array) const; .br void operator+= (const valarray& array) const; .br void operator-= (const valarray& array) const; .br void operator^= (const valarray& array) const; .br void operator&= (const valarray& array) const; .br void operator|= (const valarray& array) const; .br void operator<<= (const valarray& array) const; .br void operator>>= (const valarray& array) const; .br .RE .RS 2 // fill function .RE .RS 1 void operator=(const T&); .RE .RS 0 .br private: .RE .RS 2 // constructors .RE .RS 1 gslice_array(); .br gslice_array(const gslice_array&); .RE .RS 2 // operator = .RE .RS 1 gslice_array& operator= (const gslice_array& array); .RE .RS 0 }; .SH CONSTRUCTORS .br gslice_array(); .br gslice_array(const gslice_array&); .RE .RS 3 All gslice_array constructors are private and cannot be called directly. This prevents copy construction of gslice_arrays. .RE .SH ASSIGNMENT OPERATORS .br void operator=(const valarray& x) const; .RE .RS 3 Assigns values from \f2x \fPto the selected elements of the valarray that self refers to. Remember that a gslice_array never holds any elements itself; it simply refers to selected elements in the valarray used to generate it. .RE .br gslice_array& .br operator=(const gslice-_array& x); .RE .RS 3 Private assignment operator. Cannot be called directly, thus preventing assignment between gslice_arrays. .RE .SH COMPUTED ASSIGNMENT OPERATORS .br void operator*=(const valarray& val) const; .br void operator/=(const valarray& val) const; .br void operator%=(const valarray& val) const; .br void operator+=(const valarray& val) const; .br void operator-=(const valarray& val) const; .br void operator^=(const valarray& val) const; .br void operator&=(const valarray& val) const; .br void operator|=(const valarray& val) const; .br void operator<<=(const valarray& val) const; .br void operator>>=(const valarray& val) const; .RE .RS 3 Applies the indicated operation using elements from \f2val\fP to the selected elements of the valarray that self refers to. Remember that a gslice_array never holds any elements itself; it simply refers to selected elements in the valarray used to generate it. .RE .SH MEMBER FUNCTIONS .br void operator=(const T& x) const; .RE .RS 3 Assigns \f2x\fP to the selected elements of the valarray that self refers to. .RE .SH EXAMPLE .br // .br // gslice_array.cpp .br // .br #include "valarray.h" // Contains a valarray stream inserter .br using namespace std; .br .br int main(void) .br { .RE .RS 1 int ibuf[27] = .RE .RS 3 {0,1,2,3,4,5,6,7,8,1,2,3,4,5,6,7,8,9,2,3,4,5,6,7,8,9,10}; .RE .RS 1 int buf13[9] = {13,13,13,13,13,13,13,13,13}; .br size_t len_buf[3] = {3,3,3}; .br size_t stride_buf[3] = {9,3,1}; .RE .RS 0 .RE .RS 2 // create a valarray of ints .RE .RS 1 valarray vi(ibuf,27); .RE .RS 0 .RE .RS 2 // print out the valarray .RE .RS 1 cout << vi << endl; .RE .RS 0 .RE .RS 2 // Get a two dimensional diagonal slice out of the middle .RE .RS 1 valarray len2(2); .br len2[0] = 3; .br len2[1] = 3; .br valarray stride2(2); .br stride2[0] = 3; .br stride2[1] = 10; .br gslice_array gsl = vi[gslice(0,len2,stride2)]; .RE .RS 0 .RE .RS 2 // print out the slice .RE .RS 1 cout << gsl << endl; .RE .RS 0 .RE .RS 2 // Assign 13's to everything in the slice .RE .RS 1 gsl = valarray(buf13,9); .RE .RS 0 .RE .RS 2 // print out the slice and our original valarray .RE .RS 1 cout << gsl << endl << vi << endl; .RE .RS 0 .RE .RS 1 return 0; .RE .RS 0 } .br .RE .RS 0 Program Output .br .br [0,1,2,3,4,5,6,7,8,1,2,3,4,5,6,7,8,9,2,3,4,5,6,7,8,9,10] .br [0,2,4,3,5,7,6,8,10] .br [13,13,13,13,13,13,13,13,13] .br [13,1,2,13,4,5,13,7,8,1,13,3,4,13,6,7,13,9,2,3,13,5,6,13,8,9,13] .SH WARNINGS If your compiler does not support namespaces, then you do not need the using declaration for \f2std\fP. .SH SEE ALSO slice, valarray, gslice, slice_array, mask_array, indirect_array