#include <eve/algo/min_value.hpp>
SIMD algorithm that returns minimum value in the range.
C++ standard only has std::min_element
that returns iterator to the minimum element. We have that too (see: eve::algo::min_element
) but it's slower then just getting the value. So we also provide min_value
for when you don't care about the position. 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
namespace eve::algo
{
template <eve::algo::relaxed_range Rng, typename Less>
std::optional<eve::value_type_t<Rng>>
min_value(Rng&& rng, Less less);
template <eve::algo::relaxed_range Rng>
std::optional<eve::value_type_t<Rng>>
min_value(Rng&& rng);
}
constexpr auto min_value
SIMD algorithm that returns minimum value in the range.
Definition: min_value.hpp:100
- Returns the minimum value, according to less. If the range is empty - returns nullopt.
- Same as 1 but the less is
eve::is_less
Parameters
rng
: Relaxed input range to process
less
: SIMD strict weak ordering.
Return value
minimum value from the range. If the input range was empty, it's std::nullopt
.
#include <eve/module/core.hpp>
#include <eve/algo.hpp>
#include <tts/tts.hpp>
#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) = "
std::cout << " -> eve::algo::min_element(v) - v.begin() = "
std::cout << " -> eve::algo::min_value(v, eve::is_greater) = "
std::cout << " -> eve::algo::min_value(v, eve::is_greater) - v.begin() = "
}
constexpr auto min_element
SIMD version of std::min_element
Definition: min_element.hpp:92
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
max_value
-
min_element