私のクラスの1つは、テンプレート化された関数を宣言しています。
template<class A, class B>
A do_something(const std::vector<B> &data)
部分的に専門にしたいと思いtypename A
ます。B
は非常に最小限のインターフェースを実装するタイプのファミリーであり、私たちはそれらを多く使用しているので、私の専門分野はで一般的なものにしたいと思いB
ます。typename A
リターンタイプとしてのみ使用されているため、これは二重に厄介だと思います。
インターネットから、関数を部分的に特殊化できないことを収集したので、次のようにクラスを作成しました。
template<class A, class B>
class do_something_implementation {
public:
do_something_implementation(const std::vector<B> &data_) {
data = data_;
}
int do_something_implementation<int, B>::operator()() {
/* Complicated algorithm goes here... */
}
double do_something_implementation<double, B>::operator()() {
/* Different complicated algorithm goes here... */
}
private:
std::vector<B> data;
}
(Visual Studio 2008を使用して)それをコンパイルしようとすると、コンパイラがクラッシュし(!)、次のエラーが発生します。
fatal error C1001: An internal error has occurred in the compiler.
これは私の問題であり、コンパイラの問題ではないと思います。私が目指している部分的な特殊化を表現するためのより良い方法はありますか?