operator==,!=,<,<=,>,>=(std::valarray)
Defined in header <valarray>
|
||
template< class T > std::valarray<bool> operator==( const std::valarray<T>& lhs, const std::valarray<T>& rhs ); |
(1) | |
template< class T > std::valarray<bool> operator==( const typename std::valarray<T>::value_type & lhsv, |
(2) | |
template< class T > std::valarray<bool> operator==( const std::valarray<T>& lhs, |
(3) | |
Compares each value within the numeric array with another value.
The behavior is undefined if size() != v.size().
Contents |
[edit] Parameters
lhs, rhs | - | numeric arrays to compare |
lhsv, rhsv | - | values to compare to each element within a numeric array |
[edit] Return value
A numeric array of bool containing comparison results of corresponding elements.
[edit] Exceptions
May throw implementation-defined exceptions.
[edit] Notes
Each of the operators can only be instantiated if the following requirements are met:
- The indicated operator can be applied to type
T
. - The result value can be unambiguously converted to bool.
- The indicated operator can be applied to type
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.
- For every function taking a const std::valarray<T>& except begin() and end()(since C++11), identical functions taking the replacement types shall be added;
- For every function taking two const std::valarray<T>& arguments, identical functions taking every combination of const std::valarray<T>& and replacement types shall be added.
- The return type does not add more than two levels of template nesting over the most deeply-nested argument type.
[edit] Example
#include <iostream> #include <valarray> int main() { // zero all negatives in a valarray std::valarray<int> v = {1, -1, 0, -3, 10, -1, -2}; std::cout << "Before: "; for (auto n : v) std::cout << n << ' '; std::cout << '\n'; v[v < 0] = 0;