Skip to content

Commit dfe6969

Browse files
committed
Simple cast examples
1 parent b60dd94 commit dfe6969

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

multi_ptr-cast/sycl-2.2/index.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,3 +149,42 @@ template <typename ElementTypeU, typename ElementTypeT, access::address_space Sp
149149
| *`multi_ptr<ElementTypeU, Space> const_pointer_cast(const multi_ptr<ElementTypeT, Space>& multiPtr)`* | Performs a `const_cast` of the underlying pointer `ElementTypeT*` contained within `multiPtr` to `ElementTypeU*` and returns a new `multi_ptr` instance containing the cast pointer. The address space stays the same. This conversion is only valid if the `const_cast` from `ElementType*` to `ElementTypeU*` is valid. |
150150
| *`multi_ptr<ElementTypeU, Space> reinterpret_pointer_cast(const multi_ptr<ElementTypeT, Space>& multiPtr)`* | Performs a `reinterpret_cast` of the underlying pointer `ElementTypeT*` contained within `multiPtr` to `ElementTypeU*` and returns a new `multi_ptr` instance containing the cast pointer. The address space stays the same. This conversion is only valid if the `reinterpret_cast` from `ElementType*` to `ElementTypeU*` is valid. |
151151

152+
## Examples
153+
154+
### Simple casts
155+
156+
These examples focus on `global_ptr` for brevity,
157+
but it works the same for all `multi_ptr` types.
158+
159+
```cpp
160+
using namespace cl::sycl;
161+
const global_ptr<int> ptrInt = get_some_global_ptr();
162+
163+
// Conversion operator
164+
auto ptrFloat1 = static_cast<global_ptr<float>>(ptrInt);
165+
auto ptrVoid1 = static_cast<global_ptr<void>>(ptrInt);
166+
auto ptrConstInt1 = static_cast<global_ptr<const int>>(ptrInt);
167+
168+
// static_pointer_cast
169+
auto ptrFloat2 = static_pointer_cast<float>(ptrInt);
170+
auto ptrVoid2 = static_pointer_cast<void>(ptrInt);
171+
auto ptrConstInt2 = static_pointer_cast<const int>(ptrInt);
172+
173+
// const_pointer_cast
174+
auto ptrConstInt3 = const_pointer_cast<const int>(ptrInt);
175+
// auto ptrIntStripConst = static_cast<global_ptr<int>>(ptrConstInt1); // illegal
176+
auto ptrIntStripConst = const_pointer_cast<int>(ptrConstInt1);
177+
178+
// reinterpret_pointer_cast
179+
auto ptrFloat4 = reinterpret_pointer_cast<float>(ptrInt);
180+
auto ptrVoid4 = reinterpret_pointer_cast<void>(ptrInt);
181+
auto ptrConstInt4 = reinterpret_pointer_cast<const int>(ptrInt);
182+
```
183+
184+
### `dynamic_pointer_cast`
185+
186+
TODO(Peter)
187+
188+
### Passing `multi_ptr` to functions
189+
190+
TODO(Peter)

0 commit comments

Comments
 (0)