| <!-- |
| Licensed to the Apache Software Foundation (ASF) under one or more |
| contributor license agreements. See the NOTICE file distributed |
| with this work for additional information regarding copyright |
| ownership. The ASF licenses this file to you under the Apache |
| License, Version 2.0 (the License); you may not use this file |
| except in compliance with the License. You may obtain a copy of |
| the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or |
| implied. See the License for the specific language governing |
| permissions and limitations under the License. |
| |
| Copyright 1999-2007 Rogue Wave Software, Inc. |
| --> |
| |
| <HTML> |
| <HEAD> |
| <TITLE>Member Functions</TITLE> |
| <LINK REL=StyleSheet HREF="../rw.css" TYPE="text/css" TITLE="Apache stdcxx Stylesheet"></HEAD> |
| <BODY BGCOLOR=#FFFFFF> |
| <A HREF="22-5.html"><IMG SRC="images/bprev.gif" WIDTH=20 HEIGHT=21 ALT="Previous file" BORDER=O></A><A HREF="noframes.html"><IMG SRC="images/btop.gif" WIDTH=56 HEIGHT=21 ALT="Top of Document" BORDER=O></A><A HREF="booktoc.html"><IMG SRC="images/btoc.gif" WIDTH=56 HEIGHT=21 ALT="Contents" BORDER=O></A><A HREF="tindex.html"><IMG SRC="images/bindex.gif" WIDTH=56 HEIGHT=21 ALT="Index page" BORDER=O></A><A HREF="22-7.html"><IMG SRC="images/bnext.gif" WIDTH=25 HEIGHT=21 ALT="Next file" BORDER=O></A><DIV CLASS="DOCUMENTNAME"><B>Apache C++ Standard Library User's Guide</B></DIV> |
| <H2>22.6 Member Functions</H2> |
| <A NAME="idx471"><!></A> |
| <P>The member functions of class <B><I><A HREF="../stdlibref/valarray.html">valarray</A></I></B> include the <SAMP>size()</SAMP> function, which returns the size of a <B><I>valarray</I></B>, and the <SAMP>sum()</SAMP> function, which returns the sum of all elements in a <B><I>valarray</I></B>. The functions <SAMP>min()</SAMP> and <SAMP>max()</SAMP> return, respectively, the minimum and maximum values in a <B><I>valarray</I></B>.</P> |
| <P>Class <B><I><A HREF="../stdlibref/valarray.html">valarray</A></I></B> also contains two shift functions. Both functions shift elements a specified number of steps to the left, where the <SAMP>0</SAMP><SUP>th</SUP> element is defined as the leftmost. The <SAMP>shift()</SAMP> function fills in at the right with <SAMP>0</SAMP>s or <SAMP>T()</SAMP>s. The <SAMP>cshift()</SAMP> function performs a circular shift or <I>rotation</I> so that the <SAMP>i</SAMP><SUP>th</SUP> element becomes the element at location <SAMP>self.length() - n - i</SAMP>, where <SAMP>i</SAMP> runs from <SAMP>0</SAMP> to <SAMP>n</SAMP>, and <SAMP>n</SAMP> is the number of steps to shift. Both functions return a new <B><I>valarray</I></B>, but the original is not changed. For example:</P> |
| |
| <UL><PRE> |
| int a[5] = {1,2,3,4,5}; |
| std::valarray<int> v(a,5); |
| std::valarray<int> v2 = v.shift(2); // v2 = {3,4,5,0,0} |
| v2 = v.cshift(2); // v2 = {3,4,5,1,2} |
| </PRE></UL> |
| <P>Class <B><I><A HREF="../stdlibref/valarray.html">valarray</A></I></B> provides two versions of the <SAMP>apply()</SAMP> function. These functions apply a user-specified function to each element in the array. Again, these return a new array with the result leaving the original array unaltered.</P> |
| <P>Finally, as we noted in the discussion on constructors, <B><I><A HREF="../stdlibref/valarray.html">valarray</A></I></B> has a resize function that allows a program to change the number of elements contained by that array. The original elements, if any, are lost in the process since the function re-initializes all elements in the newly-sized array.</P> |
| |
| <BR> |
| <HR> |
| <A HREF="22-5.html"><IMG SRC="images/bprev.gif" WIDTH=20 HEIGHT=21 ALT="Previous file" BORDER=O></A><A HREF="noframes.html"><IMG SRC="images/btop.gif" WIDTH=56 HEIGHT=21 ALT="Top of Document" BORDER=O></A><A HREF="booktoc.html"><IMG SRC="images/btoc.gif" WIDTH=56 HEIGHT=21 ALT="Contents" BORDER=O></A><A HREF="tindex.html"><IMG SRC="images/bindex.gif" WIDTH=56 HEIGHT=21 ALT="Index page" BORDER=O></A><A HREF="22-7.html"><IMG SRC="images/bnext.gif" WIDTH=20 HEIGHT=21 ALT="Next file" BORDER=O></A> |
| |
| <!-- Google Analytics tracking code --> |
| <script src="http://www.google-analytics.com/urchin.js" type="text/javascript"> |
| </script> |
| <script type="text/javascript"> |
| _uacct = "UA-1775151-1"; |
| urchinTracker(); |
| </script> |
| <!-- end of Google Analytics tracking code --> |
| |
| </BODY> |
| </HTML> |