3 #ifndef DUNE_FUNCTIONS_COMMON_TYPEERASURE_HH 4 #define DUNE_FUNCTIONS_COMMON_TYPEERASURE_HH 8 #include <dune/common/typeutilities.hh> 33 template<
class Interface>
34 class TypeErasureWrapperInterface :
36 public PolymorphicType<TypeErasureWrapperInterface<Interface>>
39 virtual const std::type_info& target_type()
const = 0;
60 template<
class Interface,
class T>
61 class TypeErasureWrapperBase :
62 public TypeErasureWrapperInterface<Interface>
65 template<
class TT, disableCopyMove<TypeErasureWrapperBase, TT> = 0>
66 TypeErasureWrapperBase(TT&& t) :
67 wrapped_(
std::forward<TT>(t))
112 template<
class Interface,
template<
class>
class Implementation,
class T>
113 class TypeErasureWrapperImplementation :
114 public Implementation<TypeErasureWrapperBase<Interface, T> >
119 template<
class TT, disableCopyMove<TypeErasureWrapperImplementation, T> = 0>
120 TypeErasureWrapperImplementation(TT&& t) :
121 Implementation<TypeErasureWrapperBase<Interface, T> >(
std::forward<TT>(t))
125 virtual TypeErasureWrapperImplementation* clone()
const 127 return new TypeErasureWrapperImplementation(*
this);
131 virtual TypeErasureWrapperImplementation* clone(
void* buffer)
const 133 return new (buffer) TypeErasureWrapperImplementation(*
this);
137 virtual TypeErasureWrapperImplementation* move(
void* buffer)
139 return new (buffer) TypeErasureWrapperImplementation(std::move(*
this));
143 virtual const std::type_info& target_type()
const 163 template<
class Interface,
template<
class>
class Implementation,
size_t bufferSize = 56>
169 template<
class T, disableCopyMove<TypeErasureBase, T> = 0 >
171 wrapped_(Imp::TypeErasureWrapperImplementation<Interface, Implementation, typename
std::decay<T>::type>(
std::forward<T>(t)))
180 return wrapped_.get();
186 return wrapped_.get();
192 return wrapped_.get().target_type();
204 #endif // DUNE_FUNCTIONS_COMMON_TYPEERASURE_HH
Base class for type-erased interface wrapper.
Definition: typeerasure.hh:164
const Interface & asInterface() const
Get reference to wrapped object.
Definition: typeerasure.hh:184
A wrapper providing small object optimization with polymorphic types.
Definition: polymorphicsmallobject.hh:46
PolymorphicSmallObject< Imp::TypeErasureWrapperInterface< Interface >, bufferSize > wrapped_
Definition: typeerasure.hh:196
virtual const std::type_info & target_type() const
Get type of stored object.
Definition: typeerasure.hh:190
Interface & asInterface()
Get mutable reference to wrapped object.
Definition: typeerasure.hh:178
TypeErasureBase(T &&t)
Construct wrapper from object.
Definition: typeerasure.hh:170
Definition: polynomial.hh:7