Skip to content

Instantly share code, notes, and snippets.

@weidagang
Created April 14, 2013 12:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save weidagang/5382585 to your computer and use it in GitHub Desktop.
Save weidagang/5382585 to your computer and use it in GitHub Desktop.
Calculate n to the power of m with C++ template meta programming
#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