J
john
Hi, in TC++PL3 on page 665, regarding valarray member functions, it is
mentioned:
"valarray operator-() const; // result= -v for every element
// similarly: +, ~, !"
I checked the web and could not find anything that explains the need of
this "operator+".
Any ideas?
In MSDN it is mentioned:
"Standard C++ Library Reference
valarray:perator+
A unary operator that applies a plus to each element in a valarray.
valarray<Type> operator+( ) const;
Return Value
A valarray whose elements are plus those of the operand array.
Example
// valarray_op_eplus.cpp
// compile with: /EHsc
#include <valarray>
#include <iostream>
int main( )
{
using namespace std;
int i;
valarray<int> vaL ( 10 );
valarray<int> vaPLUS ( 10 );
for ( i = 0 ; i < 10 ; i += 2 )
vaL [ i ] = -i;
for ( i = 1 ; i < 10 ; i += 2 )
vaL [ i ] = i-1;
cout << "The initial valarray is: ( ";
for ( i = 0 ; i < 10 ; i++ )
cout << vaL [ i ] << " ";
cout << ")." << endl;
vaPLUS = +vaL;
cout << "The element-by-element result of "
<< "the operator+ is the\n valarray: ( ";
for ( i = 0 ; i < 10 ; i++ )
cout << vaPLUS [ i ] << " ";
cout << ")." << endl;
}
Output
The initial valarray is: ( 0 0 -2 2 -4 4 -6 6 -8 8 ).
The element-by-element result of the operator+ is the
valarray: ( 0 0 -2 2 -4 4 -6 6 -8 8 ).
Requirements
Header: <valarray>"
mentioned:
"valarray operator-() const; // result= -v for every element
// similarly: +, ~, !"
I checked the web and could not find anything that explains the need of
this "operator+".
Any ideas?
In MSDN it is mentioned:
"Standard C++ Library Reference
valarray:perator+
A unary operator that applies a plus to each element in a valarray.
valarray<Type> operator+( ) const;
Return Value
A valarray whose elements are plus those of the operand array.
Example
// valarray_op_eplus.cpp
// compile with: /EHsc
#include <valarray>
#include <iostream>
int main( )
{
using namespace std;
int i;
valarray<int> vaL ( 10 );
valarray<int> vaPLUS ( 10 );
for ( i = 0 ; i < 10 ; i += 2 )
vaL [ i ] = -i;
for ( i = 1 ; i < 10 ; i += 2 )
vaL [ i ] = i-1;
cout << "The initial valarray is: ( ";
for ( i = 0 ; i < 10 ; i++ )
cout << vaL [ i ] << " ";
cout << ")." << endl;
vaPLUS = +vaL;
cout << "The element-by-element result of "
<< "the operator+ is the\n valarray: ( ";
for ( i = 0 ; i < 10 ; i++ )
cout << vaPLUS [ i ] << " ";
cout << ")." << endl;
}
Output
The initial valarray is: ( 0 0 -2 2 -4 4 -6 6 -8 8 ).
The element-by-element result of the operator+ is the
valarray: ( 0 0 -2 2 -4 4 -6 6 -8 8 ).
Requirements
Header: <valarray>"