<div class="gmail_quote">On Fri, Dec 16, 2011 at 2:46 PM, Rhys Ulerich <span dir="ltr">&lt;<a href="mailto:rhys.ulerich@gmail.com">rhys.ulerich@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
&#39;Afternoon,<br>
<br>
I have a quick question on call traits and template argument<br>
deduction.  I want to use call_traits&#39; value_type and param_type to<br>
deduce a signature like<br>
  double desired_result(double const&amp; x);<br>
given an argument of type double.<br>
<br>
Is there any way to get type deduction working on a snippet like<br>
lousy_attempt (below) to produce my desired_result?<br>
<br>
#include &lt;boost/call_traits.hpp&gt;<br>
<br>
template&lt;typename Scalar&gt;<br>
typename boost::call_traits&lt;Scalar&gt;::value_type<br>
lousy_attempt(typename boost::call_traits&lt;Scalar&gt;::param_type x)<br>
{<br>
    return x;<br>
}<br>
<br>
int main()<br>
{<br>
    double y = 5;<br>
<br>
    // Works...<br>
    lousy_attempt&lt;double&gt;(y);<br>
<br>
    // &quot;No matching function call to lousy_attempt(double&amp;)&quot;<br>
    lousy_attempt(y);<br>
<br>
    return 0;<br>
}<br>
<br>
Thanks in advance,<br>
Rhys<br></blockquote><div><br>What you&#39;re doing can&#39;t work, as the compiler cannot deduce a template parameter based on matching to a nested type. Consider an arbitrary metafunction X&lt;T&gt;, with any number of specializations; how could the compiler deduce the correct &quot;T&quot; to match double (or whatever type) to X&lt;T&gt;::type? The compiler has no way of going from the ::type you&#39;re trying to match back to T.<br>
<br>If you really want this effect, you can use Boost.EnableIf:<br><br>template&lt; class T &gt;<br>typename boost::enable_if_c&lt;<br>    boost::is_same&lt;<br>        T const,<br>        typename boost::call_traits&lt;T&gt;::param_type<br>
    &gt;::value<br>&gt;::type<br>f(T const x) { /*...*/ }<br><br>template&lt; class T &gt;<br>typename boost::enable_if_c&lt;<br>    boost::is_same&lt;<br>        T const &amp;,<br>        typename boost::call_traits&lt;T&gt;::param_type<br>

    &gt;::value<br>
&gt;::type<br>
f(T const &amp; x) { /*...*/ }<br><br>Or, you can explicitly provide the template parameter to your definition of lousy_attempt. Or pass an extra, dummy argument to your function that presents T in a deduced context.<br>
<br>But I would generally recommend to just use T const &amp;.<br>
<br>- Jeff<br><br></div></div>

