You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
952 B
38 lines
952 B
#pragma once
|
|
|
|
#include <type_traits>
|
|
#include <cstddef>
|
|
|
|
template <typename T>
|
|
inline T* start_lifetime_as(void* p) noexcept
|
|
{
|
|
T* q = reinterpret_cast<T*>(p);
|
|
|
|
std::memcpy(q, q, sizeof(T));
|
|
return q;
|
|
}
|
|
|
|
template <typename T>
|
|
inline const T* start_lifetime_as(const void* p) noexcept
|
|
{
|
|
const T* q = reinterpret_cast<const T*>(p);
|
|
|
|
std::memcpy(const_cast<void*>(static_cast<const void*>(q)), q, sizeof(T));
|
|
return q;
|
|
}
|
|
|
|
template <typename T>
|
|
inline volatile T* start_lifetime_as(volatile void* p) noexcept
|
|
{
|
|
volatile T* q = reinterpret_cast<volatile T*>(p);
|
|
std::memcpy(const_cast<void*>(static_cast<volatile void*>(q)), q, sizeof(T));
|
|
return q;
|
|
}
|
|
|
|
template <typename T>
|
|
inline const volatile T* start_lifetime_as(const volatile void* p) noexcept
|
|
{
|
|
const volatile T* q = reinterpret_cast<const volatile T*>(p);
|
|
std::memcpy(const_cast<void*>(static_cast<const volatile void*>(q)), q, sizeof(T));
|
|
return q;
|
|
}
|