boost lambda的一个有关问题
boost lambda的一个问题
我想根据一个int容器的内容以及一个double容器的内容构造一个Foo容器,于是我使用了如下的代码:但是编译8通过,哪里弄错了?
struct Foo
{
Foo(int i, double d)
{
}
};
int _tmain(int argc, _TCHAR* argv[])
{
using namespace boost::lambda;
std::vector <int> int_vec;
int_vec.push_back(1);
int_vec.push_back(2);
std::vector <double> db_vec;
db_vec.push_back(1.2);
db_vec.push_back(2.3);
std::vector <Foo> foo_vec;
std::transform(int_vec.begin(), int_vec.end(), db_vec.begin(), std::back_inserter(foo_vec), Foo(_1, _2));
return 0;
}
------解决方案--------------------
boost文档里的例子
vector <pair <int, int> > v;
transform(x.begin(), x.end(), y.begin(), back_inserter(v),
bind(constructor <pair <int, int> > (), _1, _2));
看boost文档认真一点,看全了再用。
我想根据一个int容器的内容以及一个double容器的内容构造一个Foo容器,于是我使用了如下的代码:但是编译8通过,哪里弄错了?
struct Foo
{
Foo(int i, double d)
{
}
};
int _tmain(int argc, _TCHAR* argv[])
{
using namespace boost::lambda;
std::vector <int> int_vec;
int_vec.push_back(1);
int_vec.push_back(2);
std::vector <double> db_vec;
db_vec.push_back(1.2);
db_vec.push_back(2.3);
std::vector <Foo> foo_vec;
std::transform(int_vec.begin(), int_vec.end(), db_vec.begin(), std::back_inserter(foo_vec), Foo(_1, _2));
return 0;
}
------解决方案--------------------
boost文档里的例子
vector <pair <int, int> > v;
transform(x.begin(), x.end(), y.begin(), back_inserter(v),
bind(constructor <pair <int, int> > (), _1, _2));
看boost文档认真一点,看全了再用。