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

◆ contains()

template<concepts::product_type T, concepts::identifier K>
bool kumi::contains ( T && t,
K const & k )
inlineconstexprnoexcept

Checks if product type contains a given identifier.

Parameters
tthe product type to inspect.
kKeyword to check
Returns
true if current product_type contains a field based on the kw, and false otherwise.

Examples:

#include <kumi/kumi.hpp>
#include <iostream>
using namespace kumi::literals;
template<kumi::concepts::product_type T>
void check_contains(T const& t)
{
if constexpr(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} );
}
constexpr bool contains(T &&t, K const &k) noexcept
Checks if product type contains a given identifier.
Definition contains.hpp:31
constexpr decltype(auto) get(record< Ts... > &&r) noexcept
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition record.hpp:506
Fixed-size collection of heterogeneous values.
Definition tuple.hpp:29
#include <kumi/kumi.hpp>
#include <iostream>
using namespace kumi::literals;
template<kumi::concepts::product_type T>
void check_contains(T const& t)
{
if constexpr(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 fields necessarily named, names are unique.
Definition record.hpp:29