Специализация шаблонов C ++ для функций

Я экспериментирую со специализацией шаблонов и обнаружил проблему, которую не могу решить; это мой код:

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

Я прав?

И если я прав, Я предполагаю, что проблема в том, что частичная специализация шаблонов недопустима для шаблонов функций, так что же тогда будет решением, создав структуру и используя для нее специализацию?

15
задан Skeen 8 July 2011 в 10:46
поделиться