7 #ifndef PXR_EXEC_VDF_FIXED_SIZE_POLYMORPHIC_HOLDER_H
8 #define PXR_EXEC_VDF_FIXED_SIZE_POLYMORPHIC_HOLDER_H
17 #include <type_traits>
35 template <
class Base,
size_t BufferSize>
41 using _Storage =
typename std::aligned_storage_t<BufferSize, sizeof(void *)>;
58 template <
class Derived,
class ... Args>
62 "Derived is not a derived class of Base.");
64 sizeof(Derived) <=
sizeof(_Storage),
65 "The size of the derived type is larger than the availble storage.");
67 alignof(_Storage) %
alignof(Derived) == 0,
68 "The derived type has incompatible alignment.");
69 new (_GetStorage()) Derived(std::forward<Args>(
args)...);
73 static_cast<Base *
>(
static_cast<Derived *
>(_GetStorage()));
82 #if defined(ARCH_COMPILER_GCC) && ARCH_COMPILER_GCC_MAJOR < 11
87 #if defined(ARCH_COMPILER_GCC) && ARCH_COMPILER_GCC_MAJOR < 11
93 inline Base
const *
Get()
const {
94 return static_cast<Base
const *
>(_GetStorage());
99 return static_cast<Base *
>(_GetStorage());
105 inline void *_GetStorage() {
110 inline void const *_GetStorage()
const {
#define PXR_NAMESPACE_OPEN_SCOPE
GLsizei const GLfloat * value
Base * Get()
Returns a Base pointer to the held instance.
Vdf_FixedSizePolymorphicHolder()=default
#define ARCH_PRAGMA_MAYBE_UNINITIALIZED
Base const * Get() const
Returns a Base pointer to the held instance.
#define PXR_NAMESPACE_CLOSE_SCOPE
**If you just want to fire and args
Vdf_FixedSizePolymorphicHolder & operator=(Vdf_FixedSizePolymorphicHolder const &)=delete