E.V.E
v2022.03.00

◆ min_element

eve::algo::min_element = function_with_traits<min_element_>[default_simple_algo_traits]
inlineconstexpr

#include <eve/algo/min_element.hpp>

SIMD version of std::min_element

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

By default unrolls by 4 and aligned all memory accesses.

Note
for equivalent elements we return the first amoung equal.
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 min_element(Rng&& rng, Less less) -> unaligned_iterator_t<Rng>; // 1
template<relaxed_range Rng>
auto min_element(Rng&& rng) -> unaligned_iterator_t<Rng>; // 2
}
constexpr auto min_element
SIMD version of std::min_element
Definition: min_element.hpp:92
  1. Returns the position of a minimum 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 min element (end if the range is empty).

Example

#include <eve/module/core.hpp>
#include <eve/algo.hpp>
#include <tts/tts.hpp> // as_string
#include <vector>
int main()
{
std::vector<int> v{ 2, -1, 4, -1, 0 };
std::cout << " -> v = "
<< tts::as_string(v)
<< "\n";
std::cout << " -> eve::algo::min_value(v) = "
<< *eve::algo::min_value(v) << "\n";
std::cout << " -> eve::algo::min_element(v) - v.begin() = "
<< eve::algo::min_element(v) - v.begin() << "\n";
std::cout << " -> eve::algo::min_value(v, eve::is_greater) = "
std::cout << " -> eve::algo::min_value(v, eve::is_greater) - v.begin() = "
<< eve::algo::min_element(v, eve::is_greater) - v.begin() << "\n";
}
constexpr auto min_value
SIMD algorithm that returns minimum value in the range.
Definition: min_value.hpp:100
constexpr callable_is_greater_ is_greater
Returns a logical true if and only if the element value of the first parameter is greater than the se...
Definition: is_greater.hpp:80
See also
min_value
max_element