    <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  :: Code Critique Competition 90</title>
        <link>https://members.accu.org/index.php/articles/2036</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>




<div class="xar-mod-head"><span class="xar-mod-title">Student Code Critiques from CVu journal. + CVu Journal Vol 26, #5 - November 2014</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/articles/">All</a>

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

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c183/">Code Critique</a>
<br />

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

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

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c77/">CVu</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c343/">265</a>
<br />

                                            <a href="https://members.accu.org/index.php/articles/c183-343/">Any of these categories</a>

                    -                        <a href="https://members.accu.org/index.php/articles/c183+343/">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;Code Critique Competition 90</h1>
<p><strong>Author:</strong>&nbsp;Martin Moene</p>
<p>
<strong>Date:</strong> 02 November 2014 21:04:36 +00:00 or Sun, 02 November 2014 21:04:36 +00:00</p>
<p><strong>Summary:</strong>&nbsp;Set and collated by Roger Orr. A book prize is awarded for the best entry.</p>
<p><strong>Body:</strong>&nbsp;<p>Participation in this competition is open to all members, whether novice or expert. Readers are also encouraged to comment on published entries, and to supply their own possible code samples for the competition (in any common programming language) to scc@accu.org.</p>

<p>Note: we are investigating putting code critique articles online: if you would rather not have your critique visible please inform me. (We will remove email addresses!)</p>

<h2>Last issueâ€™s code</h2>

<p class="blockquote">I'm trying to write a simple program to shuffle a deck of cards, but it crashes. What have I done wrong?</p>

<p>The code is in Listing 1.</p>

<table class="sidebartable">
	<tr>
		<td>
			<pre class="programlisting">
#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;string.h&gt;

enum
{
  black,
  red
};

enum
{
  Hearts,
  Diamonds
};

enum
{
  Clubs,
  Spades
};

typedef struct Card
{
  int color;
  int suit;
  int value;
} Card;

typedef Card Deck[52];

void LoadDeck(Deck * myDeck)
{
  int i = 0;
  for(; i &lt; 51; i++)
  {
    myDeck[i]-&gt;color = i % 2;
    myDeck[i]-&gt;suit = i % 4;
    myDeck[i]-&gt;value = i % 13;
  }
}
// -- example11.cpp â€“- (C++11 example)
#include &lt;cassert&gt;
#include &quot;wrapped_vector.hxx&quot;

int main()
{
  wrapped_vector&lt;int&gt; iVec;
  iVec.push_back(1);
  iVec.push_back(0);
  iVec.push_back(2);

  int total(0);
  for (auto &amp; p : iVec)
  {
     total += p;
  }
  assert(total == 3);

  wrapped_vector&lt;int&gt;::dump();
}

void PrintDeck(Deck * myDeck)
{
  int i = 0;
  for(;i &lt; 52; i++)
  {
    char *colors[] = {&quot;black&quot;, &quot;red&quot;};
    char *suits[][2] =
       {{&quot;clubs&quot;, &quot;spades&quot;},
        {&quot;hearts&quot;, &quot;diamonds&quot;}};    
    printf(&quot;Card %s %d of %s\n&quot;,
      colors[myDeck[i]-&gt;color],
      myDeck[i]-&gt;value,
      suits[myDeck[i]-&gt;color]
           [myDeck[i]-&gt;suit]);
  }
}

void Shuffle(Deck * myDeck)
{
  int i = 0;
  for (; i &lt; 52; i++)
  {
    int n = sizeof(Card);
    int to = rand() % 52;
    Card tmp;
    memcpy(&amp;tmp, myDeck[i], n);
    memcpy(myDeck[i], myDeck[to], n);
    memcpy(myDeck[to], &amp;tmp, n);
  }
}
// -- example11.cpp â€“- (C++11 example)
#include &lt;cassert&gt;
#include &quot;wrapped_vector.hxx&quot;

int main()
{
  wrapped_vector&lt;int&gt; iVec;
  iVec.push_back(1);
  iVec.push_back(0);
  iVec.push_back(2);

  int total(0);
  for (auto &amp; p : iVec)
  {
     total += p;
  }
  assert(total == 3);

  wrapped_vector&lt;int&gt;::dump();
}

void PrintDeck(Deck * myDeck)
{
  int i = 0;
  for(;i &lt; 52; i++)
  {
    char *colors[] = {&quot;black&quot;, &quot;red&quot;};
    char *suits[][2] =
       {{&quot;clubs&quot;, &quot;spades&quot;},
        {&quot;hearts&quot;, &quot;diamonds&quot;}};    
    printf(&quot;Card %s %d of %s\n&quot;,
      colors[myDeck[i]-&gt;color],
      myDeck[i]-&gt;value,
      suits[myDeck[i]-&gt;color]
           [myDeck[i]-&gt;suit]);
  }
}

void Shuffle(Deck * myDeck)
{
  int i = 0;
  for (; i &lt; 52; i++)
  {
    int n = sizeof(Card);
    int to = rand() % 52;
    Card tmp;
    memcpy(&amp;tmp, myDeck[i], n);
    memcpy(myDeck[i], myDeck[to], n);
    memcpy(myDeck[to], &amp;tmp, n);
  }
}
			</pre>
		</td>
	</tr>
	<tr>
		<td class="title">Listing 1</td>
	</tr>
</table>

<h2>Critiques</h2>

<h3>Paul Floyd</h3>

<p>Well, thereâ€™s quite a lot not to like in this example. On first reading, I didnâ€™t like the <code>enum</code>s. There is redundancy â€“ why two <code>enum</code>s for the suits and why a separate <code>enum</code> for the colour? The colour of a suit is something that is â€˜well knownâ€™. Also I didnâ€™t like the inconsistent capitalization. In any case these enums arenâ€™t used. I would remove the <code>color</code> field of <code>Card</code>, and infer the colour from the suit (see below for the corresponding change to <code>PrintDeck</code>).</p>

<p>The main issue is that there is confusion as to what a <code>Card</code> and what a <code>Deck</code> is. Specifically the <code>LoadDeck</code>, <code>PrintDeck</code> and <code>ShuffleDeck</code> take pointer to <code>Deck</code> arguments and treat them as arrays. They should be treated as pointers to arrays of <code>Card</code>s, not pointers to arrays of <code>Deck</code>s. Simply removing the asterisks in these prototypes (and changing <code>
-&gt;</code> pointer dereferences to <code>.</code> member accesses) will fix this extra level of indirection.</p>

<p>Next, <code>LoadDeck</code>. This only iterates over 51 cards. I would recommend using a constant like <code>CARDS_IN_DECK = 52</code>. I donâ€™t like the single loop, which works because 4 and 13 are relatively prime. If this code were used for a game like â€˜beloteâ€™, which uses 32 cards, then <code>LoadDeck</code> would no longer work correctly. Two loops for suit and value would be a little more verbose but much clearer.</p>

<p><code>PrintDeck</code> just prints values from 0 to 12. Again much clearer would be names and values offset by 1, e.g., using</p>

<pre class="programlisting">
  char *values[] = {&quot;ace&quot;, &quot;2&quot;, &quot;3&quot;, &quot;4&quot;, &quot;5&quot;,
  &quot;6&quot;, &quot;7&quot;, &quot;8&quot;, &quot;9&quot;, &quot;10&quot;,
  &quot;jack&quot;, &quot;queen&quot;, &quot;king&quot;};
</pre>

<p>The attempt to read the suit from the <code>suits</code> 2D array is wrong. This is a 2x2 array, but the ranges of the subscripts are 0..1 and 0..3. I would   make <code>suits</code> a 1D array and index it with the 0..3 suit field. Also I would infer the colour from the suit, either directly in the code or by writing a little function.</p>

<p>I can only see one fault in Shuffle. There is no test to see if <code>i</code> equals <code>to</code>, in which case the second <code>memcpy</code> is undefined. This could be corrected by using <code>memmove</code> or adding a little check like</p>

<pre class="programlisting">
  if (i == to)
  {
    continue;
  }</pre>

<p>One last point. It bothers me using common names like <code>red</code> and <code>black</code>. To avoid conflicts, Iâ€™d use some prefix like <code>FooRed</code> and <code>FooBlack</code>.</p>

<h3>Silas S.Brown</h3>

<p>Iâ€™m writing this reply on a Psion Revo PDA (made in 1999) while visiting my parents in rural West Dorset (with no Internet connection and not even a phone signal), and as I donâ€™t have a proper keyboard Iâ€™ll be brief.  (The reason why I say this at all is it might inspire other members, somehow or other. I do wish someone would come up with a decent modern version of the Revo though.)</p>

<p>Bug 1: thereâ€™s an inconsistency between <code>LoadDeck</code>, which says <code>i&lt;51</code> in the <code>for</code> loop, and <code>PrintDeck</code>, which says <code>i&lt;52</code>.  Maybe the writer was thinking <code>&lt;=</code> instead of <code>&lt;</code> when writing <code>LoadDeck</code>?  Anyway itâ€™s better to keep it consistent and write <code>&lt;52</code> in both cases (I wouldnâ€™t advocate using a constant here, because anyone who knows about decks of cards in Western culture will be familiar with the number 52, but thatâ€™s an opinion that others are entitled to disagree with).</p>

<p>Bug 2: <code>suit</code> is set to <code>i % 4</code> but there are only 2 suits of each colour.  (Personally Iâ€™d have dropped colour and just listed the 4 suits, perhaps with a <code>getColour</code> function that effectively tests bit 2, but I wonâ€™t argue if you want to represent colour explicitly.)</p>

<p>Bug 3: the modulus operations in <code>LoadDeck</code> will not do what I think you meant.  For example, all cards with odd value will also have colour set to red, whereas all cards with even value will also have colour set to black.  Rather than trying to correct this using more complex assignments, Iâ€™d suggest simply writing three nested loops thus:</p>

<pre class="programlisting">
  int pointer=0, color=0, suit=0, value=0;
  for (; color &lt; 2; color++) {
    for (; suit &lt; 2; suit++) {
      for (; value &lt; 13; value++) {
        myDeck[pointer]-&gt;color=color;
        myDeck[pointer]-&gt;suit=suit;
        myDeck[pointer]-&gt;value=value;
        pointer++;
      }
    }
  }
  assert(pointer==52);</pre>

<p>Note the final <code>assert</code> as a sanity check.  (You could also add items like <code>MaxSuits</code> and <code>MaxValues</code> to the ends of each <code>enum</code>, but itâ€™s probably not worth doing so in this small example.)  Registers are cheap these days, so itâ€™s really no big deal to write multiple loops in this way, and itâ€™s more readable than the corrected version of the one-loop approach which I wonâ€™t confuse you with.</p>

<p>The <code>Shuffle</code> function is OK (there are arguments about better approaches but letâ€™s not worry about that for now); you might want to think about seeding the random number generator (if I had a copy of the standard with me right now, Iâ€™d look up whether or not itâ€™s done for you by default).</p>

<h3>James Holland</h3>

<p>Having had a quick look at the code and given the fact that it crashes, I get the impression that the problem is all to do with pointers and structures.  In fact it is reminiscent of some of the items in Alan Feuerâ€™s <em>The C Puzzle Book</em>. I now wish I had paid more attention to what Alan was saying.  Despite this, and not being an expert on C, I thought I would make an attempt to discover the defects in the code and get the program running.</p>

<p>The first thing to notice is that the three anonymous enumerated types at the start of the listing are not referenced in the code, so I shall ignore them for the time being.  I now observe the main structure that represents the deck of cards.  It is an array of 52 cards.  Each card being a structure containing three integers representing the card colour, its suit and value respectively.  The fact that the colour of the card as well as its suit is being stored is a bit of a worry.  It is always possible to deduce the colour of the card from its suit.  Clubs and spades are always black and hearts and diamonds are always red.  Maintaining a variable to keep track of the cardâ€™s colour is redundant and runs the risk of becoming out of kilter with the colour of the suit.  It is best removed.</p>

<p>The next thing to note is that the <code>LoadDeck</code> function initialises all but the last card in the deck.  The loop variable should loop from 0 until it is not less than 52, not 51 as shown in the original listing.</p>

<p>The main problem lies in the way the loop variable, <code>i</code>, accesses the <code>Deck</code> array.  The code incorrectly manipulates the <code>myDeck</code> pointer as if it were an array of pointers to a <code>Deck</code>.  In fact, it is simply a single pointer to the <code>Deck</code>.  To correctly access the suit, for example, of the card with index <code>i</code>, the following construction should be used.</p>

<pre class="programlisting">
  (*myDeck)[i].suit</pre>

<p>This first dereferences the <code>myDeck</code> pointer to obtain the first card in the deck. The card with index <code>i</code> is then obtained by means of the <code>[]</code> operator.  Finally, the suit of the card is obtained.  With the variable to store the card colour removed, the <code>LoadDeck</code> function becomes as shown below.</p>

<pre class="programlisting">
  void LoadDeck(Deck * myDeck)
  {
    int i = 0;
    for (; i &lt; 52; i++)
    {
      (*myDeck)[i].suit = i % 4;
      (*myDeck)[i].value = i % 13;
    }
  }</pre>

<p>We now come to the <code>PrintDeck</code> function.  Again, the incorrect method of referencing the cards in the deck has been used here and can be corrected in the same way as for the <code>LoadDeck</code> function.  Also, now that the variable to store the suit colour has been removed, the way the suit colour is obtained has to be amended.  Specifically, the <code>suit</code>s array within <code>PrintDeck</code> has been simplified to become a one-dimensional array of suit names. The colour of the suit can now be obtained by taking the <code>suit</code> index of the card and determining if it is odd or even.  If the <code>suit</code> index is odd, the suit colour is red.  If the suit index is even, the suit colour is black.  This is calculated by taking the <code>suit</code> index, dividing by 2 and using the remainder as in index into the colours array.  This is achieved using the <code>%</code> operator.  The revised <code>PrintDeck</code> function is shown below. </p>

<pre class="programlisting">
  void PrintDeck(Deck *myDeck)
  {
    int i = 0;
    for (; i &lt; 52; i++)
    {
      const char *colours[] = {&quot;black&quot;, &quot;red&quot;};
      const char *suits[] = {&quot;clubs&quot;, &quot;hearts&quot;,
        &quot;spades&quot;, &quot;diamonds&quot;};
      printf(&quot;Card %s %d of %s\n&quot;,
             colours[(*myDeck)[i].suit % 2],
             (*myDeck)[i].value,
             suits[(*myDeck)[i].suit]);
    }
  }</pre>

<p>The <code>shuffle</code> function, like the previous two, incorrectly references the cards in the deck and can be corrected in a similar way.</p>

<pre class="programlisting">
  void Shuffle(Deck * myDeck)
  {
    int i = 0;
    for (; i &lt; 52; i++)
    {
      int n = sizeof (Card);
      int to = rand() % 52;
      Card temp;
      memcpy(&amp;temp, &amp;(*myDeck)[i], n);
      memcpy(&amp;(*myDeck)[i], &amp;(*myDeck)[to], n);
      memcpy(&amp;(*myDeck)[to], &amp;temp, n);
    }
  }</pre>

<p>The program should now work as expected.  Incidentally, there is no point in initialising the <code>Deck</code> array with all zeroes as is done in the second statement of <code>main()</code>.  The <code>Deck</code> is correctly initialised by the (revised) <code>LoadDeck</code> function.</p>

<h3>Marcel MarrÃ©</h3>

<p>The code has several problems. The one actually leading to the crash is two different interpretations of the <code>Card</code> member <code>suit</code>. In <code>LoadDeck</code>, <code>suit</code> is initialised for each card with a value from 0 to 3. In <code>PrintDeck</code>, however, the strings for the suits are arranged in a two-dimensional array of two colours by two suits per colour. When these strings are used in the <code>printf</code> statement, the <code>Card</code>â€™s suit ranges from 0 to 3, and we read beyond the valid range of the array. We thus get an undefined <code>char*</code> for <code>printf</code> to output, which is liable to crash.</p>

<p>Let us fix <code>LoadDeck</code>. Apart from the inconsistent initialisation of <code>suit</code>, the function also initialises only a total of 51 cards. This does not lead to a crash, because the whole deck has been <code>memset</code> with 0s. This does mean, however, that one card is missing from the deck, and one card (value, suit and color all 0) is in the deck twice.</p>

<p>A more readable, logical version of <code>LoadDeck</code> would therefore be:</p>

<pre class="programlisting">
  void LoadDeck(Deck * myDeck)
  {
    int i = 0;
    for(; i &lt; 52; i++)
    {
      myDeck[i]-&gt;color = i % 2;
      myDeck[i]-&gt;suit = (i / 2) % 2;
      myDeck[i]-&gt;value = i % 13;
    }
  }</pre>

<p>The initialised deck is somewhat oddly sorted, so another change would be to initialise <code>value</code> thus: </p>

<pre class="programlisting">
    myDeck[i]-&gt;value = (i / 4) % 13; </pre>

<p>which is easier to follow. </p>

<p>Another point is that the <code>enum</code>s were not actually used at all. Using them to initialise a card is possible, although the following card: </p>

<pre class="programlisting">
  Card myCard;
  myCard.color = black;
  myCard.suit = Hearts;
  myCard.value = 5;</pre>
  
<p>will be displayed as <code>&quot;Card black 5 of Clubs&quot;</code>.</p>

<h2>Commentary</h2>

<p>The code demonstrates confusion with pointers and arrays, not helped by the way that in C arrays will implicitly â€˜decayâ€™ to pointers to the first element in the array. (There are other problems, but I think those were more straightforward to understand and resolve.)</p>

<p>The code creates a single <code>Deck</code> object called <code>myDeck</code> and passes its address to <code>LoadDeck</code>. Inside <code>LoadDeck</code> this pointer treated as an array (<code>myDeck[i]</code>) of <code>Deck</code> objects. Unfortunately weâ€™ve only passed in a single <code>Deck</code> and not an array of them, so every iteration round the loop after the first one accesses data beyond the end of <code>myDeck</code> and hence the crash.</p>

<p>Following the array subscript we have a pointer â€“ what is this actually doing? Perhaps a simpler example will help:</p>

<pre class="programlisting">
  struct data { int field; } items[10];
  items-&gt;field;</pre>

<p>The second line uses <code>items</code> which is of type â€˜<code>array</code> of 10 <code>struct data</code>â€™ but this type decays to a pointer to the first item when used in this context. The second line is equivalent to:</p>

<pre class="programlisting">
  items[0].field</pre>
  
<p>So returning to <code>LoadDeck</code> the first assignment to <code>myDeck</code> could be written as:</p>

<pre class="programlisting">
  myDeck[i][0].color = i % 2;</pre>

<p>The pair of subscripts makes it a little more obvious whatâ€™s gone wrong, as a <code>Deck</code> is a simple array of one dimension.</p>

<p>It can be helpful, even when the data type is an array, to wrap it inside a <code>struct</code> for clarity.</p>

<pre class="programlisting">
  typedef struct Deck
  {
    Card card[52];
  } Deck;</pre>
  
<p>With this restructuring the â€˜brokenâ€™ <code>LoadDeck</code> function no longer compiles as the <code>struct</code>, unlike an array, is no longer interchangeable with a pointer type; it can now be fixed by changing it to, for example:</p>

<pre class="programlisting">
  void LoadDeck(Deck * myDeck)
  {
    int i = 0;
    for(; i &lt; 52; i++)
    {
      myDeck-&gt;card[i].color = i % 2;
      myDeck-&gt;card[i].suit = i % 4;
      myDeck-&gt;card[i].value = i % 13;
    }
  }</pre>

<p>While more verbose, it may be more understandable.</p>

<h2>The winner of CC89</h2>

<p>This critique contained several different problems as well as the â€˜it crashesâ€™ problem originally reported. The entrants did a pretty good job of identifying these problems. Paul pointed out that the code relies on 13 and 4 being mutually co-prime and Silas noted that populating <code>suit</code> and <code>color</code> separately was error-prone and the code as shown assigned the <em>wrong</em> color to some of the suits. James actually changed the code to remove the problematic field color. I thought Marcelâ€™s explanation of why the 2-dimensional <code>suit</code>s array was wrong was the clearest.</p>

<p>Silas also pointed out that it would be a good idea to seed the random number generator as otherwise the likelihood is that every run of the program will shuffle the deck exactly the same way!</p>

<p>Overall it was a hard call but I eventually decided to award Silas the prize for this code critique</p>

<h2>Code Critique 90</h2>

<p>(Submissions to scc@accu.org by December 1st)</p>

<p class="blockquote">Iâ€™m trying to instrument some code to find out how many iterator operations are done by some algorithms I use that operate on vectors. Iâ€™ve got some code that worked with C++03 and Iâ€™m trying to get it working with the new C++11 features. Mostly the C++11 code is just nicer but I canâ€™t get my wrapper vector to work with the new style for loop. Iâ€™ve stripped out the instrumentation for other methods in this example code so it only counts the increment operations and when I run the two simple examples below I get this output:</p>

<pre class="programlisting">
    C: &gt;example03.exe
    Increments: 3

	C: &gt;example11.exe
	Increments: 0</pre>

<p class="blockquote">I expected the same output from both examples as all Iâ€™ve done is re-write the <code>for</code> loop using the new style <code>for</code> syntax.â€™</p>

<p>Can you find out why it doesnâ€™t work as expected and suggest some ways to improve (or replace) the mechanism being used?</p>

<p>The code is in Listing 2.</p>

<table class="sidebartable">
	<tr>
		<td>
			<pre class="programlisting">
// -- wrapped_vector.hxx --
#include &lt;vector&gt;

template&lt;typename T&gt;
struct wrapped_vector : std::vector&lt;T&gt;
{
  typedef typename std::vector&lt;T&gt; vector;
  typedef typename vector::size_type
    size_type;
  // Sort the constructors
  #if __cplusplus &gt;= 201103
    using vector::vector; // Nice :-)

  #else
    // legacy: need to spell them out ...
    wrapped_vector() {}

    explicit wrapped_vector(size_type n,
      const T&amp; value = T())
    : vector(n, value) {}

    template &lt;class InputIterator&gt;
    wrapped_vector(InputIterator first,
      InputIterator last)
    : vector(first, last) {}
    // ...
  #endif // C++11

  // print the stats
  static void dump();

  // instrumented iterator
  struct iterator : vector::iterator
  {
    typedef typename vector::iterator base;
    iterator() {}
    iterator(base it) : base(it) {}
    iterator&amp; operator ++();
    // (other instrumented methods removed)

    static int increments;
  };

  // const_iterator (unused so removed)
};

#include &quot;wrapped_vector.inl&quot;

// -- wrapped_vector.inl --
#include &lt;iostream&gt;

template &lt;typename T&gt;
void wrapped_vector&lt;T&gt;::dump()
{
  std::cout
    &lt;&lt; &quot;Increments: &quot;
    &lt;&lt; iterator::increments
    &lt;&lt; std::endl;
}

template &lt;typename T&gt;

typename wrapped_vector&lt;T&gt;::iterator&amp; wrapped_vector&lt;T&gt;::iterator::operator ++()
{
  base::operator ++();
  ++increments;
  return *this;
}

template &lt;typename T&gt;
int wrapped_vector&lt;T&gt;::iterator::increments;

// -- example03.cpp â€“
// (also works with C++11)
#include &lt;cassert&gt;
#include &quot;wrapped_vector.hxx&quot;

int main()
{
  wrapped_vector&lt;int&gt; iVec;
  iVec.push_back(1);
  iVec.push_back(0);
  iVec.push_back(2);

  int total(0);
  for (wrapped_vector&lt;int&gt;::iterator
    iter(iVec.begin()), past(iVec.end());
    iter != past; ++iter)
  {
    total += *iter;
  }
  assert(total == 3);

  wrapped_vector&lt;int&gt;::dump();
}

// -- example11.cpp â€“- (C++11 example)
#include &lt;cassert&gt;
#include &quot;wrapped_vector.hxx&quot;
int main()
{
  wrapped_vector&lt;int&gt; iVec;
  iVec.push_back(1);
  iVec.push_back(0);
  iVec.push_back(2);
  int total(0);
  for (auto &amp; p : iVec)
  {
     total += p;
  }
  assert(total == 3);
  wrapped_vector&lt;int&gt;::dump();
}
			</pre>
		</td>
	</tr>
	<tr>
		<td class="title">Listing 2</td>
	</tr>
</table>

<p>You can also get the current problem from the accu-general mail list (next entry is posted around the last issueâ€™s deadline) or from the ACCU website (<a href="http://www.accu.org/journals/">http://www.accu.org/journals/</a>). This particularly helps overseas members who typically get the magazine much later than members in the UK and Europe.</p>
</p>
<p><strong>Notes:</strong>&nbsp;</p>
<p><em>More fields may be available via dynamicdata ..</em></p>
</div>
</channel>
</rss>
