Files
compute-runtime/shared/source/helpers/casts.h
Fabian Zwolinski d69bf76282 Rename r_pod_cast function to safePodCast
Rename is necessary, because NEO uses camelCase convention for
function names.

Signed-off-by: Fabian Zwolinski <fabian.zwolinski@intel.com>
2022-05-19 10:43:20 +02:00

29 lines
757 B
C++

/*
* Copyright (C) 2018-2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#pragma once
#include <type_traits>
namespace NEO {
template <typename To, typename From>
constexpr To safePodCast(From *f) {
typedef typename std::remove_pointer<From>::type FromType;
typedef typename std::remove_pointer<To>::type ToType;
static_assert(std::is_trivially_copyable<FromType>::value &&
std::is_standard_layout<FromType>::value,
"Original cast type is not POD");
static_assert(std::is_trivially_copyable<ToType>::value &&
std::is_standard_layout<ToType>::value,
"Target cast type is not POD");
return reinterpret_cast<To>(f);
}
} // namespace NEO