title: Template with packaged_task not compile
body: <p>I am playing with an example 4.14 from the book Antony Williams - C + + Concurrency in Action in which emulated std::async using std::packaged_task and std::thread.</p>
  
  <p>Why this code does not compile when I uncomment lines and how to rewrite template to make it work?</p>
  
  <pre class="lang-c++ prettyprint-override"><code>#include &lt;iostream&gt;
  #include &lt;future&gt;
  #include &lt;thread&gt;
  #include &lt;string&gt;
  
  void func_string(const std::string &amp;x) {}
  
  void func_int(int x) {}
  
  template &lt;typename F, typename A&gt;
  std::future&lt;typename std::result_of&lt;F(A&amp;&amp;)&gt;::type&gt; spawn_task(F &amp;&amp;f, A &amp;&amp;a) {
    typedef typename std::result_of&lt;F(A&amp;&amp;)&gt;::type result_type;
    std::packaged_task&lt;result_type(A&amp;&amp;)&gt; task(std::move(f));
    std::future&lt;result_type&gt; res(task.get_future());
    std::thread t(std::move(task), std::move(a));
    t.detach();
    return res;
  }
  
  
  int main () {
    std::string str = "abc";
  
    // auto res1 = spawn_task(func_string, str);
    // res1.get();
    auto res2 = spawn_task(func_int, 10);
    res2.get();
  
    return 0;
  }
  </code></pre>
  
  <p>Compilation errors:</p>
  
  <pre><code>nnovzver@archer /tmp $ clang++ -std=c++11 -lpthread temp.cpp &amp;&amp; ./a.out
  In file included from temp.cpp:2:
  In file included from /usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.8.2/../../../../include/c++/4.8.2/future:38:
  /usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.8.2/../../../../include/c++/4.8.2/functional:1697:56: error: no type
        named 'type' in 'std::result_of&lt;std::packaged_task&lt;void (std::basic_string&lt;char&gt; &amp;)&gt; (std::basic_string&lt;char&gt;)&gt;'
        typedef typename result_of&lt;_Callable(_Args...)&gt;::type result_type;
                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
  /usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.8.2/../../../../include/c++/4.8.2/thread:135:41: note: in instantiation
        of template class 'std::_Bind_simple&lt;std::packaged_task&lt;void (std::basic_string&lt;char&gt; &amp;)&gt;
        (std::basic_string&lt;char&gt;)&gt;' requested here
          _M_start_thread(_M_make_routine(std::__bind_simple(
                                          ^
  temp.cpp:15:15: note: in instantiation of function template specialization 'std::thread::thread&lt;std::packaged_task&lt;void
        (std::basic_string&lt;char&gt; &amp;)&gt;, std::basic_string&lt;char&gt; &gt;' requested here
    std::thread t(std::move(task), std::move(a));
                ^
  temp.cpp:24:15: note: in instantiation of function template specialization 'spawn_task&lt;void (&amp;)(const
        std::basic_string&lt;char&gt; &amp;), std::basic_string&lt;char&gt; &amp;&gt;' requested here
    auto res1 = spawn_task(func_string, str);
                ^
  In file included from temp.cpp:2:
  In file included from /usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.8.2/../../../../include/c++/4.8.2/future:38:
  /usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.8.2/../../../../include/c++/4.8.2/functional:1726:50: error: no type
        named 'type' in 'std::result_of&lt;std::packaged_task&lt;void (std::basic_string&lt;char&gt; &amp;)&gt; (std::basic_string&lt;char&gt;)&gt;'
          typename result_of&lt;_Callable(_Args...)&gt;::type
          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
  2 errors generated.
  </code></pre>