KUMI v4.0.0
Flawless Fluorite
Loading...
Searching...
No Matches

◆ locate

locate_t kumi::locate {}
inlineconstexprnodiscardnoexcept

Callable object Returning the index of a value which type satisfies a given predicate.

On record types, this function operates as if the elements are ordered. The considered order is the order of declaration.

Header file

#include <kumi/algorithm/find.hpp>

Call Signature

template<product_type T, typename Predicate>
constexpr auto find(T && t, Predicate p) noexcept;

Parameters

  • t: Product Type to process
  • p: Unary predicate. p must return a value convertible to bool for every element of t.

Return value

  • The integral index of the element inside t that matches the predicate, size_v<T> otherwise.

Examples

  • Tuple
    #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 locate_t locate
    Callable object Returning the index of a value which type satisfies a given predicate.
    Definition find.hpp:84
    constexpr auto predicate() noexcept
    Convert a unary template meta-program in a running predicate.
    Definition ct_helpers.hpp:148
    Fixed-size collection of heterogeneous values.
    Definition tuple.hpp:33
  • Record
    #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 tagged fields, tags are unique.
    Definition record.hpp:36