◆ max_val() [1/2]

template<typename T , typename Comp >
T boost::simd::max_val ( T const *  first,
T const *  last,
Comp  comp 

Returns the value of the element with the smallest value in the range [first,last), The largest possible value for the order if the range is empty.

firstBeginning of the range of elements to max_val
lastEnd of the range of elements to max_val
compcomparison function object that will be applied.
  • first and last must be pointer to Vectorizable type.
  • comp must be a polymorphic unary function object, i.e callable on generic types.
  • if comp is not present the function test is done with operator <

The following code uses simd::max_val to find the greatest and smallest element std::vector.

#include <boost/simd/algorithm/max_val.hpp>
#include <boost/simd/function/is_greater.hpp>
#include <iostream>
#include <vector>
int main()
namespace bs = boost::simd;
std::vector<float> d{ 0.0f, 2.0f, 0.0f, 0.0f, -1.0f, 2.0f, 0.0f};
auto r1 = bs::max_val( d.data(), d.data()+7);
std::cout << "r1 " << r1<< "\n";
auto r2 = bs::max_val( d.data(), d.data()+7, bs::is_greater);
std::cout << "r2 " << r2 << "\n";
return 0;
r1 2
r2 -1
the maximum value of the range elements.