Created
April 14, 2013 12:46
-
-
Save weidagang/5382585 to your computer and use it in GitHub Desktop.
Calculate n to the power of m with C++ template meta programming
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> | |
template<int N, int M> | |
struct Pow { | |
enum { value = N * Pow<N, M-1>::value }; | |
}; | |
template<int N> | |
struct Pow<N, 0> { | |
enum { value = 1 }; | |
}; | |
int main() { | |
std::cout << Pow<2, 10>::value << std::endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment