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

◆ first_true

eve::first_true = functor<first_true_t>
inlineconstexpr
#include <eve/module/core.hpp>

Callable Signatures

template <relaxed_logical_value L>
std::optional<std::ptrdiff_t> first_true(L m) noexcept; // 1
template <logical_simd_value L>
std::optional<std::ptrdiff_t> first_true(top_bits<L> m) noexcept; // 1
// lane masking
std::optional<std::ptrdiff_t> first_true[conditional_expr auto c](/* any of the above */) noexcept; // 2
std::optional<std::ptrdiff_t> first_true[logical_value auto c](/* any of the above */) noexcept; // 2
Specifies that a type is a Conditional Expression.
Definition conditional.hpp:28
The concept logical_value<T> is satisfied if and only if T satisfies eve::value and the element type ...
Definition value.hpp:134
constexpr auto first_true
Returns the index of the first element in the input which evaluates to true, if there is one.
Definition first_true.hpp:83
typename decltype(detail::as_translated_type(as< T >{}))::type translate_t
Returns the final translated type of T.
Definition translation.hpp:107

Parameters

  • m - logical_value or top_bits where to find first true value

Return value

  1. An std::optional containing the index of the first element which evaluates to true, std::nullopt if there are none.
  2. Same as 1. but masked elements are ignored during the search.

Should you check for any?

The function is considering the case when nothing is set to be likely, checking for eve::any before hand is not going to be helpful. At the moment there isn't a function that would do it otherwise.

What if I know there is a match?

We would recommend eve::first_true(m) - this is likely to trigger compiler optimizations, based on it being UB otherwise.

Example

// revision 0
#include <eve/module/core.hpp>
#include <iostream>
int main()
{
eve::wide wu0{0u, 1u, 2u, 3u, 4u, 5u, 6u, 7u};
std::cout << "<- wu0 = " << wu0 << "\n";
std::cout << "-> first_true(wu0 >= maximum(wu0)/2) = " << *eve::first_true(wu0 >= eve::maximum(wu0)/2) << "\n";
std::cout << "-> first_true[ignore_first(4)](wu0 <= maximum(wu0)/2 > 1u) = " << *eve::first_true[eve::ignore_first(4)](wu0 > 1u) << "\n";
}
constexpr auto maximum
Computes the maximal value in a simd vector or valmin if the input is fully masked.
Definition maximum.hpp:82
Conditional expression ignoring the k first lanes from a eve::simd_value.
Definition conditional.hpp:459
Wrapper for SIMD registers.
Definition wide.hpp:94