title: Why does std::declval add a reference?
body: <p><a href="http://en.cppreference.com/w/cpp/utility/declval"><code>std::declval</code></a> is a compile-time utility used to construct an expression for the purpose of determining its type. It is defined like this:</p>
  
  <pre><code>template&lt; class T &gt;
  typename std::add_rvalue_reference&lt;T&gt;::type declval() noexcept;
  </code></pre>
  
  <p>Would this not be simpler instead?</p>
  
  <pre><code>template&lt; class T &gt;
  T declval() noexcept;
  </code></pre>
  
  <p>What is the advantage of a reference return type? And shouldn't it be called <code>declref</code>?</p>
  
  <p>The earliest historical example I find is <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2009/n2958.html#Value">n2958</a>, which calls the function <code>value()</code> but already always returns a reference.</p>
  
  <p>Note, the operand of <code>decltype</code> does not need to have an accessible destructor, i.e. it is not semantically checked as a full-expression.</p>
  
  <pre><code>template&lt; typename t &gt;
  t declprval() noexcept;
  
  class c { ~ c (); };
  decltype ( declprval&lt; c &gt;() ) * p = nullptr; // OK
  </code></pre>