Getting started with boost mpl with vector and push_back

蹲街弑〆低调 提交于 2019-12-11 15:07:12

问题


I've been scratching my head for far too long, I'm finding using MPL very difficult to get around and hoping somebody can get me started. Here is some partial code from a class I am developing which does not use MPL. I eventually want to implement this class all at compile time. This code probably won't make sense but I don't want all the solution in MPL - hopefully I can achieve that myself (see below for particular help).

class define_cell_type{
public:
    define_cell_type () = default;
    define_cell_type (const std::string& name_of_cell) : 
            cName {name_of_cell} {};

    double& add_variable (const std::string& Name,
            const double& init_value,
            VARIABLE declr_type = VARIABLE::STATIC_V)
    {
       vInit_val.push_back(init_value);
       vData.push_back( std::make_tuple(Name) );
            return vInit_val.back();
    };

private:
    std::string cName;
    std::vector<double> vInit_val;
    std::vector<variable_tuple> vData;
};

To get started, how do I do push_back on an mpl::vector of type double? here is an example I want to begin with similar to the function in the class I'm developing.

std::vector<double> state;
double& add_variable ( const double& init_val)
{
    state.push_back(init_val);
    return state.back();
} 

int main() {
    auto var1 = add_variable (12.2);
    auto var2 = add_variable (1.2);
    auto var2 = add_variable (6.4);
}

All I can get is something like this

typedef mpl::vector<double> state;
typedef mpl::push_back<state,double>::type types;

I would be grateful if somebody got me started, to produce a compile time vector with values pushing back the example above

来源:https://stackoverflow.com/questions/15471122/getting-started-with-boost-mpl-with-vector-and-push-back

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