Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

C++ Template Question

Name: Anonymous 2012-10-07 21:47


template <size_t N>
void print_members(int (&arr)[N]) { ... }


so is C++ going to create a new function for every different sized array I use

Name: Cudder !MhMRSATORI!fR8duoqGZdD/iE5 2012-10-08 4:03

>>5

void print_members__18(int *a) { print_members(a, 18); }
void print_members__42(int *a) { print_members(a, 42); }

void (*fn)(int*) = print_members__18;


Once again, no known compiler implements this. It's essentially a form of compile-time refactoring. The "size is no concern" attitude doesn't help either. Nevertheless, it would be awesome if the compiler could turn stuff like

func(5);
func(18);
func(29);
func(62);
...
func(2);
func(8);


into


int arr[] = { 5, 18, 29, 62, ... 2, 8 };
for(int i = 0; i < sizeof(arr)/sizeof(arr[0]);i++)
 func(arr[i]);

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List