.\" ident @(#)slice_array.3 .\" Standard Template Library .\" $$RW_INSERT_HEADER "slyrs.man" .TH slice_array 3C++ "02 Apr 1998" "Rogue Wave Software" "-" .ce2 Standard C++ Library Copyright 1998, Rogue Wave Software, Inc. .SH NAME \f2slice_array\fP \ - A numeric array class for representing a BLAS-like slice from a valarray. .SH SYNOPSIS .br #include .br template .br class slice_array ; .SH DESCRIPTION slice_array gives a slice view into a valarray. Slice_arrays are only produced by applying the slice subscript operator to a valarray. The elements in a slice_array are references to selected elements in the valarray (so changing an element in the slice_array really changes the corresponding element in the valarray). A slice_array does not itself hold any distinct elements. The template cannot be instantiated directly since all its constructors are private. However, you can easily copy a slice_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 slice_array { .br public: .br .RE .RS 2 // types .RE .RS 1 typedef T value_type; .RE .RS 0 .RE .RS 2 // destructor .br ~slice_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 // other .RE .RS 1 void operator= (const T&); .RE .RS 0 .br private: .RE .RS 2 // constructors .RE .RS 1 slice_array(); .br slice_array(const slice_array&); .RE .RS 2 // operator = .RE .RS 1 slice_array& operator= (const slice_array& array); .RE .RS 0 }; .SH CONSTRUCTORS .br slice_array(); .br slice_array(const slice_array&); .RE .RS 3 All slice_array constructors are private and cannot be called directly. This prevents copy construction of slice_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 slice_array never holds any elements itself, it simply refers to selected elements in the valarray used to generate it. .RE .br slice_array& .br operator=(const slice-_array& x); .RE .RS 3 Private assignment operator. Cannot be called directly, thus preventing assignment between slice_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 slice_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); .RE .RS 3 Assigns \f2x\fP to the selected elements of the valarray that self refers to. .RE .SH EXAMPLE .br // .br // slice_array.cpp .br // .br #include "valarray.h" // Contains a valarray .RE .RS 23 // stream inserter .RE .RS 0 using namespace std; .br .br int main(void) .br { .RE .RS 1 int ibuf[10] = {0,1,2,3,4,5,6,7,8,9}; .br int ibuf2[5] = {1,3,5,7,9}; .RE .RS 0 .RE .RS 2 // create a valarray of ints .RE .RS 1 valarray vi(ibuf,10); .br valarray vi2(ibuf2,5); .RE .RS 0 .RE .RS 2 // print it out .RE .RS 1 cout << vi << endl << vi2 << endl; .RE .RS 0 .RE .RS 2 // Get a slice and assign that slice to another array .RE .RS 1 slice_array sl = vi[slice(1,5,2)]; .br valarray vi3 = sl; .RE .RS 0 .RE .RS 2 // print out the slice .RE .RS 1 cout << vi3 << endl; .RE .RS 2 .br // Add slice from vi2 to slice of vi1 .RE .RS 1 sl += vi2; .RE .RS 0 .RE .RS 2 // print out vi1 again .RE .RS 1 cout << vi << endl; .RE .RS 0 .RE .RS 1 return 0; .RE .RS 0 } .br .RE .RS 0 Program Output .RE .RS 1 .RE .RS 0 [0,1,2,3,4,5,6,7,8,9] .br [1,3,5,7,9] .br [1,3,5,7,9] .br [0,2,2,6,4,10,6,14,8,18] .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, gslice_array, mask_array, indirect_array