Question

Is it possible to set some parameters of template and leave the rest still as template parameters? Something like creating new template class, identical to the first but with smaller number of template parameters.

A can not explain that clearly. Maybe a few lines of code help.

template<int A, typename B>
class XXX
{
    //Some code
};

template<template<typename> class C>
class YYY
{
    //Some code
};

template<int D>
class ZZZ
{
    YYY<XXX<D> > object; //This is wrong. How to do it?
};

I can't find any mechanism that makes this possible.

EDIT I selected the example improperly. The class ZZZ should look like:

template<int D>
class ZZZ : public YYY<XXX<D> >
{
    //Some code
};
Was it helpful?

Solution

template<class T>using WWW=XXX<D,T>;

or, if you have no space to do a using argument:

template<int D>struct WW{
  template<class T>using W=XXX<D,T>;
};

template<int D>
class ZZZ : public YYY<WW<D>::template W>

I advise using different names.

OTHER TIPS

Yakk's answer made ​​me realize that I can create structure which will define new class.

template<int E>
struct SetPrameter
{
    template<typename T>
    using XXX = XXX<E, T>;
};

I can use it this way:

template<int D>
class ZZZ : public YYY<typename SetPrameter<D>::XXX>
{
    //Some code
};
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top