title: Deduce type of reference template parameter
body: <p>If one has a</p>
  
  <pre class="lang-cpp prettyprint-override"><code>template &lt;class T&gt;
  class A{};
  
  // global namespace, static storage duration
  static constexpr A&lt;int&gt; a;
  </code></pre>
  
  <p>is it possible to deduce the type <code>A&lt;int&gt;</code> by passing <code>a</code> as a reference template param such as:</p>
  
  <pre class="lang-cpp prettyprint-override"><code>// This question asks to make the syntax in the following line compile:
  static_assert(std::is_same&lt;A&lt;int&gt;, typename GetReferenceType&lt;a&gt;::type&gt;::value, "");
  // I am aware the next line works, but it's not what I am looking for in this question
  static_assert(std::is_same&lt;A&lt;int&gt;, decltype(a)&gt;::value, "");
  
  // This is pseudo code of how this could work in theory
  template &lt;const T&amp; RefT, class T&gt; // I know this does not compile, but this shows what I want
  struct GetReferenceType{          // which is automatically deduce type `T` without having to 
    using type = T;                 // write it out
  };
  </code></pre>
  
  <p>An answer which explains why this is not possible in C++ is as welcome as a solution to make this syntax compile :)
  I am mostly asking out of curiosity, since basically everything else can be deduced in templates, but apparently not reference types.</p>
  
  <p>This should also work, but does not fulfill the above syntax requirement:</p>
  
  <pre class="lang-cpp prettyprint-override"><code>template &lt;class T&gt;
  constexpr auto GetReferenceTypeFunc(const T&amp; t) -&gt; T;
  
  static_assert(std::is_same&lt;A&lt;int&gt;, decltype(GetReferenceTypeFunc(a))&gt;::value, "");
  </code></pre>
  
  <p><strong>Why I want to do this</strong></p>
  
  <p>I am striving for the most concise syntax.
  While <code>Instantiate&lt;decltype(a)&gt;</code> works, it's not ranking highly in the terseness scale, especially if a syntax like <code>Instantiate&lt;a&gt;</code> was possible.</p>
  
  <p>Imagine <code>a</code> does not have a short type <code>A&lt;int&gt;</code> but instead something like
  <code>A&lt;OmgWhyIsThisTypeNameSoLong&gt;</code>.</p>
  
  <p>Then, if you want to instantiate a type with <code>A&lt;OmgWhyIsThisTypeNameSoLong&gt;</code>, you'd have to write:</p>
  
  <pre class="lang-cpp prettyprint-override"><code>Instantiate&lt;A&lt;OmgWhyIsThisTypeNameSoLong&gt;&gt;;
  </code></pre>
  
  <p>It just so happens that we already have a global object <code>a</code>, so it would be nice not to have to write that long type but instead <code>Instantiate&lt;a&gt;</code>.</p>
  
  <p>There is of course the option of creating an alias <code>using AOmg = A&lt;OmgWhyIsThisTypeNameSoLong&gt;</code> but I would really like to get around spamming the namespace with another very similar name to <code>A</code>.</p>