Elements 6.3.3
A C++ base framework for the Euclid Software.
Loading...
Searching...
No Matches
FuncPtrCast.tpp
Go to the documentation of this file.
1
20
21// IWYU pragma: private, include "ElementsKernel/FuncPtrCast.h"
22
23#ifndef ELEMENTSKERNEL_ELEMENTSKERNEL_FUNCPTRCAST_IMPL_
24#error "This file should not be included directly! Use ElementsKernel/FuncPtrCast.h instead"
25#else
26
27#include <cstring> // for memcpy
28#include <type_traits> // for is_pointer
29
30namespace Elements {
31
32namespace System {
33
34template <typename DESTPTR, typename SRC>
35constexpr DESTPTR FuncPtrCast(SRC* const src_p) noexcept {
36 static_assert(std::is_pointer<DESTPTR>::value, "must be a pointer");
37 DESTPTR dst_p = nullptr; // must initialize to be a valid constexpr...
38 std::memcpy(&dst_p, &src_p, sizeof(dst_p));
39 return dst_p;
40}
41
42} // namespace System
43
44} // namespace Elements
45
46#endif // ELEMENTSKERNEL_ELEMENTSKERNEL_FUNCPTRCAST_IMPL_
constexpr DESTPTR FuncPtrCast(SRC *const src_p) noexcept
Cast from void * to function pointer.
T memcpy(T... args)