title: C++ test if lambda function
body: <p>I'm making a hooking library, which basically intercepts a function and makes it jump to the intercept function.</p>
  
  <pre><code>class CHook
  {
  public:
  
      template&lt;typename S, typename D&gt;
      void SetupHook(S Source, D Destionation)
      {
          pSource = (PBYTE)Source;
          pDestination = (PBYTE)Destionation;
      }
  
  private:
      PBYTE pSource;
      PBYTE pDestination;
  };
  </code></pre>
  
  <p>I want CHook::SetupHook to take (for Destination) either DWORD (address of function), function pointer which both can be type casted to PBYTE.</p>
  
  <p>I want CHook::SetupHook to also be able to take a function pointer from lambda but it cannot be type casted to PBYTE so I overload it and since I know lambda function are classes I use std::is_class to identify them.</p>
  
  <pre><code>template&lt;typename S, typename D&gt;
  void SetupHook(S Source, typename std::enable_if&lt;!std::is_class&lt;D&gt;::value, D&gt;::type Destionation)
  {
      pSource = (PBYTE)Source;
      pDestination = (PBYTE)Destionation;
  }
  
  template&lt;typename S, typename D&gt;
  void SetupHook(S Source, typename std::enable_if&lt;std::is_class&lt;D&gt;::value, D&gt;::type Destionation)
  {
      pSource = (PBYTE)Source;
      pDestination = (PBYTE)to_function_pointer(Destionation);
  }
  </code></pre>
  
  <p>But it results in these erorrs:</p>
  
  <pre><code>error C2783: 'void CHook::SetupHook(S,std::enable_if&lt;std::is_class&lt;D&gt;::value,D&gt;::type)': could not deduce template argument for 'D'
  note: see declaration of 'CHook::SetupHook'
  </code></pre>