title: "error C2678: binary '=' : no operator found which takes a left-hand operand of type..." when using lambda function for map filtering
body: <p>I have written (partailly copied :) ) the following code:
  HigherOrderFunctions.h :</p>
  
  <pre><code>#ifndef HigherOrderFunctions_H
  #define HigherOrderFunctions_H
  
  #include &lt;algorithm&gt;
  
  class HigherOrderFunctions {
  public:
     template&lt;class Coll, class Func&gt;
     static Coll&amp; filter(Coll&amp; items, Func&amp;&amp; filterFunc);
  private:
     HigherOrderFunctions() {}
  };
  
  template &lt; class Coll, class Func&gt;
  Coll&amp; HigherOrderFunctions::filter(Coll&amp; items, Func&amp;&amp; filterFunc) {
     auto first = std::find_if_not(items.begin(), items.end(), filterFunc);
     const auto last = items.end();
     if (first != last) {
        for(auto it = first; ++it != last; ) {
           if (filterFunc(*it)) {
              *first++ = std::move(*it);
           }
        }
     }
     items.erase(first, items.end());
     return items;
  }
  
  #endif // HigherOrderFunctions_H
  </code></pre>
  
  <p>Now when I try to test the above code with the test function:</p>
  
  <pre><code>void HighOrderFunctionsTest::testFilter() {
     vector&lt;int&gt; integers = {1, 2, 3, 4, 5, 6, 7};
     HigherOrderFunctions::filter(integers, [](int elem) -&gt; bool {
        return (elem % 2) == 0;
     });
  
     const int ADULT_AGE = 18;
     map&lt;string, int&gt; name_age_list = {{"sm", 10}, {"ak", 20}, {"al", 30}, {"am", 35}};
     function&lt;bool(const pair&lt;string, int&gt;&amp;)&gt; funct = [ADULT_AGE](const pair&lt;string, int&gt;&amp; elem) -&gt; bool {
        return (elem.second &gt; ADULT_AGE);
     };
  
     HigherOrderFunctions::filter(name_age_list, funct);
  }
  </code></pre>
  
  <p>The part where I filter the vector compiles OK, but when I add the part with map I get the following compile error (using MSVS 2013):</p>
  
  <pre><code>HighOrderFunctionsTest.cpp
  2&gt;C:\winapp\MSVS2013PRO\VC\include\utility(175): error C2678: binary '=' : no operator found which takes a left-hand operand of type 'const std::string' (or there is no acceptable conversion)
  2&gt;          C:\winapp\MSVS2013PRO\VC\include\xstring(1017): could be 'std::basic_string&lt;char,std::char_traits&lt;char&gt;,std::allocator&lt;char&gt;&gt; &amp;std::basic_string&lt;char,std::char_traits&lt;char&gt;,std::allocator&lt;char&gt;&gt;::operator =(_Elem)'
  2&gt;          with
  2&gt;          [
  2&gt;              _Elem=char
  2&gt;          ]
  2&gt;          C:\winapp\MSVS2013PRO\VC\include\xstring(1012): or       'std::basic_string&lt;char,std::char_traits&lt;char&gt;,std::allocator&lt;char&gt;&gt; &amp;std::basic_string&lt;char,std::char_traits&lt;char&gt;,std::allocator&lt;char&gt;&gt;::operator =(const _Elem *)'
  2&gt;          with
  2&gt;          [
  2&gt;              _Elem=char
  2&gt;          ]
  2&gt;          C:\winapp\MSVS2013PRO\VC\include\xstring(996): or       'std::basic_string&lt;char,std::char_traits&lt;char&gt;,std::allocator&lt;char&gt;&gt; &amp;std::basic_string&lt;char,std::char_traits&lt;char&gt;,std::allocator&lt;char&gt;&gt;::operator =(const std::basic_string&lt;char,std::char_traits&lt;char&gt;,std::allocator&lt;char&gt;&gt; &amp;)'
  2&gt;          C:\winapp\MSVS2013PRO\VC\include\xstring(957): or       'std::basic_string&lt;char,std::char_traits&lt;char&gt;,std::allocator&lt;char&gt;&gt; &amp;std::basic_string&lt;char,std::char_traits&lt;char&gt;,std::allocator&lt;char&gt;&gt;::operator =(std::initializer_list&lt;_Elem&gt;)'
  2&gt;          with
  2&gt;          [
  2&gt;              _Elem=char
  2&gt;          ]
  2&gt;          C:\winapp\MSVS2013PRO\VC\include\xstring(901): or       'std::basic_string&lt;char,std::char_traits&lt;char&gt;,std::allocator&lt;char&gt;&gt; &amp;std::basic_string&lt;char,std::char_traits&lt;char&gt;,std::allocator&lt;char&gt;&gt;::operator =(std::basic_string&lt;char,std::char_traits&lt;char&gt;,std::allocator&lt;char&gt;&gt; &amp;&amp;) throw()'
  2&gt;          while trying to match the argument list '(const std::string, const std::string)'
  2&gt;          C:\winapp\MSVS2013PRO\VC\include\utility(174) : while compiling class template member function 'std::pair&lt;const _Kty,_Ty&gt; &amp;std::pair&lt;const _Kty,_Ty&gt;::operator =(std::pair&lt;const _Kty,_Ty&gt; &amp;&amp;)'
  2&gt;          with
  2&gt;          [
  2&gt;              _Kty=std::string
  2&gt;  ,            _Ty=int
  2&gt;          ]
  2&gt;          D:\tax\tax_win\tc\src\cpp\foundation\HigherOrderFunctions.h(219) : see reference to function template instantiation 'std::pair&lt;const _Kty,_Ty&gt; &amp;std::pair&lt;const _Kty,_Ty&gt;::operator =(std::pair&lt;const _Kty,_Ty&gt; &amp;&amp;)' being compiled
  2&gt;          with
  2&gt;          [
  2&gt;              _Kty=std::string
  2&gt;  ,            _Ty=int
  2&gt;          ]
  2&gt;          ..\..\..\..\..\..\src\cpp\foundation\test\HighOrderFunctionsTest.cpp(33) : see reference to class template instantiation 'std::pair&lt;const _Kty,_Ty&gt;' being compiled
  2&gt;          with
  2&gt;          [
  2&gt;              _Kty=std::string
  2&gt;  ,            _Ty=int
  2&gt;          ]
  </code></pre>
  
  <p>I have looked for similar errors and I found out that this could happen if my function where the code is called would be const, but it is not. Can you please help me with this problem?</p>