title: Workaround for VS 2013 SFINAE deficiencies
body: <p>I'm trying to fix up a library (<a href="https://github.com/alecthomas/entityx" rel="nofollow">entityx</a>) that does not currently compile on Windows using VS 2013.  It compiles fine on Linux with gcc and also on Windows with MinGW.</p>
  
  <p>It seems the problem is with SFINAE - I guess VS 2013 doesn't properly ignore substitution failures for templates.</p>
  
  <p>There is a report of this issue on Microsoft Connect, <a href="http://connect.microsoft.com/VisualStudio/feedback/details/794707/sfinae-fai" rel="nofollow">here</a>.</p>
  
  <p>Before I dive into <a href="https://github.com/alecthomas/entityx" rel="nofollow">entityx</a>, there is a sample of the problem (taken from the report at Microsoft Connect):</p>
  
  <pre><code>#include &lt;vector&gt;
  #include &lt;future&gt;
  
  using namespace std;
  
  typedef int async_io_op;
  
  struct Foo
  {
      //! Invoke the specified callable when the supplied operation completes
      template&lt;class R&gt; inline std::pair &lt; std::vector &lt; future &lt; R &gt;&gt; , std::vector &lt; async_io_op &gt;&gt; call(const std::vector&lt;async_io_op&gt; &amp;ops, const std::vector &lt; std::function &lt; R() &gt;&gt; &amp;callables);
      //! Invoke the specified callable when the supplied operation completes
      template&lt;class R&gt; std::pair &lt; std::vector &lt; future &lt; R &gt;&gt; , std::vector &lt; async_io_op &gt;&gt; call(const std::vector &lt; std::function &lt; R() &gt;&gt; &amp;callables) { return call(std::vector&lt;async_io_op&gt;(), callables); }
      //! Invoke the specified callable when the supplied operation completes
      template&lt;class R&gt; inline std::pair&lt;future&lt;R&gt;, async_io_op&gt; call(const async_io_op &amp;req, std::function&lt;R()&gt; callback);
      //! Invoke the specified callable when the supplied operation completes
      template&lt;class C, class... Args&gt; inline std::pair&lt;future&lt;typename std::result_of&lt;C(Args...)&gt;::type&gt;, async_io_op&gt; call(const async_io_op &amp;req, C callback, Args... args);
  };
  
  int main(void)
  {
      Foo foo;
      std::vector&lt;async_io_op&gt; ops;
      std::vector &lt; std::function &lt; int() &gt;&gt; callables;
      foo.call(ops, std::move(callables));
      return 0;
  }
  </code></pre>
  
  <p>I get the following error when attempting to compile this:</p>
  
  <blockquote>
    <p>error C2064: term does not evaluate to a function taking 0 arguments</p>
    
    <p>c:\program files (x86)\microsoft visual studio 12.0\vc\include\xrefwrap 58</p>
  </blockquote>
  
  <p>Apparently, we can use <code>std::enable_if</code> to work around this problem.  However, I can't figure out how.</p>
  
  <p>Does anyone know how I can fix this compile error?</p>
  
  <p><strong>Edit</strong>:  Full output from VS 2013:</p>
  
  <pre><code>1&gt;------ Build started: Project: VS2013_SFINAE_Failure, Configuration: Debug Win32 ------
  1&gt;  test_case.cpp
  1&gt;c:\program files (x86)\microsoft visual studio 12.0\vc\include\xrefwrap(58): error C2064: term does not evaluate to a function taking 0 arguments
  1&gt;          c:\program files (x86)\microsoft visual studio 12.0\vc\include\xrefwrap(118) : see reference to class template instantiation 'std::_Result_of&lt;_Fty,&gt;' being compiled
  1&gt;          with
  1&gt;          [
  1&gt;              _Fty=std::vector&lt;std::function&lt;int (void)&gt;,std::allocator&lt;std::function&lt;int (void)&gt;&gt;&gt;
  1&gt;          ]
  1&gt;          c:\users\jarrett\downloads\vs2013_sfinae_failure\vs2013_sfinae_failure\test_case.cpp(25) : see reference to class template instantiation 'std::result_of&lt;std::vector&lt;std::function&lt;int (void)&gt;,std::allocator&lt;_Ty&gt;&gt; (void)&gt;' being compiled
  1&gt;          with
  1&gt;          [
  1&gt;              _Ty=std::function&lt;int (void)&gt;
  1&gt;          ]
  ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
  </code></pre>