title: Partial template deduction in constructors
body: <p><strong>Problem:</strong>  I'm often in a situation where some types can be deduced from the constructor's arguments, but not all:</p>
  <pre class="lang-cpp prettyprint-override"><code>template &lt;typename Res, typename Arg&gt;
  struct adder {
      adder (Arg a1, Arg a2) : a1 {a1}, a2 {a2} {}
      void compute () { res = a1 + a2; }
      Res result () { return res; }
  
      Arg a1, a2;
      Res res;
  };
  </code></pre>
  <p>If I'm using <code>int</code> arguments and want to specify <code>unsigned</code> as result type, I would like to write something like:</p>
  <pre class="lang-cpp prettyprint-override"><code>auto add = adder&lt;unsigned&gt;(42, -51);
  </code></pre>
  <p>…which doesn't work.  However, I don't want to explicitly mention <code>int</code>.</p>
  <p><strong>Candidate solutions:</strong> I can think of two ways to &quot;make it work&quot;, first with a maker:</p>
  <pre class="lang-cpp prettyprint-override"><code>template &lt;typename Res&gt;
  struct wrapper {
      template &lt;typename Arg&gt;
      static auto make_adder (Arg a1, Arg a2) {
        return adder&lt;Res, Arg&gt; (a1, a2);
      }
  };
  
  auto add = wrapper&lt;unsigned&gt;::make_adder (42, -51);
  </code></pre>
  <p>Second by making sure that all types can be deduced in the constructor:</p>
  <pre class="lang-cpp prettyprint-override"><code>template &lt;typename Res, typename Arg&gt;
  struct adder_extra {
      adder_extra (Arg a1, Arg a2, Res r) : a1 {a1}, a2 {a2} {}
      void compute () { res = a1 + a2; }
      Res result () { return res; }
  
      Arg a1, a2;
      Res res;
  };
  
  auto add = adder_extra (42, -51, (unsigned) 0);
  </code></pre>
  <p><strong>Question:</strong> Is there a preferred way?  Can this be solved more neatly in another fashion?</p>