DPC++ Runtime
Runtime libraries for oneAPI DPC++
traits.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  *
3  * Copyright (C) Codeplay Software Ltd.
4  *
5  * Part of the LLVM Project, under the Apache License v2.0 with LLVM
6  * Exceptions. See https://llvm.org/LICENSE.txt for license information.
7  * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  *
15  * SYCL compatibility extension
16  *
17  * traits.hpp
18  *
19  * Description:
20  * Type traits for the SYCL compatibility extension
21  **************************************************************************/
22 
23 #pragma once
24 
25 #include <cstddef>
26 #include <type_traits>
27 
28 namespace syclcompat {
29 
30 // Equivalent to C++20's std::type_identity (used to create non-deduced
31 // contexts)
32 template <class T> struct type_identity {
33  using type = T;
34 };
35 template <class T> using type_identity_t = typename type_identity<T>::type;
36 
37 // Defines the operand type for arithemtic operations on T. This is identity
38 // for all types except pointers, for which it is std::ptrdiff_t
39 template <typename T> struct arith {
40  using type = std::conditional_t<std::is_pointer_v<T>, std::ptrdiff_t, T>;
41 };
42 template <typename T> using arith_t = typename arith<T>::type;
43 
44 } // namespace syclcompat
typename type_identity< T >::type type_identity_t
Definition: traits.hpp:35
typename arith< T >::type arith_t
Definition: traits.hpp:42
std::conditional_t< std::is_pointer_v< T >, std::ptrdiff_t, T > type
Definition: traits.hpp:40