次のパターンに従う2セットのミックスイン基本クラスがあります
// base class taking one contructor argument
struct OneArgBase
{
const double x;
template<typename T>
OneArgBase(const T & t) :
x(t.x)
{}
};
// base class taking two constructor arguments
struct TwoArgBase
{
const double y;
template<typename T, typename U>
TwoArgBase(const T & t, const U & u) :
y(t.y + u.y)
{}
};
これらの基本クラスから、2 セットの mixin クラスを派生させます
template<typename ... Mixins>
struct OneArgMix : Mixins...
{
template<typename T>
OneArgsMix(const T & t) :
Mixins(t)...
{}
};
template<typename ... Mixins>
struct TwoArgMix : Mixins...
{
template<typename T, typename U>
TwoArgsMix(const T & t, const U & u) :
Mixins(t, u)...
{}
};
私が今直面している問題は、OneArgBase パターンに従ってクラスを TwoArgMix に渡したいということです
using Mix = TwoArgMix<TwoArgBase, OneArgBase>;
template<typename ... Mixins>
struct TwoArgMix : Mixins...
{
template<typename T, typename U>
TwoArgsMix(const T & t, const U & u) :
Mixins(t, u)... // if Mixins is TwoArgBase
Mixins(t)... // if Mixins is OneArgBase
{}
};
しかし、OneArgMix パターンに従う Mixin 基本クラスに最初のテンプレート パラメーターのみを渡す場合に、TwoArgMix のコンストラクターをどのように記述するかはわかりません。これらのクラスは OneArgMix にも必要であるため、可能であれば、OneArgMix コンストラクターにダミー引数を書き込むことは避けたいと思います。