Created
November 5, 2017 09:09
-
-
Save velnias75/53f9530159123c7d04589b7c5b840b4a to your computer and use it in GitHub Desktop.
Binominal coefficient constant template
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
/* | |
* binominal coefficient constant template | |
* | |
* g++ --std=c++11 -g0 -O3 -s bicot.cpp -o bicot | |
* | |
* (c) 2017 by Heiko Schaefer <[email protected]> | |
* | |
*/ | |
#include <iostream> | |
#include <cstdlib> | |
#include <cstdint> | |
#include <type_traits> | |
namespace bicot { | |
template<class T, | |
typename std::integral_constant<T, T(0)>::value_type n, | |
typename std::integral_constant<T, T(0)>::value_type k> | |
struct binomial { | |
static constexpr T value = (binomial<T, n - T(1), k - T(1)>::value + binomial<T, n - T(1), k>::value); | |
}; | |
template<class T> | |
struct binomial<T, | |
typename std::integral_constant<T, T(0)>::value_type(0), | |
typename std::integral_constant<T, T(0)>::value_type(0)> { | |
static constexpr T value = T(1); | |
}; | |
template<class T, | |
typename std::integral_constant<T, T(0)>::value_type n> | |
struct binomial<T, n, typename std::integral_constant<T, T(0)>::value_type(0)> { | |
static constexpr T value = T(1); | |
}; | |
template<class T, typename std::integral_constant<T, T(0)>::value_type n> | |
struct binomial<T, n, n> { | |
static constexpr T value = T(1); | |
}; | |
} | |
int main(int, char**) { | |
std::cout << bicot::binomial<uint32_t, uint32_t(49), uint32_t(6)>::value << std::endl; | |
return EXIT_SUCCESS; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment