//alternative to switch_ #ifndef FUN_SWITCH_HPP #define FUN_SWITCH_HPP #include #include template struct fun_switch_impl { typedef typename F::result_type result_type ; template struct fun_case { static result_type _(F f) { Case arg; return f(arg); } }; struct fun_vec { typedef result_type (* fun_type )(F) ; static unsigned const vec_size = boost::mpl::size::type::value ; typedef fun_type vec_type [ vec_size ] ; struct fill_vec { vec_type& my_vec ; fill_vec(vec_type& a_vec) : my_vec(a_vec) {} template < typename Case > void operator()(Case) { my_vec[Case::value]=fun_case::_; } }; vec_type my_vec ; fun_vec(void) { boost::mpl::for_each(fill_vec(my_vec)); } fun_type operator[](Int i)const { return my_vec[i]; } }; static fun_vec const& our_vec(void) { static fun_vec const a_vec; return a_vec; } static result_type _(Int i, F f) { return our_vec()[i](f); } }; template typename F::result_type fun_switch(Int i, F f) { return fun_switch_impl::_(i,f); } #endif