<?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>Sufficiently Small &#187; C++</title>
	<atom:link href="http://www.smallshire.org.uk/sufficientlysmall/tag/c/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.smallshire.org.uk/sufficientlysmall</link>
	<description>sin(x) = x</description>
	<lastBuildDate>Sun, 11 Apr 2010 19:36:07 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>In C++ throw is an expression</title>
		<link>http://www.smallshire.org.uk/sufficientlysmall/2009/07/31/in-c-throw-is-an-expression/</link>
		<comments>http://www.smallshire.org.uk/sufficientlysmall/2009/07/31/in-c-throw-is-an-expression/#comments</comments>
		<pubDate>Fri, 31 Jul 2009 11:11:45 +0000</pubDate>
		<dc:creator>Robert Smallshire</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[computing]]></category>
		<category><![CDATA[software]]></category>

		<guid isPermaLink="false">http://www.smallshire.org.uk/sufficientlysmall/?p=384</guid>
		<description><![CDATA[After 15 years programming in C++, I was surprised to discover today that throw in C++ is an expression rather than a statement. As a result, throw may be used as part of larger expressions.

int x = 5;
int y = x &#62; 4 ? x : throw std::out_of_range;

The only use I&#8217;ve found for this &#8212; [...]]]></description>
			<content:encoded><![CDATA[<p>After 15 years programming in C++, I was surprised to discover today that <code>throw</code> in C++ is an expression rather than a statement. As a result, <code>throw</code> may be used as part of larger expressions.</p>
<pre class="brush: cpp;">
int x = 5;
int y = x &gt; 4 ? x : throw std::out_of_range;
</pre>
<p>The only use I&#8217;ve found for this &#8212; and in fact the speculative attempt by which I discovered it &#8212; is range checking within constructor initializer lists.</p>
<pre class="brush: cpp;">
RangeChecked::RangeChecked(int x) :
    int_member(x &gt; 0 ? x : throw std::out_of_range)
{
}
</pre>
<p>It&#8217;s academic what the <i>type</i> of a throw expression is, since it will never be returned, but for type-checking purposes the compiler seems to be happy to use it in place of any type.</p>
<hr/>Copyright &copy; 2010 <strong><a href="http://www.smallshire.org.uk/sufficientlysmall">Sufficiently Small</a></strong>. This Feed is for personal non-commercial use only. If you are not reading this material in your news aggregator, the site you are looking at is guilty of copyright infringement. Please contact legal@smallshire.org.uk so we can take legal action immediately.<br/><span style="float: right;font-size: 7pt"><a href="http://blog.taragana.com/index.php/archive/wordpress-plugins-provided-by-taraganacom/">Plugin</a> by <a href="http://www.taragana.com/">Taragana</a></span>]]></content:encoded>
			<wfw:commentRss>http://www.smallshire.org.uk/sufficientlysmall/2009/07/31/in-c-throw-is-an-expression/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>
