Я играю со специализацией по шаблонам и обнаружил проблему, которую не могу решить; это мой код:
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]'
Последние две строки в значительной степени совпадают с первыми.
Мне кажется, это не ловит специализацию, следовательно:
a.cpp:83:43: error: template-id 'test<0>' in declaration of primary template
Я прав?
И если я прав, я полагаю, что проблема в том, что частичная специализация шаблонов не разрешена для шаблонов функций, так что же тогда будет решением, создание структуры и использование специализации на этом?