cuda::experimental::stf::all_convertible

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

template<typename T, typename ...P>
auto cuda::experimental::stf::all_convertible(P&&... p)

Creates an std::array of type T from all convertible elements in a parameter pack.

This template function inspects each element in a parameter pack and adds it to an std::array if it is convertible to the type T. It returns this array containing all convertible elements. The function ensures that only convertible elements are added by using std::is_convertible. It also handles exceptions and properly destructs already constructed elements in case of an exception during array construction.

int i = 42;
double d = 3.14;
std::string s = "hello";
// The following call will create an array of strings from all arguments that can be converted to a string.
// In this case, only 's' is convertible, so the array will contain two copies of 's'.
auto result = all_convertible<std::string>(i, s, d, s);

Note

The size of the returned array, N, is determined at compile time based on the number of convertible elements in the parameter pack.

Template Parameters
  • T – The target type to which the elements of the parameter pack should be convertible.

  • P – Variadic template representing the types in the parameter pack.

Parameters

p – The parameter pack containing elements to be checked for convertibility and potentially added to the array.

Throws

Any – exception thrown during the construction of elements in the array will be propagated after destructing already constructed elements.

Returns

::std::array<T, N> An array of type T containing all elements from the parameter pack that are convertible to T.