C++ C++;boostmpl:如何去掉向量和callnot内部函数?

C++ C++;boostmpl:如何去掉向量和callnot内部函数?,c++,boost,boost-mpl,C++,Boost,Boost Mpl,我正在学习Boost.MPL,我才刚刚开始。所以,请原谅我,如果解决办法是显而易见的。我看这样的例子: #include <boost/mpl/vector.hpp> #include <boost/mpl/for_each.hpp> #include <iostream> using namespace std; struct A { template <class T> void operator()(T t)

我正在学习Boost.MPL,我才刚刚开始。所以,请原谅我,如果解决办法是显而易见的。我看这样的例子:

#include <boost/mpl/vector.hpp>
#include <boost/mpl/for_each.hpp>
#include <iostream>

using namespace std;

struct A
{
    template <class T>
    void    operator()(T t)
    {
        cout << typeid(T).name() << "\t" << t << endl;
    }

    template <class TypeVector>
    void    FooAll(void)
    {
        boost::mpl::for_each<TypeVector>(*this);
    }
};

void main(void)
{
    A   a;
    a.FooAll<boost::mpl::vector<int, float, long>>();
}
#包括
#包括
#包括
使用名称空间std;
结构A
{
模板
void运算符()(T)
{

cout请看boost元组实现(解决了一个类似的问题)。其主要思想是,您可以为FollAll()方法指定最大数量的模板参数,并为大多数模板参数提供默认类型。下面是我想到的一个草图

#include <boost/type_traits/is_same.hpp>
#include <boost/mpl/eval_if.hpp>
#include <boost/mpl/vector.hpp>
#include <boost/mpl/push_back.hpp>

using boost::is_same;
using boost::mpl::eval_if;
using boost::mpl::vector;
using boost::mpl::push_back;

struct EmptyType {  };

struct A
{
  template<typename arg1, typename arg2=EmptyType, typename arg3=EmptyType, ..., typename argN=EmptyType>
  void    FooAll() {
      // reconstruct the type vector for easy manipulation later
      // Bolierplate code!
      typedef vector<arg>   vector_arg1;       
      typedef typename eval_if<is_same<arg2, EmptyType>,
                                vector_arg1,
                                push_back<vector_arg1, arg2> >::type  vector_arg2;
      typedef typename eval_if<is_same<arg3, EmptyType>,
                                vector_arg2,
                                push_back<vector_arg2, arg3> >::type  vector_arg3;
      //... rest of arguments
      typedef typename eval_if<is_same<argN, EmptyType>,
                                vector_arg(N-1),
                                push_back<vector_arg(N-1), argN> >::type  vector_argN;

      // now you can manipulate the reconstructed type vector
      Do_some_internal_stuff<vector_argN>::apply();
  }
}
#包括
#包括
#包括
#包括
使用boost::是一样的;
使用boost::mpl::eval_if;
使用boost::mpl::vector;
使用boost::mpl::push_-back;
结构清空类型{};
结构A
{
模板
void FooAll(){
//重建类型向量以便于以后的操作
//Bolierplate代码!
但请确保您所针对的编译器已经支持此功能

致以最良好的祝愿,
Marcin

@user1072853我已经用更多细节更新了示例。我没有访问编译器的权限,因此请将此代码仅作为草图处理。