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

◆ contains_only()

template<concepts::product_type T, concepts::identifier... Is>
auto kumi::contains_only ( T && t,
Is const &... ids )
inlineconstexprnoexcept

Checks if a product type contains fields based only on selected identifiers.

Parameters
tthe product type to inspect.
idsIdentifiers to check
Returns
std::true_type if t contains a field labeled by any of the ids, and std::false_type otherwise.

Helper type

namespace kumi::result
{
template<product_type T, concepts::identifier... ID> struct contains_only;
template<product_type T, concepts::identifier... ID>
using contains_only_t = typename contains_only<T,ID...>::type;
}
Concept specifying a type represent an identifier.
Definition concepts.hpp:193
constexpr auto contains_only(T &&t, Is const &... ids) noexcept
Checks if a product type contains fields based only on selected identifiers.
Definition contains.hpp:131

Computes the type returned by a call to 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(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:33

Record:

#include <kumi/kumi.hpp>
#include <iostream>
using namespace kumi::literals;
template<kumi::concepts::product_type T>
void check_contains(T const&)
{
if constexpr(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 tagged fields, tags are unique.
Definition record.hpp:36