title: Default template parameter based on type of other template parameter
body: <p>I have a templated function as below:</p>
  
  <pre><code>template&lt;typename T&gt;
  std::vector&lt;RT&gt; myFunc(std::vector&lt;T&gt; inVec){
      ...
      std::vector&lt;RT&gt; outVec;
      return outVec
  </code></pre>
  
  <p>I need the return type <code>RT</code> to be deduced from <code>T</code> with the logic that if <code>T</code> is <code>std::complex</code> then <code>RT</code> will be same as <code>T</code> but if not then <code>RT</code> will be <code>std::complex&lt;T&gt;</code>. </p>
  
  <p>I tried defining a type trait to check if <code>T</code> is <code>std::complex</code> and have a default template parameter based on that as follows:</p>
  
  <pre><code>template&lt;typename T&gt;
  struct is_complex : std::false_type {};
  
  template&lt;typename T&gt; 
  struct is_complex&lt;std::complex&lt;T&gt;&gt; : std::true_type {};
  
  template&lt;typename T, typename RT = typename is_complex&lt;T&gt;::value ? T : std::complex&lt;T&gt;&gt;
  std::vector&lt;RT&gt; myFunc(std::vector&lt;T&gt; inVec){
      ...
      std::vector&lt;RT&gt; outVec;
      return outVec
  </code></pre>
  
  <p>but this doesn't compile giving me the following error:</p>
  
  <pre><code>error: expected '&gt;' before '?' token template&lt;typename T, typename RT = typename is_complex&lt;T&gt;::value ? T : std::complex&lt;T&gt;&gt;
  </code></pre>
  
  <p>Is this not legal C++ code?</p>