Go to the documentation of this file.00001
00006 #include<iostream>
00007 #ifdef N
00008 const unsigned n=N;
00009 #undef N
00010 #else
00011 #error Constant integer N must be defined, use -DN=[n] option
00012 const unsigned n=0;
00013 #endif
00014
00015
00016 namespace my_lib {
00017
00018 template<unsigned N, unsigned K>
00019 struct Binomial;
00020
00029 template<bool T,unsigned N, unsigned K>
00030 struct CondBinom {
00031 static const unsigned val=Binomial<N-1,K-1>::val + Binomial<N-1,K>::val;
00032 };
00033
00040 template<unsigned N, unsigned K>
00041 struct CondBinom<false,N,K> {
00042 static const unsigned val=0;
00043 };
00044
00051 template<unsigned N, unsigned K>
00052 struct Binomial {
00053 static const unsigned val=CondBinom<(N>=K),N,K>::val;
00054 };
00055
00061 template<unsigned N>
00062 struct Binomial<N,0> {
00063 static const unsigned val=1;
00064 };
00065
00071 template<unsigned N>
00072 struct Binomial<N,N> {
00073 static const unsigned val=1;
00074 };
00075
00080 template<>
00081 struct Binomial<0,0> {
00082 static const unsigned val=1;
00083 };
00084
00085
00086
00092 template<unsigned K, unsigned N>
00093 struct Loop {
00094 static void print(){
00095 std::cout << Binomial<N,K>::val << std::endl;
00096 Loop<K+1,N>::print();
00097 }
00098 };
00099
00105 template<unsigned N>
00106 struct Loop<N,N> {
00107 static void print(){
00108 std::cout << Binomial<N,N>::val << std::endl;
00109 }
00110 };
00111
00112 }
00113
00114 using namespace my_lib;
00115 int main(){
00116 Loop<0,n>::print();
00117 }
00118
00119