DUNE PDELab (git)

Dune::Functions::PolymorphicSmallObject< Base, bufferSize > Class Template Reference

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.
 
PolymorphicSmallObjectoperator= (const PolymorphicSmallObject &other)
 Copy assignment from other PolymorphicSmallObject.
 
PolymorphicSmallObjectoperator= (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

template<class Base, size_t bufferSize>
class Dune::Functions::PolymorphicSmallObject< Base, bufferSize >

A wrapper providing small object optimization with polymorphic types.

Template Parameters
BaseBase class type of wrapped objects
bufferSizeSize 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()

template<class Base , size_t bufferSize>
template<class Derived , std::enable_if_t< std::is_base_of_v< Base, std::remove_cv_t< std::remove_reference_t< Derived > > >, int > = 0>
Dune::Functions::PolymorphicSmallObject< Base, bufferSize >::PolymorphicSmallObject ( Derived &&  derived)
inline

Construct from object.

Template Parameters
DerivedType of object to be stored, must be derived from Base
Parameters
derivedObject to be stored

The documentation for this class was generated from the following file:
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 23, 23:29, 2024)