Skip to content

Instantly share code, notes, and snippets.

@airglow923
Created December 18, 2020 15:07
Show Gist options
  • Save airglow923/565967bb54e086922baa13f16b41e19b to your computer and use it in GitHub Desktop.
Save airglow923/565967bb54e086922baa13f16b41e19b to your computer and use it in GitHub Desktop.
Exponents at compile time
namespace {
using LL = signed long long int;
template <LL N, LL X>
struct PowerOf {
static constexpr LL value_ = N * PowerOf<N, X - 1>::value_;
};
template <LL N>
struct PowerOf<N, 0> {
static constexpr LL value_ = 1;
};
} // namespace
template <LL N, LL X>
inline constexpr LL PowerOfV = PowerOf<N, X>::value_;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment