    <rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:admin="http://webns.net/mvcb/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:content="http://purl.org/rss/1.0/modules/content/">
     <channel>
        <title>ACCU  :: editor &lt;&lt; letters;</title>
        <link>https://members.accu.org/index.php/journals/492</link>
        <description>Professionalism in Programming</description>
        <dc:language>en-us</dc:language> 
        <dc:creator>Administrator</dc:creator> 
        <admin:generatorAgent rdf:resource="http://www.xaraya.org" /> 
        <admin:errorReportsTo rdf:resource="mailto:webeditor@accu.org" />
       <sy:updatePeriod>hourly</sy:updatePeriod>
       <sy:updateFrequency>1</sy:updateFrequency>
       <docs>http://backend.userland.com/rss</docs>


        <h2>Journal Articles</h2>


<div class="xar-mod-head"><span class="xar-mod-title">Overload Journal #37 - May 2000 + Programming Topics + Letters to the Editor</span></div>

<table border="0" cellpadding="1" cellspacing="0">
    <tbody>
    <tr>
        <td valign="top">
            Browse in :
       </td>
       <td valign="top">

                                            <a href="https://members.accu.org/index.php/journals/">All</a>

                     &gt;                         <a href="https://members.accu.org/index.php/journals/c76/">Journals</a>

                     &gt;                         <a href="https://members.accu.org/index.php/journals/c78/">Overload</a>

                     &gt;                         <a href="https://members.accu.org/index.php/journals/c167/">37</a>
                    (7)
<br />

                                            <a href="https://members.accu.org/index.php/journals/">All</a>

                     &gt;                         <a href="https://members.accu.org/index.php/journals/c13/">Topics</a>

                     &gt;                         <a href="https://members.accu.org/index.php/journals/c65/">Programming</a>
                    (877)
<br />

                                            <a href="https://members.accu.org/index.php/journals/">All</a>

                     &gt;                         <a href="https://members.accu.org/index.php/journals/c184/">Journal Columns</a>

                     &gt;                         <a href="https://members.accu.org/index.php/journals/c186/">LettersEditor</a>
                    (132)
<br />

                                            <a href="https://members.accu.org/index.php/journals/c167-65-186/">Any of these categories</a>

                    -                        <a href="https://members.accu.org/index.php/journals/c167+65+186/">All of these categories</a>
<br />
</td>
   </tr>
   </tbody>
</table>




<div class="xar-error">
   <p>
 <strong>Note:</strong> when you create a new publication type,
the articles module will automatically use the templates
<em>user-display-[publicationtype].xt</em>
and <em>user-summary-[publicationtype].xt</em>.
If those templates do not exist when you try to preview or display a new article,
you'll get this warning :-)  Please place your own templates in themes/<em>yourtheme</em>/modules/articles . The templates will get the extension .xt there. </p>
</div>
<div class="xar-norm xar-standard-box-padding">
   <h1><strong>Title:</strong>&nbsp;editor &lt;&lt; letters;</h1>
<p><strong>Author:</strong>&nbsp;</p>
<p>
<strong>Date:</strong> 26 May 2000 17:50:57 +01:00 or Fri, 26 May 2000 17:50:57 +01:00</p>
<p><strong>Summary:</strong>&nbsp;</p>
<p><strong>Body:</strong>&nbsp;<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e20" id="d0e20"></a></h2>
<h3>mutable</h3>
</div>
<p>I have had two replies to my 'Mutable' letter from
Overload-34.</p>
</div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e24" id="d0e24"></a>mutable -
Defensive coding idea from Roger Woollett</h2>
</div>
<p>A possible solution is to use an object of class type to control
the <tt class="literal">for</tt> loop.</p>
<pre class="programlisting">
class index {
public:
  index(int i){value= i;}
  operator int(){return value;}
  index operator++()
       {return ++value;}
private:
  int value;
};
</pre>
<p>You can now write:</p>
<pre class="programlisting">
for(index i=0; i&lt;10; ++i) fn(i);
</pre>
<p>This will work if <tt class="function">fn</tt> takes an
<tt class="type">int</tt> but not if it takes <tt class=
"type">int&amp;</tt>.</p>
<p><span class="emphasis"><em>Roger Woollett</em></span> <tt class=
"email">&lt;<a href=
"mailto:rwoollett@cix.compulink.co.uk">rwoollett@cix.compulink.co.uk</a>&gt;</tt></p>
</div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e55" id="d0e55"></a>mutable -
Defensive coding from Andy Robb</h2>
</div>
<p>Here are a couple of alternatives for you:</p>
<pre class="programlisting">
for(int i=0; i&lt;10; ++i)
     fn(int(i));
</pre>
<p>The inline construction of <tt class="literal">int(i)</tt>
returns a (<tt class="type">int const &amp;</tt>) which would catch
the coder's change.</p>
<p>Alternatively:</p>
<pre class="programlisting">
for(int i=0; i&lt;10; ++i){
  int const  &amp; ci = i;
  fn(ci);
}
</pre>
<p>This has the advantage that the reference does not change and
can be optimised out of the loop.</p>
<p><span class="emphasis"><em>Andy Robb</em></span> <tt class=
"email">&lt;<a href=
"mailto:Andy.ROBB@lyonnaisecable.com">Andy.ROBB@lyonnaisecable.com</a>&gt;</tt></p>
</div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e82" id="d0e82"></a>mutable Aaron
Ridout</h2>
</div>
<p>Many thanks to Andy and Roger for replying. Andy's solutions are
great for the original problem if I were re-visiting the code for
low impact (cost / risk) maintenance.</p>
<p>However, if I were writing some green field code, I'd prefer
Roger's idea as it is a more object oriented solution, but I have
yet to test its impact on speed. It would also have to be converted
into a template in order to work with any type, STL iterators for
example as well as POD types such as <tt class="type">int</tt>.</p>
<p>Furthermore, this should work with the <tt class=
"function">for_each</tt> template and this new template object
should provide a wrapper for the requirements of a set to be
iterated over and the function to be called via <tt class=
"function">for_each</tt>, then one could write:</p>
<pre class="programlisting">
void fn( const int &amp;i ) ;
Iterate&lt;int,0,10,fn&gt;
</pre>
<p>or</p>
<pre class="programlisting">
std::list&lt;int&gt; i ;
Iterate&lt;std::list&lt;int&gt;,i.begin(),i.end(),fn&gt;
</pre>
<p>Perhaps fn should be a member of Iterate, then it could read the
index for itself rather than having to be passed in as a formal
parameter...</p>
<p><span class="emphasis"><em>Aaron Ridout</em></span> <tt class=
"email">&lt;<a href=
"mailto:Aaron.Ridout@signal.co.uk">Aaron.Ridout@signal.co.uk</a>&gt;</tt></p>
</div>
</p>
<p><strong>Notes:</strong>&nbsp;</p>
<p><em>More fields may be available via dynamicdata ..</em></p>
</div>
</channel>
</rss>
