Dune Core Modules (2.10.0)
A wrapper providing small object optimization with polymorphic types. More...
#include <dune/functions/common/polymorphicsmallobject.hh>
Public Member Functions | |
PolymorphicSmallObject () | |
Default constructor. | |
template<class Derived , std::enable_if_t< std::is_base_of_v< Base, std::remove_cv_t< std::remove_reference_t< Derived > > >, int > = 0> | |
PolymorphicSmallObject (Derived &&derived) | |
Construct from object. More... | |
PolymorphicSmallObject (PolymorphicSmallObject &&other) noexcept | |
Move constructor from other PolymorphicSmallObject. | |
PolymorphicSmallObject (const PolymorphicSmallObject &other) | |
Copy constructor from other PolymorphicSmallObject. | |
~PolymorphicSmallObject () | |
Destructor. | |
PolymorphicSmallObject & | operator= (const PolymorphicSmallObject &other) |
Copy assignment from other PolymorphicSmallObject. | |
PolymorphicSmallObject & | operator= (PolymorphicSmallObject &&other) noexcept |
Move assignment from other PolymorphicSmallObject. | |
operator bool () const | |
Check if *this is not empty. | |
bool | bufferUsed () const |
Check if object is stored in internal stack buffer. | |
const Base & | get () const |
Obtain reference to stored object. | |
Base & | get () |
Obtain mutable reference to stored object. | |
Detailed Description
class Dune::Functions::PolymorphicSmallObject< Base, bufferSize >
A wrapper providing small object optimization with polymorphic types.
- Template Parameters
-
Base Base class type of wrapped objects bufferSize Size of small object buffer
This class encapsulates small object optimization for polymorphic types. The type of objects passed to the constructor must be derived from the base class type Base.
If the size of the derived type fits into the static buffer, then the wrapped object is stored there, otherwise it is allocated dynamically.
Notice that this class does implement use type erasure for destructors, copy/move constructors and copy/move assignment. Hence it requires that Base has a virtual destructor.
In order to make the copy constructor work for polymorphic types, Base must provide virtual methods Base* clone()
and Base* clone(void*)
. The former should return a pointer to a dynamically allocated clone, while the latter should call the appropriate placement-new with the passed pointer.
Similarly the polymorphic type has to implement a virtual Base* move(void*)
method. This should call placement-new and can std::move all the data but leave the object in a valid and probably unusable state.
Constructor & Destructor Documentation
◆ PolymorphicSmallObject()
|
inline |
Construct from object.
- Template Parameters
-
Derived Type of object to be stored, must be derived from Base
- Parameters
-
derived Object to be stored
The documentation for this class was generated from the following file:
- dune/functions/common/polymorphicsmallobject.hh