3
以下は、私がしようとしているものの例です。私は問題を説明するためにそれを使用しています。このため基本パラメータテンプレートテンプレートパラメータとして使用するデュアルパラメータテンプレートから単一パラメータテンプレートを作成する方法
#include <iostream>
using namespace std;
template <int STEP, bool SIDE> class Stepper {
int step(int x) {
return SIDE ? x + STEP : x - STEP;
}
};
template <template <bool> typename STEPPER> class DualStepper {
STEPPER<true> upStepper;
STEPPER<false> downStepper;
pair<int , int> step(int x) {
return pair<int , int>(upStepper.step(x), downStepper.step(x));
}
};
template <int STEP> class FixedDualStepper : public DualStepper<template <bool SIDE> using FT = Stepper<STEP, SIDE>> {
};
int main() {
FixedDualStepper<5> stepper;
pair<int, int> x = stepper.step(10);
cout << x.first << '\t' << x.second << endl;
return 0;
}
私はエラーを取得する:
/Work/Learn/04PartialTemplate/main.cpp:23:115: error: template argument 1 is invalid
template <int STEP> class FixedDualStepper : public DualStepper<template <bool SIDE> using FT = Stepper<STEP, SIDE>> {
^
/Work/Learn/04PartialTemplate/main.cpp: In function ‘int main()’:
/Work/Learn/04PartialTemplate/main.cpp:31:29: error: ‘class FixedDualStepper<5>’ has no member named ‘step’
pair<int, int> x = stepper.step(10);
は、私は望ましい効果を得るために
... : public DualStepper<???>
に使用できる構文があります。私。 Stepper
をSTEP
に設定し、DualStepper
のテンプレートテンプレートパラメータとして使用する単一のパラメータクラステンプレートを取得しますか?
。 – skypjack