.\" ident @(#)indirect_array.3 .\" Standard Template Library .\" $$RW_INSERT_HEADER "slyrs.man" .TH indirect_array 3C++ "02 Apr 1998" "Rogue Wave Software" "-" .ce2 Standard C++ Library Copyright 1998, Rogue Wave Software, Inc. .SH NAME \f2indirect_array\fP \ - A numeric array class used to represent elements selected from a valarray. .SH SYNOPSIS .br #include .br template .br class indirect_array ; .SH DESCRIPTION indirect_array creates a selective view into a valarray. Indirect_arrays are produced by applying the indirect subscript operator to a valarray. The indirect array produced by this subscript contains only the elements of the valarray whose indices appear as values in the argument. The elements in an indirect_array are references to selected elements in the valarray (so changing an element in the indirect_array really changes the corresponding element in the valarray). An indirect_array does not itself hold any distinct elements. The template cannot be instantiated directly since all its constructors are private. However, you can copy an indirect_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 indirect_array { .br public: .br .RE .RS 2 // types .RE .RS 1 typedef T value_type; .RE .RS 0 .RE .RS 2 // destructor .br ~indirect_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 indirect_array(); .br indirect_array(const indirect_array&); .RE .RS 2 // operator = .RE .RS 1 indirect_array& .RE .RS 4 operator= (const indirect_array& array); .RE .RS 0 }; .SH CONSTRUCTORS .br indirect_array(); .br indirect_array(const indirect_array&); .RE .RS 3 All indirect_array constructors are private and cannot be called directly. This prevents copy construction of indirect_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 an indirect_array never holds any elements itself; it simply refers to selected elements in the valarray used to generate it. .RE .br indirect_array& .br operator=(const indirect-_array& x); .RE .RS 3 Private assignment operator. Cannot be called directly, thus preventing assignment between indirect_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 an indirect_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 // indirect_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[10] = {0,1,2,3,4,5,6,7,8,9}; .br size_t sbuf[6] = {0,2,3,4,7,8}; .RE .RS 0 .RE .RS 2 // create a valarray of ints .RE .RS 1 valarray vi(ibuf,10); .RE .RS 0 .RE .RS 2 // create a valarray of indices for a selector .RE .RS 1 valarray selector(sbuf,6); .RE .RS 0 .RE .RS 2 // print out the valarray .RE .RS 1 cout << vi << endl; .RE .RS 0 .RE .RS 2 // Get a indirect_array .br // and assign that indirect to another valarray .RE .RS 1 indirect_array select = vi[selector]; .br valarray vi3 = select; .RE .RS 0 .RE .RS 2 // print out the selective array .RE .RS 1 cout << vi3 << endl; .RE .RS 0 .RE .RS 2 // Double the selected values .RE .RS 1 select += vi3; .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 .br .br [0,1,2,3,4,5,6,7,8,9] .br [0,2,3,4,7,8] .br [0,1,4,6,8,5,6,14,16,9] .SH WARNINGS If your compiler does not support namespaces, then you do not need the using declaration for \f2std\fP. .SH SEE ALSO slice, slice_array, valarray, gslice, gslice_array, mask_array