title: get type of element in range based loop **directly** e.g. for "using"
body: <p>How to get type of <strong>return value</strong> <strong><em>of</em></strong> ranged-base loop elegantly?    </p>
  
  <p>I currently use this :-  (it works OK)</p>
  
  <pre><code>using Encapsulator= std::vector&lt;int&gt;;  //&lt;-- any datastructure
  using ReturnType = decltype(std::declval&lt;Encapsulator&gt;().begin().operator*());
  //^ ReturnType is "int&amp;"
  </code></pre>
  
  <p><strong>Objective:</strong> <code>ReturnType</code> is a type that fit the word <code>auto</code> in:-</p>
  
  <pre><code>for(auto returnType : an-instance-of-Encapsulator ){}
  </code></pre>
  
  <p>However, I think my above code is not elegant at all.<br>
  I feel dizzy after staring it for a long time.     </p>
  
  <h2><strong>Question</strong></h2>
  
  <p>Is there anything in <strong>standard library / syntax</strong> that works elegantly like this?   </p>
  
  <pre><code>using ReturnType = std::rangedBasedLoopType&lt;Encapsulator&gt;;    
  </code></pre>
  
  <p>I wonder that I should code <code>rangedBasedLoopType</code> myself, but I am trying to avoid reinventing the wheel.    </p>
  
  <h2>My reinventing the wheel</h2>
  
  <p>My bad ... I can't resist.  This code works OK.</p>
  
  <pre><code>template&lt;class Collection&gt; using GetReturn =
      decltype(std::declval&lt;Collection&gt;().begin().operator*());
  using ReturnType = GetReturn&lt;Encapsulator&gt;;    
  </code></pre>
  
  <p><strong>Edit (after accept answer):</strong>    </p>
  
  <p>For me, both answers are very good.  Thank a lot!<br>
  <strong>R Sahu</strong>'s is neat, while <strong>Cheers and hth. - Alf</strong>'s is more robust.<br>
  It is a pity that I can accept only one, so I select the one that suitable for my <em>small</em> project.</p>