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

◆ to_tuple()

template<product_type Type>
constexpr auto kumi::to_tuple ( Type &&  t)
inlineconstexpr

Converts a kumi::product_type to an instance kumi::tuple.

Constructs an instance kumi::tuple from the elements of the kumi::product_type parameters

Parameters
tkumi::product_type to convert
Returns
An instance of kumi::tuple constructed from each elements of t in order.

Example

#include <kumi/tuple.hpp>
#include <cstdint>
#include <iostream>
#include <type_traits>
#include <utility>
struct pixel
{
int r, g, b;
};
template<std::size_t I>
decltype(auto) get(pixel const& p) noexcept
{
if constexpr(I==0) return p.r;
if constexpr(I==1) return p.g;
if constexpr(I==2) return p.b;
}
template<std::size_t I>
decltype(auto) get(pixel& p) noexcept
{
if constexpr(I==0) return p.r;
if constexpr(I==1) return p.g;
if constexpr(I==2) return p.b;
}
// Opt-in for Product Type semantic
template<>
struct kumi::is_product_type<pixel> : std::true_type
{};
// Adapt as structured bindable type
template<>
struct std::tuple_size<pixel>
: std::integral_constant<std::size_t,3> {};
template<std::size_t I> struct std::tuple_element<I,pixel> { using type = int; };
int main()
{
pixel a = { 37, 15, 27 };
auto b = kumi::to_tuple(a);
std::cout << b << "\n";
}
constexpr auto to_tuple(Type &&t)
Converts a kumi::product_type to an instance kumi::tuple.
Definition: convert.hpp:78
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:414
Opt-in traits for types behaving like a kumi::product_type.
Definition: traits.hpp:31