alpaka
Abstraction Library for Parallel Kernel Acceleration
Loading...
Searching...
No Matches
util.hpp
Go to the documentation of this file.
1/* Copyright 2024 René Widera
2 * SPDX-License-Identifier: MPL-2.0
3 */
4
5#pragma once
6
8
9#include <cstdio>
10#include <tuple>
11#include <utility>
12
13namespace alpaka
14{
15 template<typename T>
16 constexpr decltype(auto) unWrapp(T&& value)
17 {
18 using WrappedType = std::unwrap_reference_t<std::decay_t<decltype(value)>>;
19 return std::unwrap_reference_t<WrappedType>(std::forward<T>(value));
20 }
21
22 template<typename T>
23 using RemoveVolatileFromPointer_t = std::add_pointer_t<std::remove_volatile_t<std::remove_pointer_t<T>>>;
24
25 /**
26 * @brief Cast a pointer that may or may not point to volatile memory to a (void*) or (void const*).
27 *
28 * Useful for freeing the memory.
29 *
30 * @param inPtr The pointer to convert.
31 * @tparam T The type of the given pointer.
32 */
33 template<typename T>
34 auto* toVoidPtr(T inPtr)
35 {
36 static_assert(std::is_pointer_v<T>);
37 using DataType = std::remove_pointer_t<T>;
38 using VoidPtrType = std::conditional_t<std::is_const_v<DataType>, void const*, void*>;
39 return reinterpret_cast<VoidPtrType>(const_cast<RemoveVolatileFromPointer_t<T>>(inPtr));
40 }
41} // namespace alpaka
main alpaka namespace.
Definition alpaka.hpp:76
constexpr decltype(auto) unWrapp(T &&value)
Definition util.hpp:16
auto * toVoidPtr(T inPtr)
Cast a pointer that may or may not point to volatile memory to a (void*) or (void const*).
Definition util.hpp:34
std::add_pointer_t< std::remove_volatile_t< std::remove_pointer_t< T > > > RemoveVolatileFromPointer_t
Definition util.hpp:23