You can use a template taking the array size: http://ideone.com/0Qhra
template <size_t N>
void myMethod ( const int (& intArray) [N] )
{
std::cout << "Array of " << N << " ints
";
return;
}
EDIT:
A possible way to avoid code bloat would be to have a function that takes a pointer and a size that does the actual work:
void myMethodImpl ( const int * intArray, size_t n );
and a trivial template that calls it, that will easily be inlined.
template <size_t N>
void myMethod ( const int (& intArray) [N] )
{ myMethodImpl ( intArray, N ); }
Of course, you'ld have to find a way to test that this is always inlined away, but you do get the safety and ease of use. Even in the cases it is not, you get the benefits for relatively small cost.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…