3#ifndef DUNE_FUNCTIONS_COMMON_TYPEERASURE_HH
4#define DUNE_FUNCTIONS_COMMON_TYPEERASURE_HH
10#include <dune/functions/common/type_traits.hh>
11#include <dune/functions/common/interfaces.hh>
12#include <dune/functions/common/polymorphicsmallobject.hh>
33template<
class Interface>
34class TypeErasureWrapperInterface :
36 public PolymorphicType<TypeErasureWrapperInterface<Interface>>
39 virtual const std::type_info& target_type()
const = 0;
60template<
class Interface,
class T>
61class TypeErasureWrapperBase :
62 public TypeErasureWrapperInterface<Interface>
65 template<
class TT, disableCopyMove<TypeErasureWrapperBase, TT> = 0>
66 TypeErasureWrapperBase(TT&& t) :
67 wrapped_(
std::forward<TT>(t))
112template<
class Interface,
template<
class>
class Implementation,
class T>
113class 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
163template<
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();
A wrapper providing small object optimization with polymorphic types.
Definition: polymorphicsmallobject.hh:45
Base class for type-erased interface wrapper.
Definition: typeerasure.hh:165
const std::type_info & target_type() const
Get type of stored object.
Definition: typeerasure.hh:190
TypeErasureBase(T &&t)
Construct wrapper from object.
Definition: typeerasure.hh:170
TypeErasureBase()=default
Default constructor.
Interface & asInterface()
Get mutable reference to wrapped object.
Definition: typeerasure.hh:178
const Interface & asInterface() const
Get reference to wrapped object.
Definition: typeerasure.hh:184
Communication interface between remote and local indices.
Definition: interface.hh:209
Dune namespace.
Definition: alignedallocator.hh:13
Utilities for type computations, constraining overloads, ...