我必須將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 ::拉姆達相反,我試圖使用的std ::複製,但無法得到它的權利。
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