KUMI v5.0.0
Gorgeous Garnet
Loading...
Searching...
No Matches
kumi::contains_only

Callable object checking if a product type contains fields based on a selected identifier. More...

Variables

constexpr contains_only_t kumi::contains_only {}

Detailed Description

Callable object checking if a product type contains fields based on a selected identifier.

Variable Documentation

◆ contains_only

contains_only_t kumi::contains_only {}
inlineconstexprnodiscardnoexcept

Header file

#include <kumi/kumi.hpp>

Call Signature

namespace kumi
{
constexpr auto contains_only(T && t, IDs const&... ids) noexcept;
}
Concept specifying a type represents an identifier.
Definition concepts.hpp:204
Concept specifying a type follows the Product Type semantic.
Definition concepts.hpp:77
constexpr contains_only_t contains_only
Definition contains.hpp:254
Main KUMI namespace.
Definition algorithm.hpp:11

Parameters

  • t: The product type to inspect
  • ids: The identifiers to check for

Return value

  • std::true_type if t contains a field labeled with any of the ids, std::false_type otherwise.

Helper type

template<kumi::concepts::product_type T, kumi::concepts::identifier... IDs>
using contains_only_t = decltype(kumi::contains_only(kumi::declval<T>(), kumi::declval<IDs>()...));
template<kumi::concepts::product_type T, kumi::concepts::identifier... IDs> struct contains_only
{
using type = kumi::result::contains_only_t<T, IDs...>;
};

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

Examples

  • Tuple
    #include <kumi/kumi.hpp>
    #include <iostream>
    using namespace kumi::literals;
    template<kumi::concepts::product_type T>
    void check_contains(T const&)
    {
    if constexpr(kumi::contains_only(T{}, "value"_id, "active"_id))
    std::cout << "Correct product_type\n";
    else
    std::cout << "Incorrect product type\n";
    }
    int main()
    {
    check_contains( kumi::tuple{"value"_id = 9 });
    check_contains( kumi::tuple{"malus"_id = 6.5, "value"_id = 17} );
    check_contains( kumi::tuple{"active"_id = std::bool_constant<true>{} });
    check_contains( kumi::tuple{"active"_id = std::bool_constant<true>{}, "value"_id = 17} );
    check_contains( kumi::tuple{"active"_id = std::bool_constant<true>{}, "value"_id = 17, "other"_id = false});
    }
    Fixed-size collection of heterogeneous values.
    Definition tuple.hpp:35
  • Record
    #include <kumi/kumi.hpp>
    #include <iostream>
    using namespace kumi::literals;
    template<kumi::concepts::product_type T>
    void check_contains(T const&)
    {
    if constexpr(kumi::contains_only(T{}, "value"_id, "active"_id))
    std::cout << "Correct product_type\n";
    else
    std::cout << "Incorrect product type\n";
    }
    int main()
    {
    check_contains( kumi::record{"value"_id = 9 });
    check_contains( kumi::record{"malus"_id = 6.5, "value"_id = 17} );
    check_contains( kumi::record{"active"_id = std::bool_constant<true>{} });
    check_contains( kumi::record{"active"_id = std::bool_constant<true>{}, "value"_id = 17} );
    check_contains( kumi::record{"active"_id = std::bool_constant<true>{}, "value"_id = 17, "other"_id = false});
    }
    Fixed-size collection of heterogeneous fields with distinct labels.
    Definition record.hpp:36