KUMI v5.0.0
Gorgeous Garnet
Loading...
Searching...
No Matches

◆ to_tuple

to_tuple_t kumi::to_tuple {}
inlineconstexprnodiscard

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

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

Note
An overload is provided for kumi::concepts::static_container.

Header file

#include <kumi/product_types/tuple.hpp>

Call Signature

template<product_type T>
constexpr auto to_tuple(T&& t);

Parameters

Return value

  • An instance of kumi::tuple constructed from each element of t in order.

Example

#include <kumi/kumi.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;
}
// 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";
}
decltype(auto) constexpr get(record< Ts... > &r) noexcept
Extracts the Ith field from a kumi::record.
Definition record.hpp:766