title: What expressions yield a reference type when decltype is applied to them?
body: <p>I was reading C++ Primer and couldn't quite understand when an expression yields an object type, and when it yields a reference type to the object.</p>
  
  <p>I quote from the book: </p>
  
  <blockquote>
    <ol>
    <li>When we apply decltype to an expression that is not a variable, we get the type that  > that expression yields.</li>
    <li>Generally speaking, decltype returns a reference type for expressions that yield 
    objects that can stand on the left-hand side of the assignment.</li>
    </ol>
  </blockquote>
  
  <p>Considering the code below:</p>
  
  <pre><code>int i = 3, *ptr = &amp;i, &amp;ref = i;
  decltype(ref + 0) j;
  </code></pre>
  
  <p>In the above code, the expression "ref + 0" results in an inherent operation of addition of  value of the object that ref refers to, i and 0. Hence, going by the first rule the expression yields an int type.
  But going by the second rule, as the expression yields the type of an object that can stand on the left hand side of an assignment (in this case int), shouldn't the decltype yield a ref to int(int&amp;) type? </p>
  
  <p>The book also says, for the following code</p>
  
  <pre><code>decltype(*ptr) k;
  </code></pre>
  
  <p>k has type int&amp; and not int, the type which the expression results in.</p>
  
  <p>It also says that for an assignment expression like in code below</p>
  
  <pre><code>decltype(a = b) l;
  </code></pre>
  
  <p>l would have the type of reference to object on the left hand side of the assignment operation.</p>
  
  <p>How would we know which expressions yield the object type and which yield the reference to the object type?</p>