template encounter empty array

I wrote a template function which use dynamic array as parameter. But if parameter is a empty array, it have compile error.

code:
#include <iostream>

int arry[] = {1,2,3};
int empty_arry[] = {};

template<int count>
void array_test(int (&iarry)[count])
{
std::cout << "count=" << count << std::endl;
}

int main (int argc, char* argv[])
{
array_test(arry);
array_test(empty_arry);
return 0;
}

compile error:
[zengchao@cmcc-server2 ]$g++ test.cpp
test.cpp: In function ‘int main(int, char**)’:
test.cpp:16: error: no matching function for call to ‘array_parameter(int [0])’
Well, it is logical as zero-length arrays are illegal in C++
Standard wrote:
8.3.4 Arrays [dcl.array]
1. [...] If the constant-expression (5.19) is present, it shall be an integral constant expression and its value shall be greater than zero. [...] An object of array type contains a contiguously allocated non-empty set of N subobjects of type T.
Topic archived. No new replies allowed.