flatten 20260225
This commit is contained in:
46
tjp/core/in_place/InPlace.h
Executable file
46
tjp/core/in_place/InPlace.h
Executable file
@@ -0,0 +1,46 @@
|
||||
// TJP COPYRIGHT HEADER
|
||||
|
||||
// draft
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <tjp/core/types/Types.h>
|
||||
|
||||
namespace tjp {
|
||||
namespace core {
|
||||
|
||||
template<typename T, size_t size, size_t alignment>
|
||||
struct InPlace
|
||||
{
|
||||
struct Value {
|
||||
char memory [size];
|
||||
} __attribute__ ((aligned (alignment)));
|
||||
|
||||
Value v;
|
||||
|
||||
T *operator ->()
|
||||
{
|
||||
return (T *)&v.memory;
|
||||
}
|
||||
|
||||
T *operator ->() const
|
||||
{
|
||||
return (const T *)&v.memory;
|
||||
}
|
||||
|
||||
template<typename ... Args>
|
||||
InPlace(Args&& ... args)
|
||||
{
|
||||
(*this)->T(std::forward<Args>(args)...);
|
||||
static_assert(sizeof(T) == size);
|
||||
}
|
||||
|
||||
~InPlace ()
|
||||
{
|
||||
(*this)->~T();
|
||||
}
|
||||
} ;
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
Reference in New Issue
Block a user