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)))
192 return wrapped_.get().target_type();
204 #endif // DUNE_FUNCTIONS_COMMON_TYPEERASURE_HH