Boost logo

Boost Users :

Subject: [Boost-users] [fusion] Non-default initialisation of sequence components.
From: Hugh Dickinson (hugh.dickinson_at_[hidden])
Date: 2010-09-13 08:24:59


Hi Everyone,

I'm wondering if there is a (built-in) way in boost::fusion to instantiate a sequence of heterogeneous elements while passing an identical set of arguments to the constructor of each element? It seems like the only options are to default construct the elements or to supply references to previously constructed elements.

As a semi-concrete example, is there a way to achieve the equivalent of the following?

template <int Label>
struct TestType {

TestType(int i, double d, string s):I(i), D(d), S(s){}

int I;
double D;
string S;

};

int main(int argc, char* argv[]){

typedef vector<int, double, string> ArgVector;

typedef vector<Type<1>, Type<2>, Type<3> > TypeVector;

ArgVector args(1, 2.5, "hello");

// Want to pass the elements of Args as constructor arguments to each element of vec.
TypeVector vec(args);

}

Any help much appreciated,

Hugh


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net