title: can I deduce a tuple element type in a function parameter (ie with std::tuple_element)?
body: <p>I have a struct which stores some data in a tuple. I want to build a function <code>getWithDefault&lt;n&gt;(m)</code>, which gets the data from the nth term but replaces it with m if the value is 0. But to do this, I have to know the correct data type for m in the function parameter: <code>getWithDefault&lt;&gt;(WhichType?)</code>. Is there any way of doing this? I've tried with <code>std::tuple_element</code>, but it doesn't seem to work.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;tuple&gt;
  
  
  template &lt;typename... T&gt;
  struct C
  {
      C(T... args) : t(std::make_tuple(args...)) {}
  
      template &lt;int n&gt;
      auto get() const
      { return std::get&lt;n&gt;(t); }
  
      template &lt;int n&gt;
      auto getWithDefault(std::tuple_element&lt;n, decltype(t)&gt;::type de)    // Compiler error: identifier not found
      {
          const auto v = get&lt;n&gt;();
          return v != 0 ? v : de;
      }
  
  private:
  
      const std::tuple&lt;T...&gt; t;
  };
  
  
  
  int main()
  {
  
      C&lt;int, int&gt; c(0, 4);
  
      std::cout &lt;&lt; c.getWithDefault&lt;0&gt;(5);     // this should return 5
  
      return 0;
  }
  </code></pre>
  
  <p>I can see why this code fails--<code>std::tuple_element</code> doesn't have access to the member variable from inside the function parameter. So, is there a viable way of deducing the type of a tuple term from within a function parameter?</p>