kumi v3.1.0
Exquisite Epidote
 
Loading...
Searching...
No Matches

◆ locate()

template<typename Pred , typename... Ts>
constexpr auto kumi::locate ( tuple< Ts... > const &  t,
Pred  p 
)
constexprnoexcept

Return the index of a value which type satisfies a given predicate.

Parameters
tTuple to process
pUnary predicate. p must return a value convertible to bool for every element of t.
Returns
Integral index of the element inside the tuple if present, kumi::size<tuple<T...>>::value otherwise.

Example:

#include <kumi/tuple.hpp>
#include <iostream>
#include <type_traits>
int main()
{
auto t = kumi::tuple{1, 2., 0ULL, 3.f, 'z'};
std::cout << std::boolalpha
<< kumi::locate( t, kumi::predicate<std::is_floating_point>() ) << "\n";
std::cout << std::boolalpha << kumi::locate( t, [](auto e) { return e > 3; } ) << "\n";
}
constexpr auto locate(tuple< Ts... > const &t, Pred p) noexcept
Return the index of a value which type satisfies a given predicate.
Definition: find.hpp:23
Fixed-size collection of heterogeneous values.
Definition: tuple.hpp:35