テンプレートの特殊化で遊んでいますが、解決できないと思われる問題を見つけました。これは私のコードです:
template<int length, typename T>
void test(T* array)
{
...
test<length-1>(array);
}
template<typename T>
void test<0>(T* array)
{
return;
}
だから私がやろうとしているのは、テンプレートで処理されるものの長さを渡すことです。
問題は、これをコンパイルすると、永久に出力されることです。
a.cpp:83:43: error: template-id 'test<0>' in declaration of primary template
a.cpp: In function 'void test(T*) [with int length= -0x000000081, T = int]':
a.cpp:77:9: instantiated from 'void test(T*) [with int length= -0x000000080, T = int]'
a.cpp:77:9: instantiated from 'void test(T*) [with int length= -0x00000007f, T = int]'
a.cpp:77:9: [ skipping 151 instantiation contexts ]
a.cpp:77:9: instantiated from 'void test(T*) [with int length= 28, T = int]'
a.cpp:77:9: instantiated from 'void test(T*) [with int length= 29, T = int]'
...
a.cpp: In function 'void test(T*) [with int length= -0x000000082, T = int]':
a.cpp:77:9: instantiated from 'void test(T*) [with int length= -0x000000081, T = int]'
a.cpp:77:9: instantiated from 'void test(T*) [with int length= -0x000000080, T = int]'
最後の2行は、最初の行とほとんど同じです。
私には、専門分野を捉えていないように思われるので、次のようになります。
a.cpp:83:43: error: template-id 'test<0>' in declaration of primary template
私は正しいですか?
そして、私が正しければ、部分的なテンプレートの特殊化が関数テンプレートに許可されていないという問題だと思います。それでは、構造体を作成し、それに特殊化を使用することで、どのような解決策がありますか?