C++ <valarray> - operator! Function
The C++ valarray::operator! function is used to apply unary not operator to each element of the valarray.
Syntax
valarray<bool> operator!() const;
Parameters
No parameter is required.
Return Value
Returns a new valarray object with modified values.
Time Complexity
Depends on library implementation.
Example:
In the example below, the valarray::operator! function is used to perform unary not operation on each element of the given valarray.
#include <iostream> #include <valarray> using namespace std; int main (){ valarray<bool> varr1 {true, false, true}; //result of unary not operation //on varr1 is stored in varr2 valarray<bool> varr2 = !varr1; cout<<boolalpha; cout<<"varr1 contains: "; for(int i = 0; i < varr1.size(); i++) cout<<varr1[i]<<" "; cout<<"\nvarr2 contains: "; for(int i = 0; i < varr2.size(); i++) cout<<varr2[i]<<" "; return 0; }
The output of the above code will be:
varr1 contains: true false true varr2 contains: false true false
❮ C++ <valarray> Library