cuda::experimental::stf::shuffled_tuple

Defined in include/cuda/experimental/__stf/utility/traits.cuh

template<typename ...DataTypes, typename ...ArgTypes>
::std::tuple<DataTypes...> cuda::experimental::stf::shuffled_tuple(ArgTypes... args)

Creates a tuple with arguments in any order.

This function creates a tuple where each element is a value from the variadic argument list args that is convertible to the corresponding type in DataTypes. The function checks the convertibility of each argument type to the corresponding type in DataTypes and throws a static assertion if any argument type is not convertible to exactly one type in DataTypes.

struct A { int value; };
struct B { std::string text; };
struct C { float number; };

A a{10};
B b{"example"};
C c{3.14f};

// This will create an `std::tuple<A, B, C>` from the provided arguments,
// automatically assigning them based on their types.
auto my_tuple = shuffled_tuple<A, B, C>(b, c, a);
// Now my_tuple is of type std::tuple<A, B, C>, and contains a, b, c in that order.

// This will not compile because there are two arguments that can fill the same tuple slot.
// auto my_tuple = shuffled_tuple<A, B, C, double>(b, c, a, a);

// This will not compile because the argument '5' can convert to both 'int' and 'float',
// causing an ambiguity.
// auto my_tuple = shuffled_tuple<A, B, C>(b, c, 5);

Note

A static_assert error is issued if a type is not convertible to exactly one type.

Template Parameters
  • DataTypes – The types to use for the tuple elements.

  • ArgTypes – The types of the arguments to shuffle.

Parameters

args – The arguments to shuffle.

Returns

std::tuple<DataTypes…> A tuple where each element is a value from args that is convertible to the corresponding type in DataTypes.