title: Function wont accept Lambda but will accept function pointer
body: <p>I am trying to implement a JavaScript map function in C++ but cannot get it to accept a lambda. It works when I use a function pointer but not with a lambda. I understand that a lambda and a function pointer are different; I just don't understand why the foreach function is fine but the map function is not.</p>
  
  <p>Any help you will be very appreciated.</p>
  
  <pre class="lang-cpp prettyprint-override"><code>template&lt;typename T&gt;
  struct List {
      void* buffer;
  
      ...
  
      void each(void(func)(T))
      {
          for (u32 index = 0; index &lt; size; index += 1)
          {
              func(((T*)buffer)[index]);
          }
      }
  
      template &lt;typename OutType&gt;
      List&lt;OutType&gt; map(OutType(func)(T))
      {
          List&lt;OutType&gt; list;
          for (u32 index = 0; index &lt; size; index += 1)
          {
              list.push(func(((T*)buffer)[index]));
          }
          return list;
      }
  };
  </code></pre>
  
  <p>Usage Code:</p>
  
  <pre class="lang-cpp prettyprint-override"><code>i64 addTwo(i32 n)
  {
      return (i64)(n + 2);
  }
  
  int main()
  {
      List&lt;i32&gt; list;
      list.push(4);
      list.push(2);
  
      // works
      list.each([](i32 num) {
          std::cout &lt;&lt; num &lt;&lt; std::endl;
      });
  
      // works
      auto list1 = list.map(addTwo);
  
      // does not work
      auto list2 = list.map([](i32 n) -&gt; i32 {
          return n + 3;
      });
  }
  </code></pre>
  
  <p>Error Output:</p>
  
  <pre class="lang-sh prettyprint-override"><code>.../main.cpp:53:23: error: no matching member function for call to 'map'
      auto list2 = list.map([](i32 n) -&gt; i32 {
                   ~~~~~^~~
  .../list.hpp:86:19: note: candidate template ignored: could not match 'OutType (*)(int)' against
        '(lambda at /home/caleb/opengl-starter/source/main.cpp:53:27)'
      List&lt;OutType&gt; map(OutType(func)(T))
                    ^
  1 error generated.
  </code></pre>