title: How does std::declval<T>() work?
body: <p>I am trying to understand how <code>std::declval&lt;T&gt;()</code> works. I know how to use it, and know what it does, mainly allows you to use <code>decltype</code> without constructing the object, like</p>
  
  <pre><code>decltype(std::declval&lt;Foo&gt;().some_func()) my_type; // no construction of Foo
  </code></pre>
  
  <p>I know from <a href="http://en.cppreference.com/w/cpp/utility/declval" rel="noreferrer">cppreference.com</a> that <code>std::declval&lt;Foo&gt;</code> "adds" a rvalue reference to <code>Foo</code>, which due to reference collapsing rules ends up being either a rvalue reference or a lvalue reference. My question is why the constructor of <code>Foo</code> is not called? How can one implement a "toy" version of <code>std::declval&lt;T&gt;</code> without constructing the template parameter?</p>
  
  <p>PS: <a href="https://stackoverflow.com/q/14657092/3093378">I know</a> it is not the same as the old trick</p>
  
  <pre><code>(*(T*)(nullptr))
  </code></pre>