DPC++ Runtime
Runtime libraries for oneAPI DPC++
impl_utils.hpp
Go to the documentation of this file.
1 //===- impl_utils.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 
9 #pragma once
10 
11 #include <cassert> // for assert
12 #include <type_traits> // for add_pointer_t
13 
14 namespace sycl {
15 inline namespace _V1 {
16 namespace detail {
17 
18 // Helper function for extracting implementation from SYCL's interface objects.
19 // Note! This function relies on the fact that all SYCL interface classes
20 // contain "impl" field that points to implementation object. "impl" field
21 // should be accessible from this function.
22 //
23 // Note that due to a bug in MSVC compilers (including MSVC2019 v19.20), it
24 // may not recognize the usage of this function in friend member declarations
25 // if the template parameter name there is not equal to the name used here,
26 // i.e. 'Obj'. For example, using 'Obj' here and 'T' in such declaration
27 // would trigger that error in MSVC:
28 // template <class T>
29 // friend decltype(T::impl) detail::getSyclObjImpl(const T &SyclObject);
30 template <class Obj>
31 const decltype(Obj::impl) &getSyclObjImpl(const Obj &SyclObject) {
32  assert(SyclObject.impl && "every constructor should create an impl");
33  return SyclObject.impl;
34 }
35 
36 // Helper function for creation SYCL interface objects from implementations.
37 // Note! This function relies on the fact that all SYCL interface classes
38 // contain "impl" field that points to implementation object. "impl" field
39 // should be accessible from this function.
40 template <class T> T createSyclObjFromImpl(decltype(T::impl) ImplObj) {
41  return T(ImplObj);
42 }
43 
44 } // namespace detail
45 } // namespace _V1
46 } // namespace sycl
decltype(Obj::impl) const & getSyclObjImpl(const Obj &SyclObject)
Definition: impl_utils.hpp:31
T createSyclObjFromImpl(decltype(T::impl) ImplObj)
Definition: impl_utils.hpp:40
Definition: access.hpp:18