7 #ifndef PXR_EXEC_ESF_FIXED_SIZE_POLYMORPHIC_HOLDER_H
8 #define PXR_EXEC_ESF_FIXED_SIZE_POLYMORPHIC_HOLDER_H
21 #include <type_traits>
37 template <
class Base,
size_t BufferSize>
76 template <
class Base,
size_t BufferSize = sizeof(Base)>
79 static_assert(std::is_base_of_v<EsfFixedSizePolymorphicBase, Base>);
80 constexpr
static size_t _REQUIRED_ALIGNMENT =
alignof(Base);
98 template <
class Derived,
class... Args>
100 std::in_place_type_t<Derived> derivedTypeHint, Args &&...
args);
106 other->_CopyTo(_storage);
116 other->_MoveTo(_storage);
132 if (
this != &other) {
134 other->_CopyTo(_storage);
147 if (
this != &other) {
149 other->_MoveTo(_storage);
160 return reinterpret_cast<Base *
>(_storage);
163 inline const Base *
Get()
const {
164 return reinterpret_cast<const Base *
>(_storage);
192 template <
class Derived>
195 template <
class Derived>
197 std::is_base_of_v<Base, Derived>;
199 template <
class Derived>
201 alignof(Derived) == _REQUIRED_ALIGNMENT;
209 template <
class Derived>
215 template <
class Derived>
216 class _Holder :
public Derived
220 template <
class... Args>
221 _Holder(Args &&...
args) : Derived(std::forward<Args>(
args)...) {
227 const Derived *thisDerived =
static_cast<const Derived *
>(
this);
228 ::new (static_cast<void *>(
storage)) _Holder<Derived>(*thisDerived);
232 Derived *thisDerived =
static_cast<Derived *
>(
this);
233 ::new (static_cast<void *>(
storage)) _Holder<Derived>(
234 std::move(*thisDerived));
239 alignas(_REQUIRED_ALIGNMENT) std::
byte _storage[BufferSize];
242 template <
class Base,
size_t BufferSize>
245 std::in_place_type_t<Derived> derivedTypeHint, Args &&...
args)
250 Compatibility::template FITS_IN_BUFFER<Derived>,
251 "The size of the derived type is larger than the availble "
254 Compatibility::template DERIVES_FROM_BASE<Derived>,
255 "Derived is not a derived class of Base.");
257 Compatibility::template HAS_ALIGNMENT<Derived>,
258 "The derived type has incompatible alignment.");
260 ::new (static_cast<void *>(_storage)) _Holder<Derived>(
261 std::forward<Args>(
args)...);
264 template <
class Base,
size_t BufferSize>
265 template <
class Derived>
270 if constexpr (!DERIVES_FROM_BASE<Derived>) {
274 const Base *base =
static_cast<const Base *
>(&derived);
275 const void *baseAddress =
static_cast<const void *
>(base);
276 const void *derivedAddress =
static_cast<const void *
>(&derived);
277 return baseAddress == derivedAddress;
static constexpr bool HAS_ALIGNMENT
*get result *(waiting if necessary)*A common idiom is to fire a bunch of sub tasks at the and then *wait for them to all complete We provide a helper class
getFileOption("OpenEXR:storage") storage
#define PXR_NAMESPACE_OPEN_SCOPE
const Base * operator->() const
const Base & operator*() const
static constexpr bool FITS_IN_BUFFER
EsfFixedSizePolymorphicHolder(const This &other)
This & operator=(This &&other)
EsfFixedSizePolymorphicHolder()=delete
~EsfFixedSizePolymorphicHolder()
#define PXR_NAMESPACE_CLOSE_SCOPE
EsfFixedSizePolymorphicHolder(This &&other)
**If you just want to fire and args
static constexpr bool DERIVES_FROM_BASE
This & operator=(const This &other)
static bool HasBaseAtSameAddress(const Derived &derived)