#include "boost/mpl/vector.hpp" #include "boost/mpl/range_c.hpp" #include "boost/mpl/zip_view.hpp" #include "boost/mpl/identity.hpp" #include "boost/mpl/for_each.hpp" #include #include "boost/mpl/size.hpp" #include "boost/mpl/int.hpp" #include "boost/mpl/at.hpp" //#include namespace mpl = boost::mpl ; using mpl::_ ; struct Array_Item { int a ; int b ; void set( int a_param, int b_param ) { a = a_param ; b = b_param ; } } ; struct Initializer { Initializer( Array_Item *item ) : array_( item ) { } template < typename U > void operator()( mpl::identity< U > ) { array_[mpl::at_c< U, 0 >::type::value]. set( mpl::at_c< U, 1>::type::a_param, mpl::at_c< U, 1>::type::b_param ) ; } Array_Item *array_ ; } ; template < typename Descriptor_List_ > struct Holder { typedef Descriptor_List_ Descriptor_List ; static void setup( void ) { static Array_Item array_[mpl::size< Descriptor_List >::type::value] ; typedef mpl::zip_view < mpl::vector2 < mpl::range_c< int, 0, mpl::size::value >, Descriptor_List > > My_View ; mpl::for_each< My_View, mpl::make_identity<_> >( Initializer( array_ ) ) ; //std::cout << array_[0].a << ", " << array_[0].b << std::endl ; //std::cout << array_[1].a << ", " << array_[1].b << std::endl ; } } ; #if 0 template < typename Descriptor_List_ > void Holder< Descriptor_List_ >::setup( void ) { static Array_Item array_[mpl::size< Descriptor_List >::type::value] ; typedef mpl::zip_view < mpl::vector2 < mpl::range_c< int, 0, mpl::size::value > , Descriptor_List > > My_View ; mpl::for_each< My_View, mpl::make_identity<_> >( Initializer( array_ ) ) ; //std::cout << array_[0].a << ", " << array_[0].b << std::endl ; //std::cout << array_[1].a << ", " << array_[1].b << std::endl ; } #endif struct First_Descriptor { static const int a_param = 46 ; static const int b_param = 23 ; } ; struct Second_Descriptor { static const int a_param = 2567 ; static const int b_param = -42 ; } ; typedef mpl::list< First_Descriptor, Second_Descriptor > Descriptors ; int main() { // for ( int i = 0; i < 1000000000; ++i ) // { Holder< Descriptors >::setup() ; // } return 0 ; }