Tomographer
v5.3
Tomographer C++ Framework Documentation
|
Provide appropriate operator new()
definitions for a structure which has a member of the given stored types.
More...
#include <tomographer/tools/needownoperatornew.h>
Provide appropriate operator new()
definitions for a structure which has a member of the given stored types.
Some types require a specific implementation of operator new()
, such as Eigen (see this page). Hence, if a class has an Eigen member, it needs to make sure to have the appropriate implementations of operator new()
.
Because in our generic classes, we may be requried to store types (as members), such as a PointType in a random walk, and we can't assume it will be an Eigen object. The solution is that those objects inherit NeedOwnOperatorNew<PointType>::ProviderType, such that proper operator-new definitions can be generated by appropriate specializations of NeedOwnOperatorNew.
The template arguments are a list of types, which could potentially require having appropriate operator new()
implementations if such a type is a class member. Just inherit NeedOwnOperatorNew<Type1, Type2, ...>::ProviderType
and (provided the types don't have conflicting requirements for special operator-new implementations) the correct implementation of operator-new (if any is required) will be used automatically.
If a specific type T needs a particular operator-new requirement (such as Eigen types), the first thing to do is define the requested operator new definitions inside a "provider type" class (see, for example, EigenAlignedOperatorNewProvider). This class should expose the correct operator new definition.
Then, you should specialize the template class NeedOwnOperatorNew for your type, and expose a ProviderType typedef to your operator-new provider class. Make sure you delete the default constructor as a safe-guard, to avoid unadvertently inheriting NeedOwnOperatorNew<T>
instead of NeedOwnOperatorNew<T>::ProviderType
. For instance:
The template specialization may of course also have further template parameters, i.e., partial specialization (see for example: the specialization for Eigen Matrix types).
Definition at line 145 of file needownoperatornew.h.