I would like to use an array pointer (with array arithmetic) as a non-type argument. I understand that the argument should be known at compile-time, but isn't it the case for a fixed size global array?
This example can print the first 2 lines, but not the third one. Is there any workaround for this?
EDIT: I am looking for an answer for not only aa+1, but all aa+is where i is less than the size of aa
#include <iostream>
void print (int n) {
printf("the value is: %d\n", n);
}
template <int *n>
void myWrapper() {
print(*n);
}
void myCall(void (*CALLBACK)(void)) {
CALLBACK();
}
int a = 1; int aa[4] = {2,3,4,5};
int main()
{
myCall(myWrapper<&a>); // prints 1
myCall(myWrapper<aa>); // prints 2
/* the following line gives error: no matches converting function 'myWrapper' to type 'void (*)()'
note: candidate is: template<int* n> void myWrapper()
*/
myCall(myWrapper<aa+1>);
}
template<int *n> void myWrapper()tovoid myWrapper(int *n)?