C++ valarray Library - Function max
Description
It returns the maximum value contained in the valarray, as if the elements were compared with operator<.
Declaration
Following is the declaration for std::valarray::max function.
T max() const;
C++11
T max() const;
Parameters
none
Return Value
It returns the maximum value contained in the valarray, as if the elements were compared with operator<.
Exceptions
Basic guarantee − if any operation performed on the elements throws an exception.
Data races
All elements effectively copied are accessed.
Example
In below example explains about std::valarray::max function.
#include <iostream>
#include <valarray>
int main () {
int init[]={10,50,20,90};
std::valarray<int> myvalarray (init,4);
std::cout << "The max is " << myvalarray.max() << '\n';
return 0;
}
Let us compile and run the above program, this will produce the following result −
The max is 90
valarray.htm