C++ - binary templates
Those other templates are not nearly complicated enough. Peano arithmetic is too easy. We have to use bits! And your spelling is so un creative...
#include <cstdio>
class wun {};
class zeroh {};
template<class... bits>
class numbur;
template<class lsb, class... msbs>
class numbur<lsb, msbs...> : public numbur<msbs...>
{};
template<>
class numbur<> {};
template<class lhs, class rhs>
class suhm;
template<class... leftoverz>
class suhm<numbur<>, numbur<leftoverz...>>
{
public: typedef numbur<leftoverz...> rusult;
};
template<class... leftoverz>
class suhm<numbur<leftoverz...>, numbur<>>
{
public: typedef numbur<leftoverz...> rusult;
};
template<class lsb, class... otherz>
struct cat;
template<class lsb, class... otherz>
struct cat<lsb, numbur<otherz...>>
{
typedef numbur<lsb, otherz...> risult;
};
template<class... beezel, class... beezer>
class suhm<numbur<zeroh, beezel...>, numbur<zeroh, beezer...>>
{
public: typedef typename cat<zeroh, typename suhm<numbur<beezel...>, numbur<beezer...>>::rusult>::risult rusult;
};
template<class... beezel, class... beezer>
class suhm<numbur<wun, beezel...>, numbur<zeroh, beezer...>>
{
public: typedef typename cat<wun, typename suhm<numbur<beezel...>, numbur<beezer...>>::rusult>::risult rusult;
};
template<class... beezel, class... beezer>
class suhm<numbur<zeroh, beezel...>, numbur<wun, beezer...>>
{
public: typedef typename cat<wun, typename suhm<numbur<beezel...>, numbur<beezer...>>::rusult>::risult rusult;
};
template<class... beezel, class... beezer>
class suhm<numbur<wun, beezel...>, numbur<wun, beezer...>>
{
typedef typename suhm<numbur<wun>, numbur<beezel...>>::rusult DrewCarry;
public: typedef typename cat<zeroh, typename suhm<DrewCarry, numbur<beezer...>>::rusult>::risult rusult;
};
template<class numbr>
struct prant;
template<>
struct prant<numbur<>>
{
static void praaant() {
printf("\n");
}
};
template<class... bees>
struct prant<numbur<wun, bees...>>
{
static void praaant() {
printf("1");
prant<numbur<bees...>>::praaant();
}
};
template<class... bees>
struct prant<numbur<zeroh, bees...>>
{
static void praaant() {
printf("0");
prant<numbur<bees...>>::praaant();
}
};
typedef numbur<wun, wun, zeroh, wun> ayy;
typedef numbur<zeroh, wun, wun, zeroh, wun> beee;
int main ()
{
prant<ayy>::praaant();
prant<beee>::praaant();
prant<suhm<ayy, beee>::rusult>::praaant();
return 0;
}
$.sum=function(a,b){return a+b};
. \$\endgroup\$'SELECT ' + a + ' + ' + b + ';'
. It's simple and understandable. \$\endgroup\$