39#ifndef HPCOMBI_POWER_HPP_
40#define HPCOMBI_POWER_HPP_
44namespace power_helper {
47template <
typename T>
struct Monoid;
61template <
typename T,
typename M = power_helper::Mono
id<T>>
82template <
unsigned exp,
typename T,
typename M = power_helper::Mono
id<T>>
83const T
pow(
const T x) {
84 return (exp == 0) ? M::one()
86 ? square<T, M>(
pow<
unsigned(exp / 2), T, M>(x))
87 : M::prod(x, square<T, M>(
pow<
unsigned(exp / 2), T, M>(x)));
90namespace power_helper {
105 static const T
one() {
return 1; }
112 static const T
prod(T a, T b) {
return a * b; }
const T square(const T x)
A generic compile time squaring function.
Definition power.hpp:62
const T pow(const T x)
A generic compile time exponentiation function.
Definition power.hpp:83
Algebraic monoid structure used by default for type T by the pow function and prod function.
Definition power.hpp:103
static const T prod(T a, T b)
the product of two elements of type T
Definition power.hpp:112
static const T one()
The one of type T.
Definition power.hpp:105