3 #ifndef DUNE_FUNCTIONS_COMMON_POLYMORPHICSMALLOBJECT_HH 4 #define DUNE_FUNCTIONS_COMMON_POLYMORPHICSMALLOBJECT_HH 37 template<
class Base,
size_t bufferSize>
53 template<
class Derived>
56 if (
sizeof(Derived)<bufferSize)
57 p_ =
new (buffer_) Derived(std::forward<Derived>(derived));
59 p_ =
new Derived(std::forward<Derived>(derived));
65 moveToWrappedObject(std::move(other));
71 copyToWrappedObject(other);
77 destroyWrappedObject();
83 destroyWrappedObject();
84 copyToWrappedObject(other);
91 destroyWrappedObject();
92 moveToWrappedObject(std::move(other));
97 explicit operator bool()
const 105 return ((
void*) (p_) == (
void*)(&buffer_));
109 const Base&
get()
const 122 void destroyWrappedObject()
135 if (other.bufferUsed())
136 p_ = other.p_->move(buffer_);
157 p_ = other.p_->clone(buffer_);
159 p_ = other.p_->clone();
163 alignas(Base)
char buffer_[bufferSize];
171 #endif // DUNE_FUNCTIONS_COMMON_POLYMORPHICSMALLOBJECT_HH Definition: polynomial.hh:7
PolymorphicSmallObject & operator=(PolymorphicSmallObject &&other)
Move assignment from other PolymorphicSmallObject.
Definition: polymorphicsmallobject.hh:89
PolymorphicSmallObject()
Default constructor.
Definition: polymorphicsmallobject.hh:43
~PolymorphicSmallObject()
Destructor.
Definition: polymorphicsmallobject.hh:75
PolymorphicSmallObject(const PolymorphicSmallObject &other)
Copy constructor from other PolymorphicSmallObject.
Definition: polymorphicsmallobject.hh:69
PolymorphicSmallObject & operator=(const PolymorphicSmallObject &other)
Copy assignment from other PolymorphicSmallObject.
Definition: polymorphicsmallobject.hh:81
PolymorphicSmallObject(Derived &&derived)
Construct from object.
Definition: polymorphicsmallobject.hh:54
bool bufferUsed() const
Check if object is stored in internal stack buffer.
Definition: polymorphicsmallobject.hh:103
A wrapper providing small object optimization with polymorphic types.
Definition: polymorphicsmallobject.hh:38
PolymorphicSmallObject(PolymorphicSmallObject &&other)
Move constructor from other PolymorphicSmallObject.
Definition: polymorphicsmallobject.hh:63