title: map, lambda, remove_if
body: <p>So, i've problem with std::map, lambda and stl algorithm(remove_if). Actually, same code with std::list or std::vector works well.</p>
  
  <p>My test example :</p>
  
  <pre><code>#include &lt;map&gt;
  #include &lt;iostream&gt;
  #include &lt;algorithm&gt;
  
  struct Foo
  {
      Foo() : _id(0) {}
      Foo(int id) : _id(id)
      {
  
      }
  
      int _id;    
  };
  typedef std::map&lt;int, Foo&gt; FooMap;
  
  
  int main()
  {
      FooMap m;
      for (int i = 0; i &lt; 10; ++i)
          m[i + 100] = Foo(i);
  
      int removeId = 6;
      // &lt;&lt;&lt; Error here &gt;&gt;&gt;
      std::remove_if(m.begin(), m.end(), [=](const FooMap::value_type &amp; item) { return item.second._id == removeId ;} ); 
  
      for (auto &amp; item : m )
          std::cout &lt;&lt; item.first &lt;&lt; " = " &lt;&lt; item.second._id &lt;&lt; "\n";    
  
      return 0;
  }
  </code></pre>
  
  <p>Error message :</p>
  
  <pre><code>In file included from /usr/include/c++/4.6/utility:71:0,
                   from /usr/include/c++/4.6/algorithm:61,
                   from main.cxx:1:
  /usr/include/c++/4.6/bits/stl_pair.h: In member function ‘std::pair&lt;_T1, _T2&gt;&amp; std::pair&lt;_T1, _T2&gt;::operator=(std::pair&lt;_T1, _T2&gt;&amp;&amp;) [with _T1 = const int, _T2 = Foo, std::pair&lt;_T1, _T2&gt; = std::pair&lt;const int, Foo&gt;]’:
  /usr/include/c++/4.6/bits/stl_algo.h:1149:13:   instantiated from ‘_FIter std::remove_if(_FIter, _FIter, _Predicate) [with _FIter = std::_Rb_tree_iterator&lt;std::pair&lt;const int, Foo&gt; &gt;, _Predicate = main()::&lt;lambda(const value_type&amp;)&gt;]’
  main.cxx:33:114:   instantiated from here
  /usr/include/c++/4.6/bits/stl_pair.h:156:2: error: assignment of read-only member ‘std::pair&lt;const int, Foo&gt;::first’
  </code></pre>
  
  <p>I don't understand what's wrong here. So, i gladly to read some advices/directions about it. My goal - use new lambda-style with std::map and algorithms, such as remove_if. </p>
  
  <p>g++ 4.6, -std=c++0x.</p>