#include #include // Set up a few output funtions to list types template< class T > void output_type(); template<> void output_type< float >() { std::cout << "float"; } template<> void output_type< int >() { std::cout << "int"; } // Wrap them up in a single class class output_type_func { public: template< class T > void operator()( T * ) { output_type< T >(); std::cout << std::endl; } }; // A similar class to output the values as well class output_value_func { public: template< class T > void operator()( const T &val ) { output_type< T >(); std::cout << " " << val << std::endl; } }; // A class to filter out float values class is_float { public: template< class T > class filter { public: static const bool result = true; }; class filter< float > { public: static const bool result = false; }; }; // Change float to int and int to float class switch_float_and_int { public: template< class T > class transform; class transform< int > { public: typedef float result; }; class transform< float > { public: typedef int result; }; }; // Function which takes a type vector template< class TV > void f( const TV &x ) { output_type_func func1; std::cout << "Types..." << std::endl; TV::for_each_static( func1 ); std::cout << std::endl; std::cout << "Values..." << std::endl; output_value_func func2; x.for_each( func2 ); std::cout << std::endl; std::cout << "Non float types..." << std::endl; typedef typename TV::filter< is_float >::result without_floats; without_floats::for_each_static( func1 ); std::cout << std::endl; std::cout << "Switched..." << std::endl; typedef typename TV::transform< switch_float_and_int >::result switched; switched::for_each_static( func1 ); std::cout << std::endl; std::cout << "Some other types..." << std::endl; hkm::make_tv< float, float, int >::result::for_each_static( func1 ); } int main() { int x1 = 5; float x2 = 6.7f; int x3 = 7; f( hkm::tv0() | x1 | x2 | x3 ); return 0; }