kumi v3.1.0
Exquisite Epidote
 
Loading...
Searching...
No Matches
kumi::as_tuple< T, Meta > Struct Template Reference

Generate a kumi::tuple type from a type. More...

Detailed Description

template<typename T, template< typename... > class Meta = std::type_identity>
struct kumi::as_tuple< T, Meta >

Generate a kumi::tuple type from a type.

If T is a kumi::product_type, returns the kumi::tuple type containing the same element as T. Otherwise, it returns kumi::tuple<T>.

A template meta-function can be optionally passed to be applied to each of those types when types are computed.

Template Parameters
TType to transform
MetaUnary template meta-function to apply to each types. Defaults to std::type_identity

Helper type

namespace kumi
{
template<typename T, template<typename...> class Meta = std::type_identity>
using as_tuple_t = typename as_tuple<T, Meta>::type;
}
Main KUMI namespace.
Definition: algorithm.hpp:11
Generate a kumi::tuple type from a type.
Definition: convert.hpp:110

Example:

#include <kumi/tuple.hpp>
#include <concepts>
#include <cstdint>
#include <type_traits>
#include <utility>
struct vec3
{
float x, y, z;
};
template<std::size_t I>
decltype(auto) get(vec3 const& v) noexcept
{
if constexpr(I==0) return v.x;
if constexpr(I==1) return v.y;
if constexpr(I==2) return v.z;
}
template<std::size_t I>
decltype(auto) get(vec3& v) noexcept
{
if constexpr(I==0) return v.x;
if constexpr(I==1) return v.y;
if constexpr(I==2) return v.z;
}
// Opt-in for Product Type semantic
template<>
struct kumi::is_product_type<vec3> : std::true_type
{};
// Adapt as structured bindable type
template<>
struct std::tuple_size<vec3>
: std::integral_constant<std::size_t,3> {};
template<std::size_t I> struct std::tuple_element<I,vec3> { using type = float; };
int main()
{
using three_floats = kumi::as_tuple_t<vec3>;
using single_type = kumi::as_tuple_t<float>;
using three_pointers = kumi::as_tuple_t<vec3, std::add_pointer>;
using single_pointer = kumi::as_tuple_t<float, std::add_pointer>;
static_assert( std::same_as<three_floats , kumi::tuple<float ,float ,float > >);
static_assert( std::same_as<three_pointers, kumi::tuple<float*,float*,float*> >);
static_assert( std::same_as<single_type , kumi::tuple<float> >);
static_assert( std::same_as<single_pointer, kumi::tuple<float*> >);
}
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