提升不同std ::向量的融合向量来实现数据帧

时间:2012-11-27 18:05:11

标签: c++ boost vector stl boost-fusion

我正试图实施一个"数据框"在C ++中输入类(如在S + / R中),类似于:

template<typename T1, typename T2, typename T3>
class data_frame;

我的目标是将数据存储在内存中,作为&#34;列向量&#34; (而不是作为元组的简单向量),原因与问题无关。

(假设我没有可变参数模板,而且我现在并不担心固定数量的参数 - 我稍后可以解决这个问题。)

使用MPL和融合,我到目前为止能够创建std:vectors的融合序列:

template <typename T> 
struct make_vector 
{ 
    typedef std::vector<T> type; 
}; 
typedef boost::mpl::vector<T1, T2, T3> data_types;
typedef boost::mpl::transform1<data_types, make_vector<_1> >  vector_types;
typedef boost::fusion::result_of::as_vector<vector_types>::type vectors;

我还设法定义了一个tuple_type,它是具有与data_frame相同签名的boost :: tuple的特化。

typedef details_not_shown tuple_type;

现在,我想定义一个允许我向data_frame添加tuple_type的成员函数。这就是我的想法:

vectors the_vectors;

struct append
{
    typedef void result_type;

    template<typename U>
    void operator()(const U & d, std::vector<U> & v) const
    {
        v.push_back(d);
    }
}

void push_back(tuple_type & t)
{
    fusion::for_each(fusion::zip(t,the_vectors), fusion::make_fused_function_object(append())) ;
}

当我编译它时(在VS2010 C ++上),我收到以下错误:

error C2664: 'void some_class<T0,T1,T2>::append::operator ()<const T>(const U &,std::vector<_Ty> &) const'
: cannot convert parameter 2 from 'const std::vector<_Ty>' to 'std::vector<_Ty> &'

显然,zip正在复制the_vectors的std:vector元素而不是传递引用,因此push_back失败。

有谁知道如何让Fusion zip传递引用而不是副本?

0 个答案:

没有答案