#include templatestruct seq{ typedef seq next; }; templatestruct seq_n_{ typedef typename seq_n_::type::next type; }; template<>struct seq_n_<0>{ typedef seq<> type; }; template using seq_n=typename seq_n_::type; templatestruct num{ unsigned long tab[n]; }; templateconstexpr num zero(){return num{};} templateconstexpr num shift(num const&a, int l, seq){ return num{{((a.tab[i]<0)?a.tab[(i>0)?i-1:0]>>(64-l):0))...}}; } templateconstexpr num operator<<(num const&a, int l){ return shift(a,l,seq_n()); } constexpr int overflow(unsigned long x, unsigned long y, unsigned long z){ return (x+yconstexpr num add(num const&r, num const&a, num const&b, int idx, int carry, seqs){ return (idx==n)?r:add(num{{(i==idx)?a.tab[i]+b.tab[i]+carry:r.tab[i]...}},a,b,idx+1,overflow(a.tab[idx],b.tab[idx],carry),s); } templateconstexpr num operator+(num const&a, num const&b){ return add(zero(),a,b,0,0,seq_n()); } templateconstexpr num times10(num const&a, int carry=0){ return add(zero(),a<<1,a<<3,0,carry,seq_n()); } constexpr int chartoint(char c){ return c-'0'; } templateconstexpr num string_to_num(const char* s, num tmp=zero()){ return (*s==0)?tmp:string_to_num(s+1,times10(tmp,chartoint(*s))); } int main(){ constexpr auto n=string_to_num<3>("12345678901234567890123456789012345678901234567890"); std::cout << n.tab[0] << '\n'; std::cout << n.tab[1] << '\n'; std::cout << n.tab[2] << '\n'; }