template<typename T, typename Enable = void>
struct kumi::is_product_type< T, Enable >
Opt-in traits for types behaving like a kumi::product_type.
To be treated like a tuple, an user defined type must supports structured bindings opt-in to kumi::product_type Semantic.
This can be done in two ways:
Example:
#include <kumi/tuple.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;
}
}
template<>
{};
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};
{
std::cout << "# " << i
<< " : " << e
<< "\n";
}
, peter
);
}
KUMI_TRIVIAL_NODISCARD constexpr decltype(auto) get(tuple< Ts... > &&arg) noexcept
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: tuple.hpp:416
Opt-in traits for types behaving like a kumi::product_type.
Definition: traits.hpp:31