相关疑难解决方法(0)

map,lambda,remove_if

所以,我对std :: map,lambda和stl算法(remove_if)有疑问.实际上,与std :: list或std :: vector相同的代码运行良好.

我的测试示例:

#include <map>
#include <iostream>
#include <algorithm>

struct Foo
{
    Foo() : _id(0) {}
    Foo(int id) : _id(id)
    {

    }

    int _id;    
};
typedef std::map<int, Foo> FooMap;


int main()
{
    FooMap m;
    for (int i = 0; i < 10; ++i)
        m[i + 100] = Foo(i);

    int removeId = 6;
    // <<< Error here >>>
    std::remove_if(m.begin(), m.end(), [=](const FooMap::value_type & item) { return item.second._id == removeId ;} ); 

    for (auto & item : …
Run Code Online (Sandbox Code Playgroud)

c++ lambda stdmap stl-algorithm c++11

14
推荐指数
1
解决办法
1万
查看次数

标签 统计

c++ ×1

c++11 ×1

lambda ×1

stdmap ×1

stl-algorithm ×1