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

◆ contains

contains_t kumi::contains {}
inlineconstexprnodiscardnoexcept

Callable object checking if a product type contains a given identifier.

Header file

#include <kumi/algorithm/contains.hpp>

Call Signature

template<product_type T, identifier ID>
constexpr auto contains(T && t, ID const& id) noexcept;
constexpr contains_t contains
Callable object checking if a product type contains a given identifier.
Definition contains.hpp:129

Parameters

  • t: The product type to inspect
  • id: The identifier to check for

Return value

  • std::true_type if t contains a field labeled with the id identifier, std::false_type otherwise.

Helper type

template<kumi::concepts::product_type T, kumi::concepts::identifier ID> struct contains
{
using type = decltype(kumi::contains(std::declval<T>(), std::declval<ID>()));
};
template<kumi::concepts::product_type T, kumi::concepts::identifier ID>
using contains_t = typename kumi::result::contains<T, ID>::type;

Computes the return type of a call to kumi:contains:

Examples

  • Tuple
    #include <kumi/kumi.hpp>
    #include <iostream>
    using namespace kumi::literals;
    template<kumi::concepts::product_type T>
    void check_contains(T const& t)
    {
    if constexpr(kumi::contains(T{}, "value"_id))
    std::cout << "Correct product_type: " << get<"value"_id>(t) << '\n';
    else
    std::cout << "Incorrect product type\n";
    }
    int main()
    {
    check_contains( kumi::tuple{"value"_id = 9 });
    check_contains( kumi::tuple{"malus"_id = 3.5});
    check_contains( kumi::tuple{"malus"_id = 6.5, "value"_id = 17} );
    }
    decltype(auto) constexpr get(record< Ts... > &r) noexcept
    Extracts the Ith field from a kumi::record.
    Definition record.hpp:618
    Fixed-size collection of heterogeneous values.
    Definition tuple.hpp:33
  • Record
    #include <kumi/kumi.hpp>
    #include <iostream>
    using namespace kumi::literals;
    template<kumi::concepts::product_type T>
    void check_contains(T const& t)
    {
    if constexpr(kumi::contains(T{}, "value"_id))
    std::cout << "Correct product_type: " << get<"value"_id>(t) << '\n';
    else
    std::cout << "Incorrect product type\n";
    }
    int main()
    {
    check_contains( kumi::record{"value"_id = 9 });
    check_contains( kumi::record{"malus"_id = 3.5});
    check_contains( kumi::record{"malus"_id = 6.5, "value"_id = 17} );
    }
    Fixed-size collection of heterogeneous tagged fields, tags are unique.
    Definition record.hpp:36