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:71

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( [](int i, auto e)
{
std::cout << "# " << i
<< " : " << e
<< "\n";
}
, peter
);
}
constexpr void for_each_index(Function f, Tuple &&t, Tuples &&... ts)
Applies the Callable object f on each element of a kumi::product_type and its index.
Definition for_each.hpp:79
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:410