【发布时间】:2010-08-05 01:31:53
【问题描述】:
我必须将某些元素从 std::map 复制到向量中。 它应该像这个循环一样工作:
typedef int First;
typedef void* Second;
std::map<First, Second> map;
// fill map
std::vector<Second> mVec;
for (std::map<First, Second>::const_iterator it = map.begin(); it != map.end(); ++it) {
if (it->first % 2 == 0) {
mVec.push_back (it->second);
}
}
由于我想避免使用任何仿函数,而是使用 boost::lambda,因此我尝试使用 std::copy,但无法正确使用。
std::copy (map.begin(), map.end(), std::back_inserter(mVec)
bind(&std::map<int, void*>::value_type::first, _1) % 2 == 0);
我是 lambda 表达式的新手,我不知道如何正确使用它们。 我在 Google 或 StackOverflow 上也没有得到任何有用的结果。 This question is similar
【问题讨论】:
标签: map boost-lambda