#include #include // Int2Type template struct Int2Type { const static int value= v; }; // a few class templates struct ApplyId{ template struct apply{ typedef Int2Type type; }; }; struct MakeTen{ template struct apply{ typedef Int2Type<10> type; }; }; struct DoubleMe{ template struct apply{ typedef Int2Type<2*(T::value)> type; }; }; struct AbsMe{ template struct apply{ typedef Int2Type< (T::value > 0)? T::value : -(T::value) > type; }; }; // helper function for output template< typename head > void showMe( std::tuple< head> ){ std::cout << head::value << "\n"; }; template< typename head, typename ... tail> void showMe( std::tuple< head, tail ... > ){ std::cout << head::value << " ," ; showMe( std::tuple< tail ...>() ); } // map function template struct map; template< typename F, typename ... Elements> struct map >{ typedef std::tuple::type ... > type; }; int main(){ std::cout << "original tupel: " << std::endl; typedef std::tuple,Int2Type<-4>,Int2Type<-3>,Int2Type<-2>,Int2Type<-1>,Int2Type<0>, Int2Type<1>,Int2Type<2>,Int2Type<3>,Int2Type<4>,Int2Type<5> >constNumbers; showMe( constNumbers() ); std::cout << "\napply identity: " << std::endl; typedef map::type idConstNumbers; showMe( idConstNumbers() ); std::cout << "\nset each value to 10" << std::endl; typedef map::type makeTenConstNumbers; showMe( makeTenConstNumbers() ); std::cout << "\ndouble each value" << std::endl; typedef map::type doubleMeConstNumbers; showMe( doubleMeConstNumbers() ); std::cout << "\nabsolute value" << std::endl; typedef map::type absMeConstNumbers; showMe( absMeConstNumbers() ); };