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
push_back
just creates a new type, with the new value at the end. It seems you want to register these values at different places in your code. I dont know exactly what you want to achieve with these values, but you may need to register them at run-time, instead. – Fulgurate