##### cppreference.com

##### Search

Create account

##### Namespaces

- Page
- Discussion

##### Variants

##### Views

- View
- Edit
- History

##### Actions

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

From cppreference.com
< cpp‎ | numeric‎ | valarray

Defined in header `<valarray>` |  |
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); | (1) |
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); | (2) |
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); | (3) |

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.

### [edit] Parameters

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

### [edit] Return value

A valarray with the same size as the parameter.

### [edit] 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.

### [edit] Example

| This section is incomplete Reason: no example

Retrieved from "http://en.cppreference.com/mwiki/index.php?title=cpp/numeric/valarray/operator_arith3&oldid=51083"
Category:

- Todo no example