E.V.E
v2023.02.15
 
Loading...
Searching...
No Matches

◆ max_value

eve::algo::max_value = function_with_traits<max_value_>[default_simple_algo_traits]
inlineconstexpr

#include <eve/module/algo/algo/max_value.hpp>

The standard only has _element versions of min/max algorithms. However, in SIMD finding the value is much faster then also finding the position - hense this algorithm.

Note
for equivalent elements we return the second amoung equal.
we assume that eve::is_less defined for your type is total order. (this comes up when switching max with min)

Alternative Header

#include <eve/algo.hpp>

Callable Signatures

namespace eve::algo
{
template <eve::algo::relaxed_range Rng, typename Less>
std::optional<eve::value_type_t<Rng>> max_value(Rng&& rng, Less less); // 1
template <eve::algo::relaxed_range Rng>
std::optional<eve::value_type_t<Rng>> max_value(Rng&& rng); // 2
}
constexpr auto max_value
SIMD algorithm that returns maximum value in the range.
Definition: max_value.hpp:94
  1. Returns the maximum value, according to less. If the range is empty - returns nullopt.
  2. Same as 1 but the less is eve::is_less

Parameters

  • rng: Relaxed input range to process
  • less: SIMD strict weak ordering.

Return value

maximum value from the range. If the input range was empty, it's std::nullopt.

Example

#include <eve/module/core.hpp>
#include <eve/module/algo.hpp>
#include <tts/tts.hpp> // as_string
#include <vector>
int main()
{
std::vector<int> v{ 2, 4, -1, 4, 0, 1 };
std::cout << " -> v = "
<< tts::as_string(v)
<< "\n";
std::cout << " -> eve::algo::max_value(v) = "
<< *eve::algo::max_value(v) << "\n";
std::cout << " -> eve::algo::max_element(v) - v.begin() = "
<< eve::algo::max_element(v) - v.begin() << "\n";
std::cout << " -> eve::algo::max_value(v, eve::is_greater) = "
std::cout << " -> eve::algo::max_value(v, eve::is_greater) - v.begin() = "
<< eve::algo::max_element(v, eve::is_greater) - v.begin() << "\n";
}
constexpr auto max_element
SIMD variation on std::max_element not exact match
Definition: max_element.hpp:93
constexpr auto is_greater
elementwise callable returning a logical true if and only if the element value of the first parameter...
Definition: is_greater.hpp:84
See also
min_value
max_element