<?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>fhtagn!</title>
	<atom:link href="http://fhtagn.unwesen.de/feed/" rel="self" type="application/rss+xml" />
	<link>http://fhtagn.unwesen.de</link>
	<description></description>
	<lastBuildDate>Wed, 02 Feb 2011 18:14:05 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.5</generator>
		<item>
		<title>The Adventures of Lil Cthulhu</title>
		<link>http://fhtagn.unwesen.de/2009/11/16/the_adventures_of_lil_cthulhu/</link>
		<comments>http://fhtagn.unwesen.de/2009/11/16/the_adventures_of_lil_cthulhu/#comments</comments>
		<pubDate>Mon, 16 Nov 2009 19:09:13 +0000</pubDate>
		<dc:creator>unwesen</dc:creator>
				<category><![CDATA[Humour]]></category>

		<guid isPermaLink="false">http://fhtagn.unwesen.de/?p=23</guid>
		<description><![CDATA[I haven&#8217;t been able to work on Fhtagn! a lot recently&#8230; paid work keeps interrupting1. In the meantime, faithful cultists might find that the waiting is a little less dreadful they watch the video below: Incidentally, if you want to hire me, head over to my business website with my portfolio and contact information.]]></description>
			<content:encoded><![CDATA[<p>I haven&#8217;t been able to work on Fhtagn! a lot recently&#8230; paid work keeps interrupting<sup><a href="http://fhtagn.unwesen.de/2009/11/16/the_adventures_of_lil_cthulhu/#footnote_0_23" id="identifier_0_23" class="footnote-link footnote-identifier-link" title="Incidentally, if you want to hire me, head over to my business website with my portfolio and contact information.">1</a></sup>. In the meantime, faithful cultists might find that the waiting is a little less dreadful they watch the video below:</p>
<p><object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/FOHJUrcVdJk&#038;hl=en_GB&#038;fs=1&#038;"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/FOHJUrcVdJk&#038;hl=en_GB&#038;fs=1&#038;" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object></p>
<ol class="footnotes"><li id="footnote_0_23" class="footnote">Incidentally, if you want to hire me, head over to <a href="http://www.finkhaeuser.de/">my business website with my portfolio and contact information</a>.</li></ol>]]></content:encoded>
			<wfw:commentRss>http://fhtagn.unwesen.de/2009/11/16/the_adventures_of_lil_cthulhu/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>0.3.0 aka Comatose Cthulhu is released!</title>
		<link>http://fhtagn.unwesen.de/2009/06/08/030_aka_comatose_cthulhu_is_released/</link>
		<comments>http://fhtagn.unwesen.de/2009/06/08/030_aka_comatose_cthulhu_is_released/#comments</comments>
		<pubDate>Mon, 08 Jun 2009 22:50:55 +0000</pubDate>
		<dc:creator>unwesen</dc:creator>
				<category><![CDATA[releases]]></category>

		<guid isPermaLink="false">http://fhtagn.unwesen.de/?p=22</guid>
		<description><![CDATA[You might be wondering what this release adds so shortly after 0.2.0 was released. The answer, depending on your perspective, is either everything or nothing. There are no code changes between the two releases. The only thing that changed is that Fhtagn! moved away from the Boost Software License Version 1.0, and is now licensed [...]]]></description>
			<content:encoded><![CDATA[<p>You might be wondering what this release adds so shortly after <a href="/articles/020_aka_black_brotherhood_is_released">0.2.0 was released</a>. The answer, depending on your perspective, is either everything or nothing.</p>
<p>There are no code changes between the two releases. The only thing that changed is that Fhtagn! moved away from the <a href="http://www.boost.org/LICENSE_1_0.txt">Boost Software License Version 1.0</a>, and is now licensed under the terms of the <a href="http://www.gnu.org/licenses/gpl-3.0.txt">GNU General Public License Version 3</a><sup><a href="http://fhtagn.unwesen.de/2009/06/08/030_aka_comatose_cthulhu_is_released/#footnote_0_22" id="identifier_0_22" class="footnote-link footnote-identifier-link" title="These changes to not pertain to the scons_util subdirectory of the project, as that contains build files used in other projects of mine.">1</a></sup>.</p>
<p>If you are a non-commercial user, e.g. if you use this software for personal, educational or other non-profit use, all that changes for you is that you now must publish the source code to any changes you make to this software, provided you distribute these changes in some way.</p>
<p><span id="more-22"></span></p>
<p>Commercial users will need to acquire a commercial license if they wish to use 0.3.0 or later. But don&#8217;t worry, 0.2.0 will not change it&#8217;s license retroactively, and nothing forces you to upgrade. On the other hand, the 0.2.0 branch won&#8217;t be developed further (a few bugfixes aside as they come in).</p>
<p>This license change has been long planned. I&#8217;ve long been profiting by the great work the <a href="http://www.fsf.org/">Free Software Foundation</a> has been doing. Free software has made my life better. I figured it was high time to give back to the community in earnest.</p>
<p>At this point I&#8217;d like to draw your attention to another change in the sources that you might overlook amidst all the changes to license text: the copyright to Fhtagn! now lies with me<sup><a href="http://fhtagn.unwesen.de/2009/06/08/030_aka_comatose_cthulhu_is_released/#footnote_1_22" id="identifier_1_22" class="footnote-link footnote-identifier-link" title="Jens Finkhaeuser">2</a></sup> rather than &#8220;the authors&#8221;.</p>
<p>The simple reason for this is that it&#8217;s more practical: a single person as the copyright holder means much less hassle when license issues need to be dealt with<sup><a href="http://fhtagn.unwesen.de/2009/06/08/030_aka_comatose_cthulhu_is_released/#footnote_2_22" id="identifier_2_22" class="footnote-link footnote-identifier-link" title="Note that for the same reason, future contributions will only be accepted if the contributors also grant copyright to me.">3</a></sup>. We briefly discussed the alternative of creating some legal non-profit entity and assigning copyright to that, but the other two contributors decided to grant me copyright instead.</p>
<p>And I&#8217;d like to take this opportunity to thank them for their invaluable help: the commit history in no way reflects how much support they&#8217;ve been during the lifetime of this project.</p>
<p>Without Henning&#8217;s contributions and encouragement, this project would not exist. And without Tony&#8217;s use of some of Fhtagn!&#8217;s features, I probably would have lost interest in the project a long time ago.</p>
<p>Thank you! Comatose Cthulhu is dedicated to you!</p>
<ol class="footnotes"><li id="footnote_0_22" class="footnote">These changes to not pertain to the <code>scons_util</code> subdirectory of the project, as that contains build files used in other projects of mine.</li><li id="footnote_1_22" class="footnote">Jens Finkhaeuser</li><li id="footnote_2_22" class="footnote">Note that for the same reason, future contributions will only be accepted if the contributors also grant copyright to me.</li></ol>]]></content:encoded>
			<wfw:commentRss>http://fhtagn.unwesen.de/2009/06/08/030_aka_comatose_cthulhu_is_released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>0.2.0 aka Black Brotherhood is released!</title>
		<link>http://fhtagn.unwesen.de/2009/06/08/020_aka_black_brotherhood_is_released/</link>
		<comments>http://fhtagn.unwesen.de/2009/06/08/020_aka_black_brotherhood_is_released/#comments</comments>
		<pubDate>Mon, 08 Jun 2009 21:38:50 +0000</pubDate>
		<dc:creator>unwesen</dc:creator>
				<category><![CDATA[releases]]></category>

		<guid isPermaLink="false">http://fhtagn.unwesen.de/?p=21</guid>
		<description><![CDATA[And it&#8217;s done! I&#8217;ve just tagged 0.2.0 aka Black Brotherhood, the first release of Fhtagn! that can reasonably be called a release. People following this project will note that a number of issues that used to be associated with 0.2.0 got pushed to 0.3.0 in recent weeks. I just felt that I&#8217;d rather postpone individual [...]]]></description>
			<content:encoded><![CDATA[<p>And it&#8217;s done! I&#8217;ve just tagged <a href="https://svn.unwesen.net/trac/fhtagn/browser/releases/0.2.0">0.2.0</a> aka <a href="http://en.wikipedia.org/wiki/Church_of_Starry_Wisdom#Black_Brotherhood">Black Brotherhood</a>, the first release of Fhtagn! that can reasonably be called a release.</p>
<p>People following this project will note that a number of issues that used to be associated with 0.2.0 got pushed to 0.3.0 in recent weeks. I just felt that I&#8217;d rather postpone individual features than keep putting off a release.</p>
<p>Please note that <a href="/articles/fhtagn_on_windows">windows</a> is still not officially supported. One of the items on the TODO-list for the next release is to improve on that.</p>
<p>Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://fhtagn.unwesen.de/2009/06/08/020_aka_black_brotherhood_is_released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Into the Future!</title>
		<link>http://fhtagn.unwesen.de/2009/04/21/into_the_future/</link>
		<comments>http://fhtagn.unwesen.de/2009/04/21/into_the_future/#comments</comments>
		<pubDate>Tue, 21 Apr 2009 21:43:08 +0000</pubDate>
		<dc:creator>unwesen</dc:creator>
				<category><![CDATA[features]]></category>
		<category><![CDATA[boost]]></category>
		<category><![CDATA[c++0x]]></category>
		<category><![CDATA[continuation]]></category>
		<category><![CDATA[future]]></category>
		<category><![CDATA[threads]]></category>

		<guid isPermaLink="false">http://fhtagn.unwesen.de/?p=20</guid>
		<description><![CDATA[Triggered by the announcement that boost will soon include futures, I sat down to write a quick implementation myself. Yes, I know, it&#8217;s kind of stupid to do something that boost/c++0x will include very soon anyway. But given that futures are conceptually like a mixture of read-only properties mixed with a subset of the tasklet-functionality, [...]]]></description>
			<content:encoded><![CDATA[<p>Triggered by the <a href="http://comments.gmane.org/gmane.comp.lib.boost.announce/230">announcement that boost will soon include futures</a>, I sat down to write a quick implementation myself. Yes, I know, it&#8217;s kind of stupid to do something that boost/c++0x will include very soon anyway.</p>
<p>But given that futures are conceptually like a mixture of read-only <a href="https://svn.unwesen.net/trac/fhtagn/browser/trunk/fhtagn/property.h">properties</a> mixed with a subset of the <a href="https://svn.unwesen.net/trac/fhtagn/browser/trunk/fhtagn/threads/tasklet.h">tasklet</a>-functionality, it was just a no-brainer to write them.</p>
<p>So there you are.</p>
<p>Follow the jump for a quick example on how to use them.</p>
<p><span id="more-20"></span></p>
<p>It really couldn&#8217;t be simpler: a future is essentially a read-only object of a value type of your choosing, the value of which is calculated in a background thread. When trying to read the value, the code blocks until the background thread has finished:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
</pre></td><td class="code"><pre class="cxx" style="font-family:monospace;">using namespace fhtagn::threads;
&nbsp;
// You need some function to calculate the value with.
// You might want to look into boost::lambda if you want
// to define it inline.
int my_calculating_function();
&nbsp;
// A future representing an integer type is instanciated
// with the function that calculates is value. This spawns
//  the background thread immediately.
future&lt;int&gt; x(&amp;my_calculating_function);
&nbsp;
// When reading the value (i.e. using the future in an
// expression), the code blocks until the background
// thread is finished.
int y = 3.1415 * x;
&nbsp;
// However, once it's calculated, there's no need to run
//  the thread again, and things are much quicker.
int z = x;</pre></td></tr></table></div>

<p>Simple, isn&#8217;t it? There&#8217;s more to it, but not a lot&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://fhtagn.unwesen.de/2009/04/21/into_the_future/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fhtagn! on Windows</title>
		<link>http://fhtagn.unwesen.de/2009/04/19/fhtagn_on_windows/</link>
		<comments>http://fhtagn.unwesen.de/2009/04/19/fhtagn_on_windows/#comments</comments>
		<pubDate>Sun, 19 Apr 2009 20:01:18 +0000</pubDate>
		<dc:creator>unwesen</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[build]]></category>
		<category><![CDATA[scons]]></category>
		<category><![CDATA[win32]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://fhtagn.unwesen.de/?p=19</guid>
		<description><![CDATA[Over the weekend, I managed to improve the SCons build and fix two or three minor issues in the code, with the result that Fhtagn!&#8217;s testsuite now also compiles and passes on Windows. This does by no means imply that all the work for making sure Fhtagn! runs on windows is done, though. But it&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>Over the weekend, I managed to improve the <a href="http://www.scons.org/">SCons</a> build and fix two or three minor issues in the code, with the result that Fhtagn!&#8217;s testsuite now also compiles and passes on Windows.</p>
<p>This does by no means imply that all the work for making sure Fhtagn! runs on windows is done, though. But it&#8217;s a major milestone &#8212; and vindicates my assumption that the code is fairly portable!</p>
<p>Enjoy!</p>
<p>Finally, here&#8217;s a partial list of things left to do:</p>
<ul>
<li>The <a href="/articles/measuring_c_allocator_performance">allocspeed</a> test program doesn&#8217;t link yet.</li>
<li>There are hundreds of compiler warnings, some of which could probably be fixed.</li>
<li>You can&#8217;t build static and dynamic libs &#8212; either one at a time works, but not both.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://fhtagn.unwesen.de/2009/04/19/fhtagn_on_windows/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>#fhtagn at freenode.net</title>
		<link>http://fhtagn.unwesen.de/2009/03/31/fhtagn_at_freenodenet/</link>
		<comments>http://fhtagn.unwesen.de/2009/03/31/fhtagn_at_freenodenet/#comments</comments>
		<pubDate>Tue, 31 Mar 2009 14:55:21 +0000</pubDate>
		<dc:creator>unwesen</dc:creator>
				<category><![CDATA[site]]></category>
		<category><![CDATA[freenode]]></category>
		<category><![CDATA[irc]]></category>

		<guid isPermaLink="false">http://fhtagn.unwesen.de/?p=17</guid>
		<description><![CDATA[This is just a quick announcement that we&#8217;ve got a #fhtagn channel at freenode.net up and running now. I&#8217;ll probably be seen lurking there.]]></description>
			<content:encoded><![CDATA[<p>This is just a quick announcement that we&#8217;ve got a <a href="irc://irc.freenode.net/%23fhtagn">#fhtagn</a> channel at <a href="http://www.freenode.net/">freenode.net</a> up and running now. I&#8217;ll probably be seen lurking there.</p>
]]></content:encoded>
			<wfw:commentRss>http://fhtagn.unwesen.de/2009/03/31/fhtagn_at_freenodenet/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Measuring C++ Allocator Performance</title>
		<link>http://fhtagn.unwesen.de/2009/03/26/measuring_c_allocator_performance/</link>
		<comments>http://fhtagn.unwesen.de/2009/03/26/measuring_c_allocator_performance/#comments</comments>
		<pubDate>Thu, 26 Mar 2009 20:52:00 +0000</pubDate>
		<dc:creator>unwesen</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[features]]></category>
		<category><![CDATA[allocator]]></category>
		<category><![CDATA[c++]]></category>
		<category><![CDATA[container]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[speed]]></category>
		<category><![CDATA[stl]]></category>

		<guid isPermaLink="false">http://fhtagn.unwesen.de/?p=11</guid>
		<description><![CDATA[A while ago, I sat down to write a few allocators for C++ objects and/or STL containers. That is, inspired by an article on STL-compatible allocators, I sat down to write one such allocator, but made it possible to feed it memory from a variety of what I chose to call pools. One such pool [...]]]></description>
			<content:encoded><![CDATA[<p>A while ago, I sat down to write a few allocators for C++ objects and/or STL containers. That is, inspired by <a href="http://www.codeproject.com/KB/cpp/allocator.aspx">an article on STL-compatible allocators</a>, I sat down to write one such allocator, but made it possible to feed it memory from a variety of what I chose to call pools. One such pool I modelled after what I dimly recall having read in the code of <a href="http://www.python.org/">Python</a>&#8216;s allocator.</p>
<p>You can find all of that effort in the <a href="https://svn.unwesen.net/fhtagn/trunk/fhtagn/memory">memory</a> sub-directory in fhtagn!&#8217;s trunk &#8212; but more important than code, right now, is another question: why should I be interested?</p>
<p><span id="more-11"></span></p>
<p>Well, this Python inspired allocator is somewhat clever in that it tries to satisfy the most common allocation requests from pre-allocated pools. It internally manages pools for different object sizes, and considers objects in sizes of two to the power of N: 1, 2, 4, 8, &#8230;, 256. Each pool then is little more than an array of entries of this fixed size.</p>
<p>For any allocation request, the allocator will determine which of the 2^N sizes would be large enough to fit the object into, and will take memory from the pool that handles this size &#8212; except if the allocation size required is too large, in which case it&#8217;ll fall back on the heap.</p>
<p>This allocation scheme works very well for Python. In python, all objects (including integers) are allocated from this allocator individually, which means that this very fast allocation from pre-allocated pools improves performance drastically.</p>
<p>But how does this approach measure up in C++?</p>
<p>To find out, I wrote a little benchmark program for allocators. It tries to imitate very naive usage of STL containers, and therefore uses STL&#8217;s vector very simply: it&#8217;ll fill a vector with a random amount of entries, then drain a random amount of entries again (from anywhere within the vector, not just the beginning or end), and then repeat the process several times.</p>
<p>The reasoning behind this approach is to simulate a relatively healthy balance between user stupidity and vector&#8217;s own approach to allocating smartly: if vector is out of memory, it&#8217;ll usually allocate as much memory as it already uses currently &#8212; a simple but relatively efficient method for anticipating what the user might do next.</p>
<p>The interesting part about this is that it flies in the face of the size-based pool approach: vector, doubling it&#8217;s capacity with each time it runs out of memory, will pretty soon request memory far larger than the size-based pools provide for, thus triggering the fallback solution of allocating from the heap. Once the vector has grown to that stage, there should be no benefit between STL&#8217;s default allocator and the size-based pool approach.</p>
<p>In that sense, the tests try to account for the worst case the size-based pools can encounter &#8212; but as it&#8217;s often impossible to determine the size of a containers before filling it, this usage of vector is also moderately realistic. In balance, I think these tests should paint a pretty realistic picture of the performance of this size-based pool approach<sup><a href="http://fhtagn.unwesen.de/2009/03/26/measuring_c_allocator_performance/#footnote_0_11" id="identifier_0_11" class="footnote-link footnote-identifier-link" title="Note that the same usage of e.g. STL&amp;#8217;s lists or maps would favour the size-based pools approach more">1</a></sup>.</p>
<ol class="footnotes"><li id="footnote_0_11" class="footnote">Note that the same usage of e.g. STL&#8217;s lists or maps would favour the size-based pools approach more</li></ol>]]></content:encoded>
			<wfw:commentRss>http://fhtagn.unwesen.de/2009/03/26/measuring_c_allocator_performance/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Constrained vs. restricted value types</title>
		<link>http://fhtagn.unwesen.de/2008/11/19/constrained_vs_restricted_value_types/</link>
		<comments>http://fhtagn.unwesen.de/2008/11/19/constrained_vs_restricted_value_types/#comments</comments>
		<pubDate>Wed, 19 Nov 2008 12:15:57 +0000</pubDate>
		<dc:creator>unwesen</dc:creator>
				<category><![CDATA[features]]></category>

		<guid isPermaLink="false">http://fhtagn.unwesen.de/?p=9</guid>
		<description><![CDATA[I admit it, I&#8217;m lurking on the boost developer mailing list. Most of what&#8217;s sent there goes past me, I don&#8217;t really feel I have the time to read it all. And sometimes I even post drivel there, usually only to be reminded that I hadn&#8217;t paid attention to detail. Such is my lot. But [...]]]></description>
			<content:encoded><![CDATA[<p>I admit it, I&#8217;m lurking on the <a href="http://www.boost.org/community/groups.html">boost developer mailing list</a>. Most of what&#8217;s sent there goes past me, I don&#8217;t really feel I have the time to read it all. And sometimes I even post drivel there, usually only to be reminded that I hadn&#8217;t paid attention to detail. Such is my lot.</p>
<p>But there was a recent bit of activity on the mailing list that I wanted to share with you, because it was about a <a href="http://rk.go.pl/f/constrained_value.zip ">constrained value</a> library about to be submitted for review. In the boost world, new libraries are submitted for review, and the results of the review determine whether or not the library is included.</p>
<p>Highly fascinating stuff, if only because Fhtagn! has included <a href="https://svn.unwesen.net/fhtagn/trunk/fhtagn/restricted.h">pretty much the same functionality</a> for a while now.</p>
<p><span id="more-9"></span></p>
<p>So naturally I took a look at the submission, if only to determine whether or not it&#8217;s good enough to drop Fhtagn!&#8217;s restricted data types in favour of boost&#8217;s constrained values. Turns out that I won&#8217;t be doing that.</p>
<p>But first, let&#8217;s take a brief look at what this sort of code does. I&#8217;ll use Fhtagn!&#8217;s version, because, well, you&#8217;re here already. But note that I&#8217;ll use restricted/constrained and restriction/constraint interchangeably in the text below.</p>
<p>The idea is to place constraints on the values that a value type can take. Fhtagn!&#8217;s approach was originally inspired by the <a href="http://www.digitalmars.com/d/2.0/dbc.html">D language&#8217;s approach to design by contract</a>. D allows a function to define a set of constracts, such as the range of values a parameter may take, and throws an exception if that contract is broken.</p>
<p>By associating this sort of contract not with a function, but with a data type, you gain more flexibility, while retaining the ability to define function prototypes with a contract:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #666666;">// even_int_t is an int that can only ever contain even values.</span>
<span style="color: #0000ff;">typedef</span> fhtagn<span style="color: #008080;">::</span><span style="color: #007788;">restricted</span><span style="color: #000080;">&lt;</span><span style="color: #0000ff;">int</span>,
  fhtagn<span style="color: #008080;">::</span><span style="color: #007788;">restrictions</span><span style="color: #008080;">::</span><span style="color: #007788;">numeric</span><span style="color: #008080;">::</span><span style="color: #007788;">even</span><span style="color: #000080;">&lt;</span><span style="color: #0000ff;">int</span><span style="color: #000080;">&gt;</span>
<span style="color: #000080;">&gt;</span> even_int_t<span style="color: #008080;">;</span>
&nbsp;
<span style="color: #0000ff;">void</span> foo<span style="color: #008000;">&#40;</span>even_int_t <span style="color: #0000ff;">const</span> <span style="color: #000040;">&amp;</span> param<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span></pre></td></tr></table></div>

<p>The beauty of this is that the <code>even</code> constraint is evaluated before <code>foo()</code>&#8216;s function body is entered.</p>
<p>You&#8217;ll note that the restriction we&#8217;re using is a template argument to the restricted type. You can even chain restrictions, like this:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #666666;">// positive_even_int_t is an int that can only ever contain positive</span>
<span style="color: #666666;">// even values.</span>
<span style="color: #0000ff;">typedef</span> fhtagn<span style="color: #008080;">::</span><span style="color: #007788;">restricted</span><span style="color: #000080;">&lt;</span><span style="color: #0000ff;">int</span>,
  fhtagn<span style="color: #008080;">::</span><span style="color: #007788;">restrictions</span><span style="color: #008080;">::</span><span style="color: #007788;">numeric</span><span style="color: #008080;">::</span><span style="color: #007788;">positive</span><span style="color: #000080;">&lt;</span><span style="color: #0000ff;">int</span>,
    fhtagn<span style="color: #008080;">::</span><span style="color: #007788;">restrictions</span><span style="color: #008080;">::</span><span style="color: #007788;">numeric</span><span style="color: #008080;">::</span><span style="color: #007788;">even</span><span style="color: #000080;">&lt;</span><span style="color: #0000ff;">int</span><span style="color: #000080;">&gt;</span>
  <span style="color: #000080;">&gt;</span>
<span style="color: #000080;">&gt;</span> positive_even_int_t<span style="color: #008080;">;</span></pre></td></tr></table></div>

<p>Here, it&#8217;s first assured that the value to be assigned to the restricted data type is positive, then it&#8217;s assured it&#8217;s even. If either of the restrictions is violated, an exception is thrown, and nested restrictions are not evaluated any more<sup><a href="http://fhtagn.unwesen.de/2008/11/19/constrained_vs_restricted_value_types/#footnote_0_9" id="identifier_0_9" class="footnote-link footnote-identifier-link" title="It therefore makes sense to first use positive, as that&amp;#8217;s very easily evaluated and already excludes half of the search space before even needs to be evaluated. Granted, the latter also excludes half of the search space, but at the cost of an additional division. Yes, I&amp;#8217;m being picky here">1</a></sup>.</p>
<p>And that&#8217;s the gist of how restricted data types work. So how do the two implementations differ?</p>
<ol class="footnotes"><li id="footnote_0_9" class="footnote">It therefore makes sense to first use <code>positive</code>, as that&#8217;s very easily evaluated and already excludes half of the search space before <code>even</code> needs to be evaluated. Granted, the latter also excludes half of the search space, but at the cost of an additional division. Yes, I&#8217;m being picky here</li></ol>]]></content:encoded>
			<wfw:commentRss>http://fhtagn.unwesen.de/2008/11/19/constrained_vs_restricted_value_types/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Infrastructure Update</title>
		<link>http://fhtagn.unwesen.de/2008/11/05/infrastructure_update/</link>
		<comments>http://fhtagn.unwesen.de/2008/11/05/infrastructure_update/#comments</comments>
		<pubDate>Wed, 05 Nov 2008 09:32:26 +0000</pubDate>
		<dc:creator>unwesen</dc:creator>
				<category><![CDATA[site]]></category>

		<guid isPermaLink="false">http://fhtagn.unwesen.de/?p=8</guid>
		<description><![CDATA[In case you hadn&#8217;t noticed, the buildbots, long defunct due to a strange bug, have been fixed. They&#8217;re also switched over to SCons builds, so now produce nightly builds again. I&#8217;ve also finally removed the mailing lists from sourceforge.net, making this site here the home of all infrastructure for Fhtagn!. The new development mailing list [...]]]></description>
			<content:encoded><![CDATA[<p>In case you hadn&#8217;t noticed, the buildbots, long defunct due to <a href="http://buildbot.net/trac/ticket/284">a strange bug</a>, have been fixed. They&#8217;re also switched over to <a href="http://fhtagn.unwesen.de/articles/moved_to_scons_builds">SCons builds</a>, so now produce nightly builds again.</p>
<p>I&#8217;ve also finally removed the mailing lists from sourceforge.net, making this site here the home of all infrastructure for Fhtagn!. The new development mailing list &#8211; the only one for now &#8211; is <a href="mailto:fhtagn-devel@unwesen.de">fhtagn-devel@unwesen.de</a>. You can find the <a href="http://dir.gmane.org/gmane.comp.lib.fhtagn.devel">archives on gmane.org</a>.</p>
<p>The mailing list is handled by <a href="http://www.ezmlm.org/">ezmlm</a>, which means you subscribe by sending a mail to <a href="mailto:fhtagn-devel-subscribe@unwesen.de">fhtagn-devel-subscribe@unwesen.de</a>, and get help on further commands by mailing <a href="mailto:fhtagn-devel-help@unwesen.de">fhtagn-devel-help@unwesen.de</a>.</p>
<p>Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://fhtagn.unwesen.de/2008/11/05/infrastructure_update/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Moved to SCons builds</title>
		<link>http://fhtagn.unwesen.de/2008/09/23/moved_to_scons_builds/</link>
		<comments>http://fhtagn.unwesen.de/2008/09/23/moved_to_scons_builds/#comments</comments>
		<pubDate>Tue, 23 Sep 2008 19:51:07 +0000</pubDate>
		<dc:creator>unwesen</dc:creator>
				<category><![CDATA[development]]></category>

		<guid isPermaLink="false">http://fhtagn.unwesen.de/articles/moved_to_scons_builds</guid>
		<description><![CDATA[We&#8217;ve wanted some advaced feature in the Fhtagn! builds, which would have been pretty ugly to hack up in autotools. For that reason, and because it just makes building a bit nicer, we&#8217;ve moved trunk over to use SCons. Now don&#8217;t get me wrong, SCons isn&#8217;t the answer to all build problems &#8212; but it&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>We&#8217;ve wanted some advaced feature in the Fhtagn! builds, which would have been pretty ugly to hack up in <a href="http://www.gnu.org/software/autoconf/">autotools</a>. For that reason, and because it just makes building a bit nicer, we&#8217;ve moved trunk over to use <a href="http://www.scons.org/">SCons</a>.</p>
<p>Now don&#8217;t get me wrong, <a href="http://www.unwesen.de/articles/scons_rant">SCons isn&#8217;t the answer to all build problems</a> &#8212; but it&#8217;s quite a bit better than most build systems out there.</p>
<p>I&#8217;d suggest heading over to the <a href="http://www.scons.org/doc/1.0.1/HTML/scons-user/book1.html">SCons User Guide</a> for a bit of background. The README bundled in trunk includes instructions specific to Fhtagn! But if you&#8217;re impatient, building Fhtagn! shouldn&#8217;t really be a lot more effort than running <code>scons</code> on the command line.</p>
<p>Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://fhtagn.unwesen.de/2008/09/23/moved_to_scons_builds/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

