<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>ChalamiuS&#039; Blog &#187; Uncategorized</title>
	<atom:link href="http://blog.chalamius.se/category/uncategorized/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.chalamius.se</link>
	<description>Yet another random blog on the internet</description>
	<lastBuildDate>Fri, 30 Sep 2011 01:46:20 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>C#: Anonymous Methods</title>
		<link>http://blog.chalamius.se/2009/06/c-anonymous-methods</link>
		<comments>http://blog.chalamius.se/2009/06/c-anonymous-methods#comments</comments>
		<pubDate>Tue, 02 Jun 2009 15:54:39 +0000</pubDate>
		<dc:creator>jisakujien</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.chalamius.se/?p=146</guid>
		<description><![CDATA[To continue ChalamiuS&#8217; theme of C# goodness, let&#8217;s explore a feature of C# introduced in version 2 of the CLS: the anonymous method. Along the way we&#8217;ll also encounter Generics and Object Initializers, but they are not the focus of &#8230; <a href="http://blog.chalamius.se/2009/06/c-anonymous-methods">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>To continue ChalamiuS&#8217; theme of C# goodness, let&#8217;s explore a feature of C# introduced in version 2 of the <a href="http://msdn.microsoft.com/en-us/library/12a7a7h3.aspx">CLS</a>: the <a href="http://msdn.microsoft.com/en-us/library/bb308966.aspx#csharp3.0overview_topic8">anonymous method</a>.  Along the way we&#8217;ll also encounter <a href="http://msdn.microsoft.com/en-us/library/512aeb7t(VS.100).aspx">Generics</a> and <a href="http://msdn.microsoft.com/en-us/library/bb308966.aspx#csharp3.0overview_topic13">Object Initializers</a>, but they are not the focus of this post.<br />
<span id="more-146"></span><br />
Anonymous methods and other features of C# 2.0 and 3.0 incorporate paradigms from <a href="http://en.wikipedia.org/wiki/Functional_programming">functional programming</a> and other (relatively) exotic notions.  The full implications of this are and the theory behind it are only minimally covered in this post.  It should also be noted that in C# 3.0, <a href="http://geekswithblogs.net/michelotti/archive/2007/08/15/114702.aspx">lambda expressions were introduced</a>, which <a href="http://blogs.msdn.com/ericlippert/archive/2007/01/10/lambda-expressions-vs-anonymous-methods-part-one.aspx">work similarly to anonymous methods and look a whole lot cooler</a>.</p>
<h3>What is an anonymous method?</h3>
<p>To answer this question, let&#8217;s first define what a named (eg, not anonymous) method is, using Object.ToString() as an example:</p>
<ul>
<li>A method name.</li>
<li>A return type.  Object.ToString, unsurprisingly, returns a string.  Note that void is a type.</li>
<li>A parameter list.  Object.ToString does not take any parameters.</li>
<li>A method body.  The default Object.ToString implementation returns the type name.</li>
</ul>
<p>Without all of these elements, we cannot have a method.  Let&#8217;s similarly analyze the makeup of an anonymous method:</p>
<ul>
<li>A return type.</li>
<li>A parameter list.</li>
<li>A method body.</li>
</ul>
<p>The major difference is, of course, the lack of a method name.  Another significant difference not apparent in our comparison is that the return type of parameter list of an anonymous method is declared in a delegate.  Any number of anonymous methods may conform to the same delegate.  This is a very basic look at anonymous methods.  I suggest you read more by <a href="http://msdn.microsoft.com/en-us/magazine/cc163682.aspx">people who actually know what they&#8217;re talking about</a>.</p>
<h3>Why use an anonymous method?</h3>
<p>There are any number of reasons to use an anonymous method instead of a regular named method, but my favorite is to help organize small blocks of specialized code.  Instead of declaring a very short method and then calling it from only one place in your code, you can put the anonymous method code right inside the method that needs it.  Anonymous methods are also a great way of sharing information between blocks of code without having use classes or complex method declarations.</p>
<p>We must be careful to not declare anonymous methods when the code they contain may be used in more than once place.  While this can be fixed by refactoring the anonymous method into a named method, it&#8217;s best to avoid this pitfall in the first place.</p>
<h3>Wait, what?</h3>
<p>Instead of drowning in <a href="http://en.wikipedia.org/wiki/Typed_lambda_calculus">theory and technical arcana</a>, let&#8217;s see a (highly contrived) example.  In this example, we create a list of cars and print out any car meeting a certain criteria.  The code declaring the Car class and filling the list of cars is at the end of this post.</p>
<h4>Example without anonymous method</h4>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">void</span> Main<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> args<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    List<span style="color: #008000;">&lt;</span>Car<span style="color: #008000;">&gt;</span> cars <span style="color: #008000;">=</span> CreateCars<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span>Car car <span style="color: #0600FF; font-weight: bold;">in</span> cars<span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        <span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>DoesCarMeetCriteria<span style="color: #008000;">&#40;</span>car<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
            Console<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span>car<span style="color: #008000;">.</span><span style="color: #0000FF;">ToString</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">bool</span> DoesCarMeetCriteria<span style="color: #008000;">&#40;</span>Car car<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    <span style="color: #0600FF; font-weight: bold;">return</span>
        car<span style="color: #008000;">.</span><span style="color: #0000FF;">Manufacturer</span> <span style="color: #008000;">==</span> <span style="color: #666666;">&quot;Toyota&quot;</span> <span style="color: #008000;">||</span>
        car<span style="color: #008000;">.</span><span style="color: #0000FF;">Manufacturer</span> <span style="color: #008000;">==</span> <span style="color: #666666;">&quot;Nissan&quot;</span> <span style="color: #008000;">&amp;&amp;</span>
        car<span style="color: #008000;">.</span><span style="color: #0000FF;">Turbocharged</span> <span style="color: #008000;">==</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<h4>Example with anonymous method</h4>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">void</span> Main<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> args<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    <span style="color: #008080; font-style: italic;">// Create a list of cars meeting criteria by calling the FindAll()</span>
    <span style="color: #008080; font-style: italic;">// method of the List returned by CreateCars().</span>
    List<span style="color: #008000;">&lt;</span>Car<span style="color: #008000;">&gt;</span> cars <span style="color: #008000;">=</span> CreateCars<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">FindAll</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">delegate</span><span style="color: #008000;">&#40;</span>Car candidate<span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        <span style="color: #008080; font-style: italic;">// Return whether the car matches our criteria.  FindAll()</span>
        <span style="color: #008080; font-style: italic;">// expects our anonymous method to return a boolean, and</span>
        <span style="color: #008080; font-style: italic;">// the compiler makes sure this is the case.</span>
        <span style="color: #0600FF; font-weight: bold;">return</span>
            candidate<span style="color: #008000;">.</span><span style="color: #0000FF;">Manufacturer</span> <span style="color: #008000;">==</span> <span style="color: #666666;">&quot;Toyota&quot;</span> <span style="color: #008000;">||</span>
            candidate<span style="color: #008000;">.</span><span style="color: #0000FF;">Manufacturer</span> <span style="color: #008000;">==</span> <span style="color: #666666;">&quot;Nissan&quot;</span> <span style="color: #008000;">&amp;&amp;</span>
            candidate<span style="color: #008000;">.</span><span style="color: #0000FF;">Turbocharged</span> <span style="color: #008000;">==</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">foreach</span><span style="color: #008000;">&#40;</span>Car car <span style="color: #0600FF; font-weight: bold;">in</span> cars<span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        Console<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span>car<span style="color: #008000;">.</span><span style="color: #0000FF;">ToString</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<h3>Conclusion</h3>
<p>Which do you prefer?  I like the anonymous method; while the syntax may seem strange it becomes quite natural after using it a few times.  Sadly this example is somewhat weak; using an anonymous method doesn&#8217;t really gain us anything.  However, showing the true power would touch on language design paradigms and the like, which I am avoiding in this post.</p>
<p>Here&#8217;s the rest of the code required to compile and run the example:</p>
<h4>The Car class</h4>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #6666cc; font-weight: bold;">class</span> Car
<span style="color: #008000;">&#123;</span>
    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">string</span> Manufacturer, Model<span style="color: #008000;">;</span>
    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">bool</span> Turbocharged<span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">override</span> <span style="color: #6666cc; font-weight: bold;">string</span> ToString<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        <span style="color: #0600FF; font-weight: bold;">return</span> <span style="color: #6666cc; font-weight: bold;">String</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Format</span><span style="color: #008000;">&#40;</span>
            <span style="color: #666666;">&quot;{0} {1} ({2}Turbo)&quot;</span>, 
            Manufacturer, 
            Model, 
            Turbocharged <span style="color: #008000;">?</span> <span style="color: #666666;">&quot;&quot;</span> <span style="color: #008000;">:</span> <span style="color: #666666;">&quot;Non-&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<h4>Creating the Car list</h4>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">static</span> List<span style="color: #008000;">&lt;</span>Car<span style="color: #008000;">&gt;</span> CreateCars<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    List<span style="color: #008000;">&lt;</span>Car<span style="color: #008000;">&gt;</span> cars <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> List<span style="color: #008000;">&lt;</span>Car<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    cars<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">new</span> Car<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        Manufacturer <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;Toyota&quot;</span>,
        Model <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;AE-86 Trueno GT-APEX&quot;</span>,
        Turbocharged <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">false</span>
    <span style="color: #008000;">&#125;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    cars<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">new</span> Car<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        Manufacturer <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;Toyota&quot;</span>,
        Model <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;MR2&quot;</span>,
        Turbocharged <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">false</span>
    <span style="color: #008000;">&#125;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    cars<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">new</span> Car<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        Manufacturer <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;Nissan&quot;</span>,
        Model <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;180SX&quot;</span>,
        Turbocharged <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">false</span>
    <span style="color: #008000;">&#125;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// Some models are turbo-charged.</span>
&nbsp;
    cars<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">new</span> Car<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
    <span style="color: #008000;">&#123;</span>
        Manufacturer <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;Nissan&quot;</span>,
        Model <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;Sileighty&quot;</span>,
        Turbocharged <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">true</span>
    <span style="color: #008000;">&#125;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #0600FF; font-weight: bold;">return</span> cars<span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.chalamius.se/2009/06/c-anonymous-methods/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Exploding Rats and the C++ Standard Vector</title>
		<link>http://blog.chalamius.se/2009/02/exploding-rats-and-the-c-standard-vector</link>
		<comments>http://blog.chalamius.se/2009/02/exploding-rats-and-the-c-standard-vector#comments</comments>
		<pubDate>Sat, 21 Feb 2009 17:12:54 +0000</pubDate>
		<dc:creator>jisakujien</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.chalamius.se/?p=133</guid>
		<description><![CDATA[Rats are small, cheap, easy to maintain and transport. As many are aware, land mines present a significant danger in many war-ravaged countries around the world. Numerous innovative techniques have been developed to clear mine fields, rendering the land once &#8230; <a href="http://blog.chalamius.se/2009/02/exploding-rats-and-the-c-standard-vector">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<blockquote>
<h3>Rats are small, cheap, easy to maintain and transport.</h3>
</blockquote>
<p>
<a href="http://en.wikipedia.org/wiki/HeroRAT"><img class="size-full wp-image-21 alignright" title="A Nose for Danger" src="http://blog.chalamius.se/wp-content/uploads/2009/02/herorat.jpg" alt="Mine-sniffing rats" width="310" height="163" /></a>As many are aware, land mines present a significant danger in many war-ravaged countries around the world.  Numerous innovative techniques have been developed to <a title="Demining - Wikipedia, the free encyclopedia" href="http://en.wikipedia.org/wiki/Demining" target="_blank">clear mine fields</a>, rendering the land once again usable and preventing tragic injuries and deaths.  A Belgian non-profit organization, <a title="A P O P O" href="http://www.apopo.org" target="_blank">APOPO</a>, began a unique program to develop a new method &#8212; using Giant Pouched Rats (<a title="Giant pouched rat - Wikipedia, the free encyclopedia" href="http://en.wikipedia.org/wiki/Giant_pouched_rat" target="_blank"><em><span class="family">Nesomyidae </span></em></a><span class="subfamily"><a title="Giant pouched rat - Wikipedia, the free encyclopedia" href="http://en.wikipedia.org/wiki/Giant_pouched_rat" target="_blank"><em><span class="mw-redirect">Cricetomyinae</span></em></a>) to detect mines &#8212; dubbed <a title="Home | Herorat.org" href="http://www.herorat.org/" target="_blank">HeroRATS</a> in 2004, and has now deployed the intrepid rodents in Mozambique.<br />
</span><br />
The rats are too light to set off mines, so disappointingly they are not destroyed in the process (sorry, I lied).  Instead, the rats are attached to guide lines and trained to scratch at the ground when they sniff out explosives.  The mine is then flagged for removal using more appropriate tools.</p>
<blockquote>
<h3><span dir="ltr">A zebra is a horse designed by a committee.</span></h3>
</blockquote>
<p><span dir="ltr">I&#8217;ll be the first to admit that I am not an expert with the C++ language.  In fact, I can use all the practice I can get.  I&#8217;ve been using the Standard Template Library on and off for almost 3 years now, but know embarrassingly little about it&#8217;s full capabilities.  In that vein, I will (hopefully) be posting a series of snippets and short programs about the STL.  I plan to start simple, and work my way up.  Without further ado, the very basics of the STL vector and it&#8217;s iterator.</span></p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #339900;">#include &lt;iostream&gt;</span>
<span style="color: #339900;">#include &lt;vector&gt;</span>
<span style="color: #339900;">#include &lt;string&gt;</span>
&nbsp;
<span style="color: #0000ff;">int</span> main<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
   <span style="color: #666666;">// Define a vector, which is an array-like container of items.</span>
   <span style="color: #666666;">// Unlike std::set, vectors can contain the same element any</span>
   <span style="color: #666666;">// number of times.</span>
   std<span style="color: #008080;">::</span><span style="color: #007788;">vector</span><span style="color: #000080;">&lt;</span>std<span style="color: #008080;">::</span><span style="color: #007788;">string</span><span style="color: #000080;">&gt;</span> strings<span style="color: #008080;">;</span>
&nbsp;
   <span style="color: #666666;">// Add some strings to the vector.</span>
   strings.<span style="color: #007788;">push_back</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;foo&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
   strings.<span style="color: #007788;">push_back</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;bar&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
   <span style="color: #666666;">// Insert a string at a specific point in the vector.  Here &quot;baz&quot;</span>
   <span style="color: #666666;">// is appended to the vector.</span>
   strings.<span style="color: #007788;">insert</span><span style="color: #008000;">&#40;</span>strings.<span style="color: #007788;">end</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>, <span style="color: #FF0000;">&quot;baz&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
   <span style="color: #666666;">// STL containers (such as vector, set, hash, etc) can be iterated</span>
   <span style="color: #666666;">// in a manner almost like foreach some in other languages.  First</span>
   <span style="color: #666666;">// an iterator must be declared.</span>
   std<span style="color: #008080;">::</span><span style="color: #007788;">vector</span><span style="color: #000080;">&lt;</span>std<span style="color: #008080;">::</span><span style="color: #007788;">string</span><span style="color: #000080;">&gt;</span><span style="color: #008080;">::</span><span style="color: #007788;">iterator</span> iter <span style="color: #000080;">=</span> strings.<span style="color: #007788;">begin</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
   <span style="color: #666666;">// The iterator can be used to access each element of the vector.</span>
   <span style="color: #0000ff;">for</span><span style="color: #008000;">&#40;</span><span style="color: #008080;">;</span>
       iter <span style="color: #000040;">!</span><span style="color: #000080;">=</span> strings.<span style="color: #007788;">end</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span> <span style="color: #ff0000; font-style: italic;">/* Don't iterate past the end. */</span>
       iter<span style="color: #000040;">++</span><span style="color: #008000;">&#41;</span> <span style="color: #ff0000; font-style: italic;">/* iters overload the increment (++) operator. */</span>
   <span style="color: #008000;">&#123;</span>
      <span style="color: #666666;">// To retrieve the value at the index represented by the</span>
      <span style="color: #666666;">// iterator, some more STL syntactical sugar makes it a</span>
      <span style="color: #666666;">// simply matter of using the dereference (*) operator.</span>
      std<span style="color: #008080;">::</span><span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #000040;">*</span>iter<span style="color: #008080;">;</span>
      std<span style="color: #008080;">::</span><span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> std<span style="color: #008080;">::</span><span style="color: #007788;">endl</span><span style="color: #008080;">;</span>
   <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<pre>$ g++ vector.cpp -o vector &amp;&amp; ./vector
foo
bar
baz
$</pre>
<p>Let me know if I&#8217;ve made obvious mistakes, which I tend to do frequently!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.chalamius.se/2009/02/exploding-rats-and-the-c-standard-vector/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

