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

◆ locate()

template<typename Pred, concepts::product_type Tuple>
auto kumi::locate ( Tuple && t,
Pred p )
inlinenodiscardconstexprnoexcept

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.

Examples:

#include <kumi/kumi.hpp>
#include <iostream>
#include <type_traits>
int main()
{
auto t = kumi::tuple{1, 2., 0ULL, 3.f, 'z'};
std::cout << std::boolalpha
std::cout << std::boolalpha << kumi::locate( t, [](auto e) { return e > 3; } ) << "\n";
}
constexpr auto locate(Tuple &&t, Pred p) noexcept
Return the index of a value which type satisfies a given predicate.
Definition find.hpp:25
constexpr auto predicate() noexcept
Convert a unary template meta-program in a running predicate.
Definition ct_helpers.hpp:111
Fixed-size collection of heterogeneous values.
Definition tuple.hpp:29
#include <kumi/kumi.hpp>
#include <iostream>
#include <type_traits>
int main()
{
using namespace kumi::literals;
auto r = kumi::record{"a"_id = 1, "b"_id = 2., "c"_id = 0ULL, "d"_id = 3.f, "e"_id = 'z'};
std::cout << std::boolalpha
std::cout << std::boolalpha << kumi::locate( r, [](auto e) { return e > 3; } ) << "\n";
}
Fixed-size collection of heterogeneous fields necessarily named, names are unique.
Definition record.hpp:29