public member function
<valarray>

std::valarray::min

T min() const;
Return smallest value
Returns the minimum value contained in the valarray, as if the elements were compared with operator<.

If the valarray has a size of zero, the value returned is unspecified (depends on the particular library implementation).

T shall support being compared with operator<.

Parameters

none

Return value

The smallest value in the valarray.
T is the template argument of valarray (the value type).

Example

1
2
3
4
5
6
7
8
9
10
11
12
// valarray::min example
#include <iostream>     // std::cout
#include <valarray>     // std::valarray

int main ()
{
  int init[]={20,40,10,30};
  std::valarray<int> myvalarray (init,4);
  std::cout << "The min is " << myvalarray.min() << '\n';

  return 0;
}


Output:

The min is 10

Complexity

Depends on library implementation (operations may be parallelized).

Iterator validity

No changes: Valid iterators, references and sub-arrays keep their validity.

Data races

Both the valarray and its elements are accessed.

Exception safety

If comparing element values with operator< throws an exception, it causes undefined behavior.

See also