I am trying to create vector<Wrap>
with same values as in v
. I tried the below combinations, didn't work!
using namespace std;
struct Wrap
{
int data;
//Other members
};
int main()
{
int a[10] = {2345,6345,3,243,24,234};
vector<int> v(&a[0],&a[10]);
Wrap w;
//Populate other members of w
vector<Wrap> vw;
using namespace boost::lambda;
//transform(v.begin(),v.end(), back_inserter(vw), (bind(&Wrap::data,&w,_1), boost::lambda::constant(w)));
//transform(v.begin(),v.end(), back_inserter(vw), bind(&Wrap::data,&w,_1), boost::lambda::constant(w));
//transform(v.begin(),v.end(), back_inserter(vw), ((w.data = _1), boost::lambda::constant(w)));
//transform(v.begin(),v.end(), back_inserter(vw), ((w.data = _1), w));
cout << vw.size() << endl;
BOOST_FOREACH(Wrap w, vw)
{
cout << w.data << endl;
}
}
Note: Can't use C++11 yet
Update Any clean solution which works in C++03 is fine. Need not use boost lambda