Created
February 21, 2009 12:38
-
-
Save mrkn/68028 to your computer and use it in GitHub Desktop.
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> | |
template<bool cond, class THEN, class ELSE> | |
struct if_ | |
{ | |
typedef ELSE type; | |
}; | |
template<class THEN, class ELSE> | |
struct if_<true, THEN, ELSE> | |
{ | |
typedef THEN type; | |
}; | |
template<unsigned long long N> | |
struct unsigned_long_long | |
{ | |
static const unsigned long long value = N; | |
}; | |
template<unsigned long N, unsigned long R> | |
struct choose | |
{ | |
static const unsigned long long value = if_<(N<R), | |
unsigned_long_long<0>, | |
unsigned_long_long<(choose<N-1, R-1>::value + | |
choose<N-1, R >::value)> | |
>::type::value; | |
}; | |
template<unsigned long N> | |
struct choose<N, 0> | |
{ | |
static const unsigned long long value = 1; | |
}; | |
template<unsigned long N> | |
struct choose<N, N> | |
{ | |
static const unsigned long long value = 1; | |
}; | |
int | |
main(int argc, char** argv) | |
{ | |
std::cout << choose<500, 16>::value << std::endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment