KUMI v3.1.0
Exquisite Epidote
Loading...
Searching...
No Matches
kumi::is_product_type< T > Struct Template Reference

Detects if a type follows the tuple protocol. More...

#include <kumi/utils/traits.hpp>

Detailed Description

template<typename T>
struct kumi::is_product_type< T >

Detects if a type follows the tuple protocol.

To be treated like a product_type, a user defined type must follow the tuple protocol defined in the standard.

Helper value

template<typename T> inline constexpr auto is_product_type_v = is_product_type<T>::value;
Detects if a type follows the tuple protocol.
Definition traits.hpp:70

Example:

#include <kumi/kumi.hpp>
#include <iostream>
#include <string>
namespace ns
{
struct people
{
std::string name;
int age;
};
template<std::size_t I>
decltype(auto) get(people const& s) noexcept
{
if constexpr(I==0) return s.name;
if constexpr(I==1) return s.age;
}
template<std::size_t I>
decltype(auto) get(people& s) noexcept
{
if constexpr(I==0) return s.name;
if constexpr(I==1) return s.age;
}
}
// Adapt as structured bindable type
template<>
struct std::tuple_size<ns::people>
: std::integral_constant<std::size_t,2> {};
template<> struct std::tuple_element<0,ns::people> { using type = std::string; };
template<> struct std::tuple_element<1,ns::people> { using type = int; };
int main()
{
ns::people peter{"Peter Parker", 24};
kumi::for_each_index( [](auto i, auto e)
{
std::cout << "# " << i
<< " : " << e
<< "\n";
}
, peter
);
}
constexpr void for_each_index(Function f, T &&t, Ts &&... ts)
Applies the Callable object f on each element of a product type and its index.
Definition for_each.hpp:81
Compile-time text based identifier.
Definition identifier.hpp:162
decltype(auto) constexpr get(record< Ts... > &r) noexcept
Extracts the Ith field from a kumi::record.
Definition record.hpp:604