Skip to content

Instantly share code, notes, and snippets.

@yaneury
Created May 16, 2017 12:10
Show Gist options
  • Select an option

  • Save yaneury/b7065000e3298e069d74416b84fe4747 to your computer and use it in GitHub Desktop.

Select an option

Save yaneury/b7065000e3298e069d74416b84fe4747 to your computer and use it in GitHub Desktop.
template <typename T>
constexpr T pow(const T& n, const T& m) {
T prod = 1;
for (T i = 0; i < m; ++i)
prod *= n;
return prod;
}
template <typename T, T n, T m>
struct Pow {
enum : T { value = pow(n, m) };
};
int main() {
unsigned n_to_the_m = Pow<unsigned, 4, 2>::value; // 16
return n_to_the_m;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment