Namespaces
Variants
Views
Actions

operator+,-,*,/,%,&,|,<<,>>,^ std::valarray

From cppreference.com
< cpp‎ | numeric‎ | valarray
Revision as of 07:22, 5 December 2012 by Bazzy (Talk | contribs)

 
 
 
 

Template:ddcl list begin <tr class="t-dsc-header">

<td>
Defined in header <valarray>
</td>

<td></td> <td></td> <tr class="t-dcl ">

<td >
template <class T> std::valarray<T> operator+ (const std::valarray<T>& lhs, const std::valarray<T>& rhs);

template <class T> std::valarray<T> operator- (const std::valarray<T>& lhs, const std::valarray<T>& rhs);
template <class T> std::valarray<T> operator* (const std::valarray<T>& lhs, const std::valarray<T>& rhs);
template <class T> std::valarray<T> operator/ (const std::valarray<T>& lhs, const std::valarray<T>& rhs);
template <class T> std::valarray<T> operator% (const std::valarray<T>& lhs, const std::valarray<T>& rhs);
template <class T> std::valarray<T> operator& (const std::valarray<T>& lhs, const std::valarray<T>& rhs);
template <class T> std::valarray<T> operator| (const std::valarray<T>& lhs, const std::valarray<T>& rhs);
template <class T> std::valarray<T> operator^ (const std::valarray<T>& lhs, const std::valarray<T>& rhs);
template <class T> std::valarray<T> operator<< (const std::valarray<T>& lhs, const std::valarray<T>& rhs);

template <class T> std::valarray<T> operator>> (const std::valarray<T>& lhs, const std::valarray<T>& rhs);
</td>

<td > (1) </td> <td class="t-dcl-nopad"> </td> </tr> <tr class="t-dcl ">

<td >
template <class T> std::valarray<T> operator+ (const T& val, const std::valarray<T>& rhs);

template <class T> std::valarray<T> operator- (const T& val, const std::valarray<T>& rhs);
template <class T> std::valarray<T> operator* (const T& val, const std::valarray<T>& rhs);
template <class T> std::valarray<T> operator/ (const T& val, const std::valarray<T>& rhs);
template <class T> std::valarray<T> operator% (const T& val, const std::valarray<T>& rhs);
template <class T> std::valarray<T> operator& (const T& val, const std::valarray<T>& rhs);
template <class T> std::valarray<T> operator| (const T& val, const std::valarray<T>& rhs);
template <class T> std::valarray<T> operator^ (const T& val, const std::valarray<T>& rhs);
template <class T> std::valarray<T> operator<< (const T& val, const std::valarray<T>& rhs);

template <class T> std::valarray<T> operator>> (const T& val, const std::valarray<T>& rhs);
</td>

<td > (2) </td> <td class="t-dcl-nopad"> </td> </tr> <tr class="t-dcl ">

<td >
template <class T> std::valarray<T> operator+ (const std::valarray<T>& lhs, const T& rhs);

template <class T> std::valarray<T> operator- (const std::valarray<T>& lhs, const T& val);
template <class T> std::valarray<T> operator* (const std::valarray<T>& lhs, const T& val);
template <class T> std::valarray<T> operator/ (const std::valarray<T>& lhs, const T& val);
template <class T> std::valarray<T> operator% (const std::valarray<T>& lhs, const T& val);
template <class T> std::valarray<T> operator& (const std::valarray<T>& lhs, const T& val);
template <class T> std::valarray<T> operator| (const std::valarray<T>& lhs, const T& val);
template <class T> std::valarray<T> operator^ (const std::valarray<T>& lhs, const T& val);
template <class T> std::valarray<T> operator<< (const std::valarray<T>& lhs, const T& val);

template <class T> std::valarray<T> operator>> (const std::valarray<T>& lhs, const T& val);
</td>

<td > (3) </td> <td class="t-dcl-nopad"> </td> </tr> Template:ddcl list end

Apply binary operators to each element of two valarrays, or a valarray and a value.

1) The operators works on valarrays of the same size and returns avalarray with the same size as the parameters with the operation applied to every elements of the two arguments.
2,3) Applies the operator between each element of the valarray and the scalar.

Contents

Parameters

rhs - a numeric array
lhs - a numeric array
val - a value of type T

Return value

A valarray with the same size as the parameter.

Note

The behaviour is undefined when the two arguments are valarrays with different sizes.

The function can be implemented with the return type different from std::valarray. In this case, the replacement type has the following properties:

  • All const member functions of std::valarray are provided.
  • std::valarray, std::slice_array, std::gslice_array, std::mask_array and std::indirect_array can be constructed from the replacement type.
  • All functions accepting a arguments of type const std::valarray& should also accept the replacement type.
  • All functions accepting two arguments of type const std::valarray& should accept every combination of const std::valarray& and the replacement type.
  • The return type does not add more than two levels of template nesting over the most deeply-nested argument type.

Example