7#ifndef DUNE_FUNCTIONS_COMMON_TYPEERASURE_HH
8#define DUNE_FUNCTIONS_COMMON_TYPEERASURE_HH
12#include <dune/common/typeutilities.hh>
14#include <dune/functions/common/type_traits.hh>
15#include <dune/functions/common/interfaces.hh>
16#include <dune/functions/common/polymorphicsmallobject.hh>
37template<
class Interface>
38class TypeErasureWrapperInterface :
40 public PolymorphicType<TypeErasureWrapperInterface<Interface>>
43 virtual const std::type_info& target_type()
const = 0;
64template<
class Interface,
class T>
65class TypeErasureWrapperBase :
66 public TypeErasureWrapperInterface<Interface>
69 template<
class TT, disableCopyMove<TypeErasureWrapperBase, TT> = 0>
70 TypeErasureWrapperBase(TT&& t) :
71 wrapped_(std::forward<TT>(t))
116template<
class Interface,
template<
class>
class Implementation,
class T>
117class TypeErasureWrapperImplementation :
118 public Implementation<TypeErasureWrapperBase<Interface, T> >
123 template<
class TT, disableCopyMove<TypeErasureWrapperImplementation, T> = 0>
124 TypeErasureWrapperImplementation(TT&& t) :
125 Implementation<TypeErasureWrapperBase<Interface, T> >(std::forward<TT>(t))
129 virtual TypeErasureWrapperImplementation* clone()
const
131 return new TypeErasureWrapperImplementation(*
this);
135 virtual TypeErasureWrapperImplementation* clone(
void* buffer)
const
137 return new (buffer) TypeErasureWrapperImplementation(*
this);
141 virtual TypeErasureWrapperImplementation* move(
void* buffer)
143 return new (buffer) TypeErasureWrapperImplementation(std::move(*
this));
147 virtual const std::type_info& target_type()
const
167template<
class Interface,
template<
class>
class Implementation,
size_t bufferSize = 56>
173 template<
class T, disableCopyMove<TypeErasureBase, T> = 0 >
175 wrapped_(Imp::TypeErasureWrapperImplementation<Interface, Implementation, std::decay_t<T>>(std::forward<T>(t)))
184 return wrapped_.get();
190 return wrapped_.get();
196 return wrapped_.get().target_type();
A wrapper providing small object optimization with polymorphic types.
Definition: polymorphicsmallobject.hh:51
Base class for type-erased interface wrapper.
Definition: typeerasure.hh:169
const std::type_info & target_type() const
Get type of stored object.
Definition: typeerasure.hh:194
TypeErasureBase(T &&t)
Construct wrapper from object.
Definition: typeerasure.hh:174
TypeErasureBase()=default
Default constructor.
Interface & asInterface()
Get mutable reference to wrapped object.
Definition: typeerasure.hh:182
const Interface & asInterface() const
Get reference to wrapped object.
Definition: typeerasure.hh:188
Definition: polynomial.hh:17