Created
November 4, 2018 16:47
-
-
Save nikanos/c6396815bffd8610de39b6d350f789e9 to your computer and use it in GitHub Desktop.
static power calculation using c++ templates
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> | |
#include <cstdint> | |
using namespace std; | |
template<int N, uint16_t P> | |
struct Pow | |
{ | |
static const uint64_t Result = N * Pow<N, P - 1>::Result; | |
}; | |
template<int N> | |
struct Pow<N, 0> | |
{ | |
static const int Result = 1; | |
}; | |
enum class PowerOfEleven :uint64_t | |
{ | |
First = Pow<11, 1>::Result, | |
Second = Pow<11, 2>::Result, | |
Third = Pow<11, 3>::Result, | |
Fifteenth = Pow<11, 15>::Result | |
}; | |
int main() | |
{ | |
cout << static_cast<uint64_t>(PowerOfEleven::Second) << endl; | |
cout << static_cast<uint64_t>(PowerOfEleven::Fifteenth) << endl; | |
cin.get(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment