boost::mpl::for_each without instantiating

后端 未结 2 1735
一向
一向 2020-12-29 13:03

Taking the following example, I wonder whether there is an alternative to boost::mpl::for_each, which does call a Functor without any arguments.



        
相关标签:
2条回答
  • 2020-12-29 13:39

    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.

    0 讨论(0)
  • 2020-12-29 13:40

    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.

    0 讨论(0)
提交回复
热议问题