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

◆ max_element

eve::algo::max_element = function_with_traits<max_element_>[default_simple_algo_traits]
inlineconstexpr

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

Note
if you just need a value and not position, use eve::algo::max_value.

By default unrolls by 4 and aligned all memory accesses.

Note
for equivalent elements we return the second amoung equal. std::max_element* returns first but this is more correct and this is also what std::minmax_element` will return as max.
we assume that eve::is_less defined for your type is total order. (this comes up when switching min with max)

Alternative Header

#include <eve/algo.hpp>

Callable Signatures

namespace eve::algo
{
template<relaxed_range Rng, typename Less>
auto max_element(Rng&& rng, Less less) -> unaligned_iterator_t<Rng>; // 1
template<relaxed_range Rng>
auto max_element(Rng&& rng) -> unaligned_iterator_t<Rng>; // 2
}
unaligned_t< iterator_t< R > > unaligned_iterator_t
Unaligned iterator for a relaxed range.
Definition: ranges_types.hpp:68
constexpr auto max_element
SIMD variation on std::max_element not exact match
Definition: max_element.hpp:93
  1. Returns the position of a maximum value, according to less. If the range is empty - returns past the end.
  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

iterator to max element (end if the range is empty).

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_value
SIMD algorithm that returns maximum value in the range.
Definition: max_value.hpp:94
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
max_value
min_element