Created
October 31, 2012 10:00
-
-
Save neel/3986190 to your computer and use it in GitHub Desktop.
This file contains 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> | |
namespace meta{ | |
template <int Begin, int End, bool done = false> | |
struct iterator{ | |
template<typename F> | |
static void iterate(F f){ | |
f(); | |
iterator<Begin, End-1, Begin == End-1>::iterate(f); | |
} | |
}; | |
template <int Begin, int End> | |
struct iterator<Begin, End, true>{ | |
template <typename F> | |
static void iterate(F){} | |
}; | |
} | |
void print(){ | |
std::cout << "print !!" << std::endl; | |
} | |
int main(){ | |
meta::iterator<4, 7>::iterate(&print); | |
return 0; | |
} |
This file contains 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> | |
namespace meta{ | |
template <int Begin, int End, bool done = false> | |
struct iterator{ | |
template<typename F> | |
static void iterate(F f){ | |
f<End>(); | |
iterator<Begin, End-1, Begin == End-1>::iterate(f); | |
} | |
}; | |
template <int Begin, int End> | |
struct iterator<Begin, End, true>{ | |
template <typename F> | |
static void iterate(F){} | |
}; | |
} | |
template <int i> | |
void print(){ | |
std::cout << "print !!" << i << std::endl; | |
} | |
int main(){ | |
meta::iterator<4, 7>::iterate(&print); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment