    <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 91</title>
        <link>https://members.accu.org/index.php/articles/2049</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">CVu Journal Vol 26, #6 - January 2015</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/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/c345/">266</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 91</h1>
<p><strong>Author:</strong>&nbsp;Martin Moene</p>
<p>
<strong>Date:</strong> 02 January 2015 21:27:18 +00:00 or Fri, 02 January 2015 21:27:18 +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 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 1.</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 1</td>
	</tr>
</table>

<h2>Critiques</h2>

<h3>Alex Paterson</h3>

<p>The problem area is around analysis of algorithm performance, with this case specifically looking at iterator usage. Analysis of code in this manner often proves tricky, but can provide vital insights into how efficient our code actually is rather than just how efficient we think it is.</p>

<p>The C++03 and C++11 code specimens have one major difference that is the root of the problem; the type of iterator used to iterate over the collection is different â€“ one of them using the instrumented iterator and the other is not. This problem is introduced by the different method of iterating over the collection in the C++11 code. The C++03 method of declaring and incrementing an iterator is replaced with the range-based <code>for</code> loop.</p>

<p>The range-based <code>for</code> statement (RBF) is type of statement that can be referred to as â€˜syntactic sugarâ€™; it is a construct that performs some task that is already possible using other language features, but does so with simpler and/or a more succinct syntax. In other words, the RBF does not add any new functionality to C++, but it reduces the amount or code we have to write (and thus read and maintain). The C++ standard specifies how RBF usage translates into the more long-winded syntax, encouraging compiler writers to add support for the new syntax by implementing it in terms of existing functionality. If I ignore usage for array types, the standard states that the compiler will use argument-dependent lookup to try and find suitable <code>begin()</code> and <code>end()</code> functions for the given type; if all goes well, the type of iterator used in the RBF loop will be the type returned from <code>begin()</code>.</p>

<pre class="programlisting">
  class X { /* â€¦ */ };
  vector&lt;X&gt; container_of_x;

  // C++11 Range Based For
  for (auto&amp; x : container_of_x)
  { /* do something with x */ }

  //Long Winded Equivalent
  for (vector&lt;X&gt;::iterator it =
    begin(container_of_x);
    it != end(container_of_x); ++it)
  {
    X&amp; x = *it;
    /* do something with x */
  }</pre>

<p>The C++03 code compiles and produces the expected output when compiled against either the C++03 or C++11 standard, which reinforces the suspicion that the two problem code specimens are not equivalent. Making a small change in the C++03 code specimen to use <code>auto</code> as the iterator type reveals the problem behaviour.</p>

<pre class="programlisting">
  //C++03 Code
  for (wrapped_vector&lt;int&gt;::iterator
    iter(iVec.begin()), past(iVec.end());
    iter != past; ++iter)
  {
    total += *iter;
  }
  // Output: Increments: 3

  //C++03 Code Modified
  for (auto iter(iVec.begin()),
      past(iVec.end());
      iter != past; ++iter)
    {
      total += *iter;
    }
  // Output: Increments: 0</pre>

<p>The conclusion from the output is that the loop using <code>auto</code> is not using the instrumented iterator. In case this is not obvious, we can stream out the type of iterator using <code>typeid(iter).name()</code>, which shows different type names. [<em>Editor: it </em>may<em> show different type names â€“ but the usefulness of the output from <code>name()</code> varies widely.</em>]</p>

<p>In both cases <code>iVec.begin()</code> is used to initialise the iterator (which returns <code>std::vector&lt;T&gt;::iterator</code>), but in the first loop this is wrapped in the instrumented iterator (of type <code>wrapped_vector&lt;T&gt;::iterator</code>). In the second loop, the wrapper is not present, so the instrumentation code never gets run. Additionally, a better name for the iterator type in <code>wrapper_vector</code> could have perhaps made it easier to spot this issue; as the code stands, there are two definitions of iterator in <code>wrapped_vector&lt;T&gt;</code>, one at the <code>wrapped_vector&lt;T&gt;</code> scope and another one at the <code>std::vector&lt;T&gt;</code> scope.</p>

<p>This explains the behaviour we are seeing, but the question now is how can we change things so that we can still use the pretty new syntax and be able to determine how many iterator increments occur?</p>

<p>Inheriting from <code>std::vector</code> in this manner is not recommended (see stackoverflow â€“ <a href="http://stackoverflow.com/questions/ 6806173/subclass-inherit-standard-containers">http://stackoverflow.com/questions/ 6806173/subclass-inherit-standard-containers</a>, <a href="http://stackoverflow.com/ questions/4353203/thou-shalt-not-inherit-from-stdvector">http://stackoverflow.com/ questions/4353203/thou-shalt-not-inherit-from-stdvector</a>). Using private inheritance in the original code improves the situation [slightly] and reveals that three functions are being used from the base class: <code>begin()</code>, <code>end()</code> and <code>push_back()</code>. <code>using push_back;</code> can be used to pull the private base class declaration into public visibility, however we need to write our own implementations of <code>begin()</code> and <code>end()</code> in order to provide an instrumented iterator using our wrapper class, as follows (remembering that at the <code>wrapped_vector&lt;T&gt;</code> scope, the type â€˜iteratorâ€™ is our instrumented iterator);</p>

<pre class="programlisting">
  template&lt;typename T&gt;
  struct wrapped_vector : private std::vector&lt;T&gt;
  {
  //â€¦
    using std::vector&lt;T&gt;::push_back;
    iterator begin()
    { return iterator(std::vector&lt;T&gt;::begin()); }

    iterator end()
    { return iterator(std::vector&lt;T&gt;::end()); }
    //â€¦
  };</pre>

<p>This gives us the expected output for our C++11 loop, however it is still inheriting from <code>std::vector</code> so is far from ideal. Extending <code>std::vector</code> in this manner is not recommend, even if it does yield the right results. The standard library collection classes are not designed to be extended. <code>std::vector&lt;T&gt;</code> does not have a virtual destructor and we therefore run the risk of the instrumented vectorâ€™s destructor not getting run.</p>

<p>This would lead to a resource leak if our vector class had any non-static member variables. E.g.</p>

<pre class="programlisting">
  std:vector&lt;int&gt;* my_naked_vector_ptr
    = new wrapped_vector&lt;int&gt;;
  delete my_naked_vector_ptr; // &lt;-- risk of
                              // resource leak!</pre>

<p>So if inheritance is not an option, then how can we analyse how efficient our algorithms are? Here are two options that I have used: alter the behaviour of the container or alter the behaviour of the contained objects. To alter the behaviour of the container, we can provide a custom allocator to track allocations of the contained objects. To alter the behaviour of the contained objects, we can substitute a test object that can track events like construction, destruction, assignment and comparison.</p>

<p>Iâ€™ve found that using a test object is the preferred technique as it provides far more opportunities to examine different behaviours, but there are cases where it is not desirable/possible to change the type of the contained objects, so altering the container is still a useful technique to know.</p>

<h4>Altering the container</h4>

<p>The template parameters of the standard containers provide the opportunity to specify not only the type of object that is contained, but also how they are allocated.</p>

<p>We implement an instrumented allocator by placing our counter increment code before we delegate the <code>allocate</code> and <code>construct</code> calls to their default implementations.</p>

<pre class="programlisting">
  template&lt;typename T&gt; struct wrapped_allocator
    : std::allocator&lt;T&gt;
  {
    typedef T* pointer;
    pointer allocate(
      typename std::allocator&lt;T&gt;::size_type n,
      std::allocator&lt;void&gt;::const_pointer hint
         = 0)
    {
      allocations++;
      return std::allocator&lt;T&gt;::allocate(n,
        hint);
    }
    template&lt; class U, class... Args &gt;
    void construct( U* p, Args&amp;&amp;... args )
    {
      constructions++;
      return std::allocator&lt;T&gt;::construct(p,
        std::forward&lt;Args&gt;(args)...);
    }
    static void reset_counters()
    { allocations = constructions = 0; }
    static void dump_counters()
    {
      std::cout
        &lt;&lt; &quot;allocations: &quot; &lt;&lt; allocations 
        &lt;&lt; &quot;, constructions: &quot; &lt;&lt; constructions
        &lt;&lt; std::endl;
    }
    static int allocations;
    static int constructions;
  };
  template&lt;typename T&gt; int
    wrapped_allocator&lt;T&gt;::allocations;
  template&lt;typename T&gt; int
    wrapped_allocator&lt;T&gt;::constructions;
  int main()
  {
    std::vector&lt;int, wrapped_allocator&lt;int&gt;&gt; 
      v{5,4,3,2,1};
    wrapped_allocator&lt;int&gt;::reset_counters();
    std::sort(begin(v), end(v));
    wrapped_allocator&lt;int&gt;::dump_counters();
  }</pre>

<p>Output: allocations: 0, constructions: 0</p>

<p>Oh, so maybe not so useful in this case, but what about comparisons? For this we need to move to our own object where we can define our own comparison operator.</p>

<h4>Using a test object</h4>

<p>A test object provides a way to examine the behaviour of our algorithm by instrumenting various functions. I usually add instrumentation to the constructors, assignment operator and inequality operators, but of course what gets instrumented depends on what we are trying to find out.</p>

<p>Combining these typical traces together, we can get a pretty good picture of what the algorithm is doing in terms of object creation and comparison.</p>

<pre class="programlisting">
  class CTestObject
  {
  public:
    CTestObject(int n) :
      m_payload(n)
    { constructions++; }
    CTestObject(const CTestObject&amp; src) :
      m_payload(src.m_payload)
    { constructions++; }
    CTestObject&amp; operator=(
      const CTestObject&amp; rhs)
    {
      assignments++;
      m_payload = rhs.m_payload;
      return *this;
    }
  friend bool operator&lt;(const CTestObject&amp; lhs,
    const CTestObject&amp; rhs)
  {
    CTestObject::comparisons++;
    return lhs.m_payload &lt; rhs.m_payload;
  }
  friend bool operator==(const CTestObject&amp; lhs,
    const CTestObject&amp; rhs)
  {
    CTestObject::comparisons++;
    return lhs.m_payload == rhs.m_payload;
  }
  static void reset_counters()
  {
    assignments = constructions = comparisons=0;
  }
  static void dump_counters()
  {
    std::cout &lt;&lt; &quot;CTestObject, assignments: &quot; 
      &lt;&lt; assignments &lt;&lt; &quot;, constructions: &quot;
      &lt;&lt; constructions &lt;&lt; &quot;, comparisons: &quot;
      &lt;&lt; comparisons &lt;&lt; std::endl;
  }
  private:
    int m_payload;
    static int assignments;
    static int constructions;
    static int comparisons;
  };
  int CTestObject::assignments;
  int CTestObject::constructions;
  int CTestObject::comparisons;
  int main()
  {
    std::vector&lt;CTestObject&gt; v{5,4,3,2,1};
    CTestObject::reset_counters();
    std::sort(begin(v), end(v));
    CTestObject::dump_counters();
  }</pre>

<p>Output: CTestObject, assignments: 16, constructions: 8, comparisons: 9</p>

<p>Of course, the number of assignments, constructions or comparisons is not necessarily the be-all and end-all of whether you have a good algorithm. It may be more important in certain cases to ensure that your algorithm is cache-friendly, which may mean extra allocations or a significant increase in the number of comparisons, but it may ultimately be faster.</p>

<h3>James Holland</h3>

<p>I may have the wrong end of the stick, but I do not think there is much wrong with the authorâ€™s code. It does exactly what is required. Specifically, it counts and displays the number of <code>iterator</code> increment operations. The confusing thing, perhaps, is that the C++11 style range-based <code>for</code> loop shown in the code listing does not use <code>iterator</code>s. It works directly on the type the <code>vector</code> contains, namely, <code>int</code>s. This is why a count of zero <code>iterator</code> increment operations are displayed when using the C++11 loop.</p>

<p>If the author wants to monitor the operations performed on <code>int</code>s, one way of proceeding is to replace the plain <code>int</code>s contained in the vector with a class with the same behaviour as <code>int</code>s but with additional instrumentation. This will allow the number of operations performed on the instrumented class to be counted. One version of such a class, named <code>My_int</code> is listed below.</p>

<pre class="programlisting">
  class My_int
  {
    int i;
    static int operator_plus_plus;
    static int operator_plus_equals;
    public:
    My_int(int ii):i(ii){}
    My_int &amp; operator+=(My_int my_int)
    {
      i += my_int.i;
      ++operator_plus_equals;
      return *this;
    }
    My_int &amp; operator++()
    {
      ++i;
      ++operator_plus_plus;
      return *this;
    }
    static void dump_operator_plus_plus()
    {
      std::cout &lt;&lt; &quot;operator++(): &quot;
        &lt;&lt; operator_plus_plus &lt;&lt; std::endl;
    }
    static void dump_operator_plus_equals()
    {
      std::cout &lt;&lt; &quot;operator+=(): &quot;
        &lt;&lt; operator_plus_equals &lt;&lt; std::endl;
    }
  };
  int My_int::operator_plus_plus = 0;
  int My_int::operator_plus_equals = 0;</pre>

<p><code>My_class</code> includes definitions of <code>operator+=()</code> and <code>operator++()</code> that when called increment corresponding static members <code>operator_plus_equals</code> and <code>operator_plus_plus</code>. Other operations could be defined if required.</p>

<p>All the author has to do is replace the <code>vector</code> of <code>int</code>s with a vector of <code>My_ints</code>, execute the algorithms that use the <code>vector</code> and then call <code>My_int</code> member functions <code>dump_operator_plus_plus()</code> and <code>dump_operator_plus_equals()</code> to display the total count of operations.</p>

<p>Incidentally, it is interesting to consider the construction of the C++03 style <code>for</code> loop. The author has declared a variable, named <code>past</code>, and assigned it the value of <code>iVec.end()</code>. The loop then used past, as opposed to <code>iVec.end()</code>, to determine when to terminate. I was wondering what the advantage of this method affords. I can only think it is marginally faster. It would be interesting to hear what others have to say about this construction.</p>

<h2>Commentary</h2>

<p>This critique shows how hard it can be to derive from a class that is not designed for derivation. In particular, if new methods are added to the base class the assumptions used to originally produce the derived class may fail completely. C++11 added methods to the many of the standard classes, such as vector and its iterators, as well as mechanisms to support the â€˜range-base forâ€™ syntax.</p>

<p>The fundamental problem is that none of the methods of vector and the iterator are virtual, and so it is all too easy to call one of the original methods being overloaded. In the presenting case that's what has happened to the iterator type: the fragment for <code>(auto &amp; p : iVec)</code> deduces the type of the underlying iterator as a â€˜vanillaâ€™ vector iterator rather than the wrapped iterator type.</p>

<p>In this case the fix is simple: add member functions <code>begin()</code> and <code>end()</code> to the <code>wrapped_vector</code>:</p>

<pre class="programlisting">
  iterator begin() { return vector::begin(); }
  iterator end() { return vector::end(); }</pre>

<p>to ensure â€“ in this case, anyway â€“ that the range-based <code>for</code> loop uses the desired iterator.</p>
<p>Alexâ€™s suggestion of using private inheritance is a good solution to the difficulty as there is then no implicit conversion (outside the wrapped type) to the underlying class, and so missing methods in the wrapped class will normally cause compilation errors rather than silently using methods from the base â€“ as happened here. (This also prevents the dangerous conversion to a base class without a virtual destructor.)</p>

<p>The presenting problem, â€œ<em>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</em>â€ begs the question of <em>why</em> â€“ I strongly suspect thereâ€™s a performance or scalability problem somewhere.</p>

<p>It is often better to instrument the whole program, or a small test program, using standard tools (you may recall articles about the valgrind set of tools in recent issues of <em>Overload</em>) as otherwise the danger is, as Alex points out, that the measure you are collecting is not the right one.</p>

<h2>The winner of CC90</h2>

<p>Alex and James both suggest instrumenting the payload rather than the iterator; although this mechanism may not permit exactly the same measurement it does provide a clean way to instrument other operations.</p>

<p>Alex also gave clear explanation of why the code was broken so I am happy to award him the prize for this critique.</p>

<h2>CC89 repriseâ€¦</h2>

<p>Silas Brown wrote in, following his entry in <em>CVu</em> 26.5, to say:</p>

<p class="blockquote">In Code Critique 89 I incorrectly stated that 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. This is not the case: as pointed out by Paul Floyd in his critique on the same page, the single loop works because 4 and 13 are relatively prime. The value is taken modulus 13, so the iterations are out of phase and eventually all combinations will be assigned. We can confirm that simply enough by typing the following into a Python prompt:</p>

<pre class="programlisting">
      sorted((i%4,i%13) for i in range(52)) == \
      [(x,y) for x in range(4) for y in range(13)]</pre>

<p class="blockquote">and Python will reply:</p>

<pre class="programlisting">
      True</pre>

<p class="blockquote">Silly me didnâ€™t see it: thatâ€™s what sometimes happens when you think about code without a compiler on hand to actually try it. However, the rest of what I said still stands, including the part about doing it with multiple loops being much clearer. If I can misunderstand the code in this way after more than 20 years of programming, then your colleagues might misunderstand it as well. The only disadvantage of having multiple loops that I can see is that more CPU registers would be required, but thatâ€™s only an issue nowadays if youâ€™re programming a microcontroller. And if thatâ€™s what youâ€™re doing, taking modulus 13 on every step might turn out to cost more CPU resources than the nested loops would anyway.</p>

<h2>Code Critique 91</h2>

<p>(Submissions to scc@accu.org by February 1st)</p>

<p class="blockquote">Iâ€™m trying to migrate my skill set from C to C++ so thought Iâ€™d get started with a simple program to fill in a set of strings and print them. But Iâ€™m getting a compilation problem on the call to <code>std::copy</code> that makes no sense to me, although I thought Iâ€™d copied it from some working code on the Internet. Can you help me get it to compile?</p>

<p>Can you help this programmer to get past this presenting problem and help them to identify any other issues with their code? The code is in Listing 2.</p>

<table class="sidebartable">
	<tr>
		<td>
			<pre class="programlisting">
#include &lt;iostream&gt;
#include &lt;iterator&gt;
#include &lt;set&gt;
// compare *contents* not raw pointers
bool string_less(char const *, char const *);
template &lt;class T, class U&gt;
void test(std::set&lt;T, U&gt; s, T p)
{
  if (s.insert(p).second)
    std::cout &lt;&lt; &quot;Added &quot; &lt;&lt; p &lt;&lt; std::endl;
  else
    std::cout &lt;&lt; p &lt;&lt; &quot; already present&quot;;
}

int main()
{
  std::set&lt;char const *,
    decltype(&amp;string_less)&gt; s(string_less);
  test(s, &quot;A&quot;);
  test(s, &quot;B&quot;);
  test(s, &quot;AB&quot;);
  std::copy(s.begin, s.end,
    std::ostream_iterator&lt;
      char const *&gt;(std::cout , &quot; &quot;));
  return 0;
}
bool string_less(const char *s, const char *t)
{
  while (*s == *t)
  {
    s++;
    t++;
  }
  return(*s &lt; *t);
}
			</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 (http://www.accu.org/journals/). 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>
