Last active
August 29, 2015 14:22
-
-
Save unix-beard/0ab79bae789f2dec2293 to your computer and use it in GitHub Desktop.
Idea for a work-around, when C++ 11 features are not available
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
template <typename T, unsigned int N> | |
unsigned int countof(T const (&array)[N]) | |
{ | |
return N; | |
} | |
void f1() { std::cout << "Hello from " << __func__ << "\n"; } | |
void f2() { std::cout << "Hello from " << __func__ << "\n"; } | |
void f3() { std::cout << "Hello from " << __func__ << "\n"; } | |
void f4() { std::cout << "Hello from " << __func__ << "\n"; } | |
void f5() { std::cout << "Hello from " << __func__ << "\n"; } | |
void f6() { std::cout << "Hello from " << __func__ << "\n"; } | |
typedef void (*func)(); | |
const func arr1[] = { | |
f1 | |
}; | |
const func arr2[] = { | |
f2, | |
f3 | |
}; | |
const func arr3[] = { | |
f4, | |
f5, | |
f6 | |
}; | |
template<class Array> | |
void call_func(const Array& arr) | |
{ | |
for (int i = 0; i < countof(arr); i++) | |
arr[i](); | |
} | |
int main() | |
{ | |
call_func(arr1); | |
call_func(arr2); | |
call_func(arr3); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment