title: What's the C++98 equivalent of the auto iterator reference?
body: <p>My development environment has RHEL 5.8 which does not support GCC 4.8+ modern (C++11+) compilers.  I anticipate that someday we'll get there, so I have a header file where I define macros based on C++11 support levels so I can do something like this:</p>
  
  <pre><code>#if defined(CPP11_auto_type_inference) &amp;&amp; defined(CPP11_range_based_for_loops)
    for (auto vit : args)
  #else
    std::vector&lt;std::string&gt;::const_iterator vit, vend;
    for (vend=args.end(),vit=args.begin(); vit != vend; ++vit)
  #endif
    { // process arguments...
      std::cout &lt;&lt; "Processing \"" &lt;&lt; *vit &lt;&lt; '"' &lt;&lt; std::endl;
      . . .
    } // end "process arguments" loop
  </code></pre>
  
  <p>So, what I'm trying to do in C++98 is the equivalent of the iterator <strong>reference</strong> (or is it more accurate to say "a dereferenced iterator"?), like below:</p>
  
  <pre><code>for (auto&amp; it : args)
    std::cout &lt;&lt; "Processing \"" &lt;&lt; it &lt;&lt; '"' &lt;&lt; std::endl;
  </code></pre>
  
  <p>For the life of me, I cannot figure out how to get a dereferenced iterator (or iterator reference) in C++98.  I can simulate, as below:</p>
  
  <pre><code>#if defined(CPP11_auto_type_inference) &amp;&amp; defined(CPP11_range_based_for_loops)
    for (auto&amp; it : args) {
  #else
    std::vector&lt;std::string&gt;::const_iterator vit, vend;
    for (vend=args.end(),vit=args.begin(); vit != vend; ++vit) {
      std::string it(*vit);
  #endif
      std::cout &lt;&lt; "Processing \"" &lt;&lt; it &lt;&lt; '"' &lt;&lt; std::endl;
      . . .
    }
  </code></pre>
  
  <p>... but I'm <em>really hoping</em> that is not the answer.</p>
  
  <p>What is the C++98 equivalent of <code>for (auto&amp; it : vec)</code>, or is it not possible?  Is it only possible to "simulate" it but dereferencing the iterator and creating a copy each iteration?</p>
  
  <p>And if that be the case, is that what is going on "under the covers" with C++11 <code>auto&amp;</code> syntax?   (I have to believe this is <em>not the case</em>.)  In any case, is it more costly to use <code>for (auto&amp; it : vec)</code> than <code>for (auto it : vec)</code>?</p>
  
  <p>Thank you in advance for your insight.</p>