<?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>Involution &#187; C++</title>
	<atom:link href="http://involution.com/category/c/feed/" rel="self" type="application/rss+xml" />
	<link>http://involution.com</link>
	<description>Tony Perrie's Weblog</description>
	<lastBuildDate>Sat, 24 Jul 2010 06:54:04 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Primzahlen</title>
		<link>http://involution.com/2006/07/25/primzahlen/</link>
		<comments>http://involution.com/2006/07/25/primzahlen/#comments</comments>
		<pubDate>Tue, 25 Jul 2006 17:06:04 +0000</pubDate>
		<dc:creator>Tony Perrie</dc:creator>
				<category><![CDATA[C++]]></category>

		<guid isPermaLink="false">http://involution.com/2006/07/25/primzahlen/</guid>
		<description><![CDATA[The magnanimous Eric Holbrook unwaveringly opined that it is possible to generate the prime numbers using g++ error messages. template &#60;int i&#62; struct D { D(void*); operator int(); }; template &#60;int p, int i&#62; struct is_prime { enum { prim = (p==2) &#124;&#124; (p%i) &#38;&#38; is_prime&#60;(i&#62;2?p:0), i-1&#62; :: prim }; }; template &#60;int i&#62; struct [...]]]></description>
			<content:encoded><![CDATA[<p>The magnanimous Eric Holbrook <a href="http://www.erwin-unruh.de/primorig.html">unwaveringly opined</a> that it is possible to generate the prime numbers using g++ error messages.  </p>
<p>
<pre><font color="#000080"><b>template</b></font> &lt;<font color="#000080"><b>int</b></font> i&gt; <font color="#000080"><b>struct</b></font> D { D(<font color="#000080"><b>void</b></font>*); <font color="#5050ff">operator</font> <font color="#000080"><b>int</b></font>(); };

<font color="#000080"><b>template</b></font> &lt;<font color="#000080"><b>int</b></font> p, <font color="#000080"><b>int</b></font> i&gt; <font color="#000080"><b>struct</b></font> is_prime {
 <font color="#000080"><b>enum</b></font> { prim = (p==<font color="#a0a0ff"><b>2</b></font>) || (p%i) &amp;&amp; is_prime&lt;(i&gt;<font color="#a0a0ff"><b>2</b></font>?p:<font color="#a0a0ff"><b>0</b></font>), i-<font color="#a0a0ff"><b>1</b></font>&gt; :: prim };
};

<font color="#000080"><b>template</b></font> &lt;<font color="#000080"><b>int</b></font> i&gt; <font color="#000080"><b>struct</b></font> Prime_print {
 Prime_print&lt;i-<font color="#a0a0ff"><b>1</b></font>&gt; a;
 <font color="#000080"><b>enum</b></font> { prim = is_prime&lt;i, i-<font color="#a0a0ff"><b>1</b></font>&gt;::prim };
 <font color="#000080"><b>void</b></font> f() { D&lt;i&gt; d = prim ? <font color="#a0a0ff"><b>1</b></font> : <font color="#a0a0ff"><b>0</b></font>; a.f();}
};

<font color="#000080"><b>template</b></font>&lt;&gt; <font color="#000080"><b>struct</b></font> is_prime&lt;<font color="#a0a0ff"><b>0</b></font>,<font color="#a0a0ff"><b>0</b></font>&gt; { <font color="#000080"><b>enum</b></font> {prim=<font color="#a0a0ff"><b>1</b></font>}; };
<font color="#000080"><b>template</b></font>&lt;&gt; <font color="#000080"><b>struct</b></font> is_prime&lt;<font color="#a0a0ff"><b>0</b></font>,<font color="#a0a0ff"><b>1</b></font>&gt; { <font color="#000080"><b>enum</b></font> {prim=<font color="#a0a0ff"><b>1</b></font>}; };

<font color="#000080"><b>template</b></font>&lt;&gt; <font color="#000080"><b>struct</b></font> Prime_print&lt;<font color="#a0a0ff"><b>1</b></font>&gt; {
 <font color="#000080"><b>enum</b></font> {prim=<font color="#a0a0ff"><b>0</b></font>};
 <font color="#000080"><b>void</b></font> f() { D&lt;<font color="#a0a0ff"><b>1</b></font>&gt; d = prim ? <font color="#a0a0ff"><b>1</b></font> : <font color="#a0a0ff"><b>0</b></font>; };
};

<font color="#a0a0ff"><b>#ifndef LAST</b></font>
<font color="#a0a0ff"><b>#define LAST </b></font><font color="#a0a0ff"><b>18</b></font>
<font color="#a0a0ff"><b>#endif</b></font>

main() {
 Prime_print&lt;LAST&gt; a;
 a.f();
}
</pre>
</p>
<p>Save this off as dedekind.C and then abuse gcc with the nefarious recipe.</p>
<pre><code>% g++ -DLAST=30 dedekind.C 2>&#038;1 | grep &quot;error:  &quot;
error:   initializing argument 1 of `D&lt;i&gt;::D(void*) [with int i = 29]'
error:   initializing argument 1 of `D&lt;i&gt;::D(void*) [with int i = 23]'
error:   initializing argument 1 of `D&lt;i&gt;::D(void*) [with int i = 19]'
error:   initializing argument 1 of `D&lt;i&gt;::D(void*) [with int i = 17]'
error:   initializing argument 1 of `D&lt;i&gt;::D(void*) [with int i = 13]'
error:   initializing argument 1 of `D&lt;i&gt;::D(void*) [with int i = 11]'
error:   initializing argument 1 of `D&lt;i&gt;::D(void*) [with int i = 7]'
error:   initializing argument 1 of `D&lt;i&gt;::D(void*) [with int i = 5]'
error:   initializing argument 1 of `D&lt;i&gt;::D(void*) [with int i = 3]'
error:   initializing argument 1 of `D&lt;i&gt;::D(void*) [with int i = 2]'
</code></pre>
<p>Bumper has proved this inadvertent programming paradigm to be Turing-complete.  As a result, I&#8217;m diligently coding a new interpreted web frame work called &#8220;Gronky!&#8221;.  The output is generated exclusively with gcc error messages which are then consumed by Zeus just as a munted man consumes libations.  Expect a feature-complete alpha upon the return of Hale-Bopp.</p>
]]></content:encoded>
			<wfw:commentRss>http://involution.com/2006/07/25/primzahlen/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>RSS Parser in 10 lines of Ruby or in 153 lines of C++</title>
		<link>http://involution.com/2006/03/20/rss-parser-in-10-lines-of-ruby-or-in-153-lines-of-c/</link>
		<comments>http://involution.com/2006/03/20/rss-parser-in-10-lines-of-ruby-or-in-153-lines-of-c/#comments</comments>
		<pubDate>Mon, 20 Mar 2006 23:20:11 +0000</pubDate>
		<dc:creator>Tony Perrie</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://involution.com/2006/03/20/rss-parser-in-10-lines-of-ruby-or-in-153-lines-of-c/</guid>
		<description><![CDATA[I know there&#8217;s like 10 libraries to do this already, but they all seemed a bit heavy to me. I just wanted to grab the items from an RSS feed. Plain and simple. What&#8217;s amazing to me is that it could be done in 10 lines of Ruby. This parser reads an RSS feed, and [...]]]></description>
			<content:encoded><![CDATA[<p>I know there&#8217;s like 10 libraries to do this already, but they all seemed a bit heavy to me.  I just wanted to grab the items from an RSS feed.  Plain and simple.  What&#8217;s amazing to me is that it could be done in 10 lines of Ruby.  This parser reads an RSS feed, and stores the descriptions, items, and links into a hash of arrays.</p>
<pre><code>
#!/usr/bin/env ruby
require 'http-access2'

h = HTTPAccess2::Client.new()
element = Hash.new {|h,k| h[k] = []}

while urlstr = ARGV.shift
  response = h.get(urlstr) { |data|
    data.gsub(/&lt;(description|title|link)&gt;(.*?)&lt;\/(description|title|link)&gt;/m) {
      element[$1].push($2.gsub(/\s\s+/m,' '))
    }
  }
end

site_description = element['description'].shift
site_title = element['title'].shift
</code></pre>
<p>Stupidly, I wrote the same code in C++ first because I thought it would run faster.  After starting down that path, I found myself wanting to use ActiveRecord.  So, I ported over to Ruby.  </p>
<p>The C++ version is <a href="http://involution.com/feed_parser.C.txt">here</a> if you really want to see it.  It&#8217;s 121 lines of C++ with a 32 line h-file.   Truth be told, it actually took me less time to code the C++ because I made a couple of <a href="http://groups.google.com/group/comp.lang.ruby/browse_thread/thread/04262b5c4efeb290/89ff16635ba12344#89ff16635ba12344">mistakes</a> in my Ruby version at first.  All said and done, the Ruby version is a helluva lot easier to maintain than the C++ which I think is why I spent the time to do it in the first place.  </p>
]]></content:encoded>
			<wfw:commentRss>http://involution.com/2006/03/20/rss-parser-in-10-lines-of-ruby-or-in-153-lines-of-c/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>
