Created
May 16, 2017 12:10
-
-
Save yaneury/b7065000e3298e069d74416b84fe4747 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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