TEMPLATES!!!
So you think you know what templates do ? Lets see, they are a type of metaprogramming right ? They allow you to use C++ compiler as an interpreter and write generic code with the use of which C++ compiler would generate specific code. So that is what templates does ? Nope. Sorry but I thought so too. But along comes this code snippet which supposedly implements a while loop. Go figure! And when you do please tell me too :D
template
class loop {
private: enum { go = (I-1) != 0 };
public: static inline void f() {
// Whatever needs to go here
loop::f(); }
};
class loop<0> {
public:
static inline void f()
{ }
};
loop::f();
No comments:
Post a Comment