title: Remove Elements from an Unordered Map Fulfilling a Predicate
body: <p>I want to remove elements (histogram bins) from an <code>std::unordered_map</code> (histogram) that fulfills a predictate (histogram bins having zero count) given as a lambda expression as follows</p>
  
  <pre><code>std::remove_if(begin(m_map), end(m_map), [](const Bin &amp; bin) { return bin.second == 0; });
  </code></pre>
  
  <p>but GCC-4.6.1 complains as follows</p>
  
  <pre><code>/usr/include/c++/4.6/bits/stl_pair.h:156:2: error: assignment of read-only member ‘std::pair&lt;const unsigned char, unsigned char&gt;::first’
  /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 unsigned char, _T2 = long unsigned int, std::pair&lt;_T1, _T2&gt; = std::pair&lt;const unsigned char, long unsigned int&gt;]’:
  /usr/include/c++/4.6/bits/stl_algo.h:1149:13:   instantiated from ‘_FIter std::remove_if(_FIter, _FIter, _Predicate) [with _FIter = std::__detail::_Hashtable_iterator&lt;std::pair&lt;const unsigned char, long unsigned int&gt;, false, false&gt;, _Predicate = pnw::histogram&lt;V, C, H&gt;::pack() [with V = std::vector&lt;unsigned char&gt;, C = long unsigned int, H = std::unordered_map&lt;unsigned char, long unsigned int, std::hash&lt;unsigned char&gt;, std::equal_to&lt;unsigned char&gt;, std::allocator&lt;std::pair&lt;const unsigned char, long unsigned int&gt; &gt; &gt;]::&lt;lambda(const Bin&amp;)&gt;]’
  tests/../histogram.hpp:68:13:   instantiated from ‘void pnw::histogram&lt;V, C, H&gt;::pack() [with V = std::vector&lt;unsigned char&gt;, C = long unsigned int, H = std::unordered_map&lt;unsigned char, long unsigned int, std::hash&lt;unsigned char&gt;, std::equal_to&lt;unsigned char&gt;, std::allocator&lt;std::pair&lt;const unsigned char, long unsigned int&gt; &gt; &gt;]’
  tests/../histogram.hpp:85:13:   instantiated from ‘void pnw::histogram&lt;V, C, H&gt;::normalize(uint) [with V = std::vector&lt;unsigned char&gt;, C = long unsigned int, H = std::unordered_map&lt;unsigned char, long unsigned int, std::hash&lt;unsigned char&gt;, std::equal_to&lt;unsigned char&gt;, std::allocator&lt;std::pair&lt;const unsigned char, long unsigned int&gt; &gt; &gt;, uint = unsigned int]’
  tests/../histogram.hpp:121:51:   instantiated from ‘H&amp; pnw::histogram&lt;V, C, H&gt;::add(It, It) [with It = __gnu_cxx::__normal_iterator&lt;const unsigned char*, std::vector&lt;unsigned char&gt; &gt;, V = std::vector&lt;unsigned char&gt;, C = long unsigned int, H = std::unordered_map&lt;unsigned char, long unsigned int, std::hash&lt;unsigned char&gt;, std::equal_to&lt;unsigned char&gt;, std::allocator&lt;std::pair&lt;const unsigned char, long unsigned int&gt; &gt; &gt;]’
  tests/../histogram.hpp:129:55:   instantiated from ‘H&amp; pnw::histogram&lt;V, C, H&gt;::add(const V&amp;) [with V = std::vector&lt;unsigned char&gt;, C = long unsigned int, H = std::unordered_map&lt;unsigned char, long unsigned int, std::hash&lt;unsigned char&gt;, std::equal_to&lt;unsigned char&gt;, std::allocator&lt;std::pair&lt;const unsigned char, long unsigned int&gt; &gt; &gt;]’
  tests/../histogram.hpp:57:60:   instantiated from ‘pnw::histogram&lt;V, C, H&gt;::histogram(const V&amp;, pnw::histogram&lt;V, C, H&gt;::TYPE_t) [with V = std::vector&lt;unsigned char&gt;, C = long unsigned int, H = std::unordered_map&lt;unsigned char, long unsigned int, std::hash&lt;unsigned char&gt;, std::equal_to&lt;unsigned char&gt;, std::allocator&lt;std::pair&lt;const unsigned char, long unsigned int&gt; &gt; &gt;]’
  tests/t_histogram.cpp:38:61:   instantiated from ‘void test_dense_histogram() [with T = unsigned char, C = long unsigned int]’
  tests/t_histogram.cpp:64:5:   instantiated from ‘void test_histograms() [with C = long unsigned int]’
  tests/t_histogram.cpp:200:29:   instantiated from here
  /usr/include/c++/4.6/bits/stl_pair.h:156:2: error: assignment of read-only member ‘std::pair&lt;const unsigned char, long unsigned int&gt;::first’
  make: *** [tests/t_histogram.o] Error 1
  </code></pre>
  
  <p>Isn't <code>std::remove_if</code> applicable to <code>std::unordered_map</code>?</p>