boost::mpl::for_each without instantiating

試著忘記壹切 提交于 2019-11-30 07:09:15

Use boost::type and mpl::_ to create an MPL lambda that transforms each type in the list before instantiating the elements and calling the function, like this:

mpl::for_each<Engines, boost::type<mpl::_> >(Registrator());

Registrator should look something like this:

struct Registrator
{
  template<typename T>
  void operator()(boost::type<T>) const
  {
      RegisterInFactory<EasyFixEngine, T> dummy(T::name());
  }
};

Hope that helps.

You should use the three parameter for_each:

mpl::for_each<Engines,mpl::single_view>(Registrator())

Then the instances you get will be of single_view.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!