B
Bo Peng
Dear List,
I have a class that may or may not have several features. For example,
there might be "partition" to d_data of obj. The code is like (please
ignore grammar mistakes):
template<typename T>
struct obj
{
vector<T> d_data;
obj(T init_value);
};
template<typename T>
struct Partition
{
vector<int> d_index;
Partition(vector<int> ind);
};
I do not want to create templates for each combination of features so I
would like to use something like a policy-based design:
template<typename T,
template <class s> class feature1,
template <class s> class feature2>
struct obj: public feature1<T>, feature2<T>
{
vector<T> d_data;
obj(T init_value);
};
typedef template<int, Partition> intDataWithPartition;
In this way, I can get data member d_index (and methods to operate on
it) from Parition class. However, this will not work since I can not
provide constructor to Partition<T> from obj:bj(). Is there any
workaround? Am I going a totally wrong way?
Many thanks in advance.
Bo
I have a class that may or may not have several features. For example,
there might be "partition" to d_data of obj. The code is like (please
ignore grammar mistakes):
template<typename T>
struct obj
{
vector<T> d_data;
obj(T init_value);
};
template<typename T>
struct Partition
{
vector<int> d_index;
Partition(vector<int> ind);
};
I do not want to create templates for each combination of features so I
would like to use something like a policy-based design:
template<typename T,
template <class s> class feature1,
template <class s> class feature2>
struct obj: public feature1<T>, feature2<T>
{
vector<T> d_data;
obj(T init_value);
};
typedef template<int, Partition> intDataWithPartition;
In this way, I can get data member d_index (and methods to operate on
it) from Parition class. However, this will not work since I can not
provide constructor to Partition<T> from obj:bj(). Is there any
workaround? Am I going a totally wrong way?
Many thanks in advance.
Bo