cuda::is_trivially_copyable#
Defined in the <cuda/type_traits> header.
namespace cuda {
template <typename T>
constexpr bool is_trivially_copyable_v = /* see below */;
template <typename T>
using is_trivially_copyable = cuda::std::bool_constant<cuda::std::is_trivially_copyable_v<T>>;
} // namespace cuda
cuda::is_trivially_copyable_v trait evaluates if a type can be copied by copying its underlying bytes.
It extends cuda::std::is_trivially_copyable to also recognize CUDA extended floating-point vector types as trivially copyable.
The trait is true when T is any of the following:
A type for which
cuda::std::is_trivially_copyable_v<T>is true.An extended floating-point vector type, for example
__half2,__nv_bfloat162.
The trait also propagates through composite types:
C-style arrays:
T[N]andT[]are trivially copyable whenTis.cuda::std::array<T, N>: trivially copyable whenTis.cuda::std::pair<T1, T2>: trivially copyable when bothT1andT2are.cuda::std::tuple<Ts...>: trivially copyable when allTs...are.cuda::std::complex<T>: trivially copyable whenTis.cuda::complex<T>: trivially copyable whenTis.Aggregates: trivially copyable when all their members are.
On MSVC, recursive data-member inspection is not supported beyond the first level.
const qualification is handled transparently, while volatile is compiler dependent.
Examples#
#include <cuda/type_traits>
#include <cuda/std/array>
#include <cuda/std/tuple>
#include <cuda/std/utility>
#include <cuda_fp16.h>
// Standard trivially copyable types
static_assert(cuda::is_trivially_copyable_v<int>);
static_assert(cuda::is_trivially_copyable_v<float>);
// Extended floating-point types
static_assert(cuda::is_trivially_copyable_v<__half>);
static_assert(cuda::is_trivially_copyable_v<__nv_bfloat16>);
static_assert(cuda::is_trivially_copyable_v<__half2>);
static_assert(cuda::is_trivially_copyable_v<cuda::std::complex<__half>>);
static_assert(cuda::is_trivially_copyable_v<cuda::complex<__half>>);
// Composite types containing extended floating-point types
static_assert(cuda::is_trivially_copyable_v<__half[4]>);
static_assert(cuda::is_trivially_copyable_v<cuda::std::array<__half2, 4>>);
static_assert(cuda::is_trivially_copyable_v<cuda::std::pair<__half2, __half>>);
static_assert(cuda::is_trivially_copyable_v<cuda::std::tuple<__half, __half2>>);
static_assert(cuda::is_trivially_copyable_v<cuda::std::pair<__half2, int>>);