DPC++ Runtime
Runtime libraries for oneAPI DPC++
is_device_copyable.hpp
Go to the documentation of this file.
1 //==------------ is_device_copyable.hpp - ----------------------------------==//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 #pragma once
9 
10 #include <array>
11 #include <optional>
12 #include <type_traits>
13 #include <variant>
14 
18 #define SYCL_DEVICE_COPYABLE 1
19 
20 namespace sycl {
21 inline namespace _V1 {
29 template <typename T> struct is_device_copyable;
30 
31 namespace detail {
32 template <typename T, typename = void>
33 struct is_device_copyable_impl : std::is_trivially_copyable<T> {};
34 
35 template <typename T>
37  T, std::enable_if_t<!std::is_same_v<T, std::remove_cv_t<T>>>>
38  // Cannot express this "recursion" (to take user's partial non-cv
39  // specializations into account) without this helper struct.
40  : is_device_copyable<std::remove_cv_t<T>> {};
41 } // namespace detail
42 
43 template <typename T>
45 
46 // std::array<T, 0> is implicitly device copyable type.
47 template <typename T>
48 struct is_device_copyable<std::array<T, 0>> : std::true_type {};
49 
50 // std::array<T, N> is implicitly device copyable type if T is device copyable.
51 template <typename T, std::size_t N>
52 struct is_device_copyable<std::array<T, N>> : is_device_copyable<T> {};
53 
54 // std::optional<T> is implicitly device copyable type if T is device copyable.
55 template <typename T>
56 struct is_device_copyable<std::optional<T>> : is_device_copyable<T> {};
57 
58 // std::pair<T1, T2> is implicitly device copyable type if T1 and T2 are device
59 // copyable.
60 template <typename T1, typename T2>
61 struct is_device_copyable<std::pair<T1, T2>>
62  : std::bool_constant<is_device_copyable<T1>::value &&
63  is_device_copyable<T2>::value> {};
64 
65 // std::tuple<Ts...> is implicitly device copyable type if each type T of Ts...
66 // is device copyable.
67 template <typename... Ts>
68 struct is_device_copyable<std::tuple<Ts...>>
69  : std::bool_constant<(... && is_device_copyable<Ts>::value)> {};
70 
71 // std::variant<Ts...> is implicitly device copyable type if each type T of
72 // Ts... is device copyable.
73 template <typename... Ts>
74 struct is_device_copyable<std::variant<Ts...>>
75  : std::bool_constant<(... && is_device_copyable<Ts>::value)> {};
76 
77 // array is device copyable if element type is device copyable.
78 template <typename T, std::size_t N>
80 
81 template <typename T>
83 } // namespace _V1
84 } // namespace sycl
constexpr bool is_device_copyable_v
Definition: access.hpp:18
is_device_copyable is a user specializable class template to indicate that a type T is device copyabl...