<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" xml:lang="en" xml:base="http://fsfoundry.org/codefreak/wp-atom.php">
	<title type="text">COdE fr3@K</title>
	<subtitle type="text">Weblog of a lively geek.</subtitle>

	<updated>2010-06-30T17:25:33Z</updated>
	<generator uri="http://wordpress.org/" version="2.8.6">WordPress</generator>

	<link rel="alternate" type="text/html" href="http://fsfoundry.org/codefreak" />
	<id>http://fsfoundry.org/codefreak/feed/atom/</id>
	

			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/atom+xml" href="http://feeds.feedburner.com/codefreak" /><feedburner:info uri="codefreak" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><link rel="license" type="text/html" href="http://creativecommons.org/licenses/by-nc-sa/2.5/" /><logo>http://creativecommons.org/images/public/somerights20.gif</logo><feedburner:browserFriendly>This is an XML content feed. It is intended to be viewed in a newsreader or syndicated to another site, subject to copyright and fair use.</feedburner:browserFriendly><entry>
		<author>
			<name>fr3@K</name>
						<uri>http://fsfoundry.org/codefreak/</uri>
					</author>
		<title type="html"><![CDATA[You Don&#8217;t Have to Resort to Goto]]></title>
		<link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/codefreak/~3/6UTB0mfFv3M/" />
		<id>http://fsfoundry.org/codefreak/?p=1013</id>
		<updated>2010-06-30T02:01:05Z</updated>
		<published>2010-06-19T14:35:13Z</published>
		<category scheme="http://fsfoundry.org/codefreak" term="~" /><category scheme="http://fsfoundry.org/codefreak" term="C++" /><category scheme="http://fsfoundry.org/codefreak" term="geeky" />		<summary type="html"><![CDATA[你一定看過這樣的 code:

PLAIN TEXT
C:




int do_something&#40;size_t n&#41;


&#123;


&#160; int result = ERROR;


&#160; char* buf;


&#160;


&#160; if&#40;n&#41;


&#160; &#123;


&#160; &#160; buf =&#160; malloc&#40;n&#41;;


&#160; &#160; if&#40;buf != 0&#41;


&#160; &#160; &#123;


&#160; &#160; &#160; if&#40;do_foo&#40;buf, n&#41; == OKAY&#41;


&#160; &#160; &#160; &#123;


&#160; &#160; &#160; &#160; if&#40;do_bar&#40;buf, n&#41; == OKAY&#41;


&#160; &#160; &#160; &#160; &#160; result = OKAY;


&#160; &#160; &#160; &#125;


&#160; &#160; &#160; free&#40;buf&#41;;


&#160; &#160; &#125;


&#160; &#125;


&#160;


&#160; [...]]]></summary>
		<content type="html" xml:base="http://fsfoundry.org/codefreak/2010/06/19/you-dont-have-to-resort-to-goto/">&lt;p&gt;你一定看過這樣的 code:&lt;/p&gt;
&lt;ul&gt;
&lt;div class="igBar"&gt;&lt;span id="lc-5"&gt;&lt;a href="#" onclick="javascript:showPlainTxt('c-5'); return false;"&gt;PLAIN TEXT&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="syntax_hilite"&gt;&lt;span class="langName"&gt;C:&lt;/span&gt;
&lt;div id="c-5"&gt;
&lt;div class="c"&gt;
&lt;ol&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #993333;"&gt;int&lt;/span&gt; do_something&lt;span style="color: #66cc66;"&gt;&amp;#40;&lt;/span&gt;size_t n&lt;span style="color: #66cc66;"&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #66cc66;"&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #993333;"&gt;int&lt;/span&gt; result = ERROR;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #993333;"&gt;char&lt;/span&gt;* buf;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #b1b100;"&gt;if&lt;/span&gt;&lt;span style="color: #66cc66;"&gt;&amp;#40;&lt;/span&gt;n&lt;span style="color: #66cc66;"&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #66cc66;"&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; buf =&amp;nbsp; malloc&lt;span style="color: #66cc66;"&gt;&amp;#40;&lt;/span&gt;n&lt;span style="color: #66cc66;"&gt;&amp;#41;&lt;/span&gt;;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; &lt;span style="color: #b1b100;"&gt;if&lt;/span&gt;&lt;span style="color: #66cc66;"&gt;&amp;#40;&lt;/span&gt;buf != &lt;span style="color: #cc66cc;color:#800000;"&gt;0&lt;/span&gt;&lt;span style="color: #66cc66;"&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; &lt;span style="color: #66cc66;"&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="color: #b1b100;"&gt;if&lt;/span&gt;&lt;span style="color: #66cc66;"&gt;&amp;#40;&lt;/span&gt;do_foo&lt;span style="color: #66cc66;"&gt;&amp;#40;&lt;/span&gt;buf, n&lt;span style="color: #66cc66;"&gt;&amp;#41;&lt;/span&gt; == OKAY&lt;span style="color: #66cc66;"&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="color: #66cc66;"&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="color: #b1b100;"&gt;if&lt;/span&gt;&lt;span style="color: #66cc66;"&gt;&amp;#40;&lt;/span&gt;do_bar&lt;span style="color: #66cc66;"&gt;&amp;#40;&lt;/span&gt;buf, n&lt;span style="color: #66cc66;"&gt;&amp;#41;&lt;/span&gt; == OKAY&lt;span style="color: #66cc66;"&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; result = OKAY;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style="color: #66cc66;"&gt;&amp;#125;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; free&lt;span style="color: #66cc66;"&gt;&amp;#40;&lt;/span&gt;buf&lt;span style="color: #66cc66;"&gt;&amp;#41;&lt;/span&gt;;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; &lt;span style="color: #66cc66;"&gt;&amp;#125;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #66cc66;"&gt;&amp;#125;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #b1b100;"&gt;return&lt;/span&gt; result;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #66cc66;"&gt;&amp;#125;&lt;/span&gt; &lt;/div&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;/ul&gt;
&lt;p&gt;可讀性差的巢狀 &lt;code&gt;if&lt;/code&gt; block, 只為了堅持由一處 &lt;code&gt;return&lt;/code&gt;.&lt;br /&gt;
&lt;span id="more-1013"&gt;&lt;/span&gt;&lt;br /&gt;
想必也看過這樣的 code:&lt;/p&gt;
&lt;ul&gt;
&lt;div class="igBar"&gt;&lt;span id="lc-6"&gt;&lt;a href="#" onclick="javascript:showPlainTxt('c-6'); return false;"&gt;PLAIN TEXT&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="syntax_hilite"&gt;&lt;span class="langName"&gt;C:&lt;/span&gt;
&lt;div id="c-6"&gt;
&lt;div class="c"&gt;
&lt;ol&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #993333;"&gt;int&lt;/span&gt; do_something&lt;span style="color: #66cc66;"&gt;&amp;#40;&lt;/span&gt;size_t n&lt;span style="color: #66cc66;"&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #66cc66;"&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #993333;"&gt;char&lt;/span&gt;* buf;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #b1b100;"&gt;if&lt;/span&gt;&lt;span style="color: #66cc66;"&gt;&amp;#40;&lt;/span&gt;n == &lt;span style="color: #cc66cc;color:#800000;"&gt;0&lt;/span&gt;&lt;span style="color: #66cc66;"&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; &lt;span style="color: #b1b100;"&gt;return&lt;/span&gt; ERROR;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; buf =&amp;nbsp; malloc&lt;span style="color: #66cc66;"&gt;&amp;#40;&lt;/span&gt;n&lt;span style="color: #66cc66;"&gt;&amp;#41;&lt;/span&gt;;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #b1b100;"&gt;if&lt;/span&gt;&lt;span style="color: #66cc66;"&gt;&amp;#40;&lt;/span&gt;buf == &lt;span style="color: #cc66cc;color:#800000;"&gt;0&lt;/span&gt;&lt;span style="color: #66cc66;"&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; &lt;span style="color: #b1b100;"&gt;return&lt;/span&gt; ERROR;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #b1b100;"&gt;if&lt;/span&gt;&lt;span style="color: #66cc66;"&gt;&amp;#40;&lt;/span&gt;do_foo&lt;span style="color: #66cc66;"&gt;&amp;#40;&lt;/span&gt;buf, n&lt;span style="color: #66cc66;"&gt;&amp;#41;&lt;/span&gt; != OKAY&lt;span style="color: #66cc66;"&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #66cc66;"&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; free&lt;span style="color: #66cc66;"&gt;&amp;#40;&lt;/span&gt;buf&lt;span style="color: #66cc66;"&gt;&amp;#41;&lt;/span&gt;;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; &lt;span style="color: #b1b100;"&gt;return&lt;/span&gt; ERROR;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #66cc66;"&gt;&amp;#125;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #b1b100;"&gt;if&lt;/span&gt;&lt;span style="color: #66cc66;"&gt;&amp;#40;&lt;/span&gt;do_bar&lt;span style="color: #66cc66;"&gt;&amp;#40;&lt;/span&gt;buf, n&lt;span style="color: #66cc66;"&gt;&amp;#41;&lt;/span&gt; != OKAY&lt;span style="color: #66cc66;"&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #66cc66;"&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; free&lt;span style="color: #66cc66;"&gt;&amp;#40;&lt;/span&gt;buf&lt;span style="color: #66cc66;"&gt;&amp;#41;&lt;/span&gt;;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; &lt;span style="color: #b1b100;"&gt;return&lt;/span&gt; ERROR;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #66cc66;"&gt;&amp;#125;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #b1b100;"&gt;return&lt;/span&gt; OKAY;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #66cc66;"&gt;&amp;#125;&lt;/span&gt; &lt;/div&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;/ul&gt;
&lt;p&gt;由多處 &lt;code&gt;return&lt;/code&gt; 雖避掉了巢狀 &lt;code&gt;if&lt;/code&gt; block, 但需要在多個地方 cleanup 之前所請求的資源.&lt;/p&gt;
&lt;p&gt;當然還有這樣的 code:&lt;/p&gt;
&lt;ul&gt;
&lt;div class="igBar"&gt;&lt;span id="lc-7"&gt;&lt;a href="#" onclick="javascript:showPlainTxt('c-7'); return false;"&gt;PLAIN TEXT&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="syntax_hilite"&gt;&lt;span class="langName"&gt;C:&lt;/span&gt;
&lt;div id="c-7"&gt;
&lt;div class="c"&gt;
&lt;ol&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #993333;"&gt;int&lt;/span&gt; do_something&lt;span style="color: #66cc66;"&gt;&amp;#40;&lt;/span&gt;size_t n&lt;span style="color: #66cc66;"&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #66cc66;"&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #993333;"&gt;int&lt;/span&gt; result = ERROR;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #993333;"&gt;char&lt;/span&gt;* buf = &lt;span style="color: #cc66cc;color:#800000;"&gt;0&lt;/span&gt;;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #b1b100;"&gt;if&lt;/span&gt;&lt;span style="color: #66cc66;"&gt;&amp;#40;&lt;/span&gt;n == &lt;span style="color: #cc66cc;color:#800000;"&gt;0&lt;/span&gt;&lt;span style="color: #66cc66;"&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; &lt;span style="color: #b1b100;"&gt;goto&lt;/span&gt; CLEANUP;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; buf =&amp;nbsp; malloc&lt;span style="color: #66cc66;"&gt;&amp;#40;&lt;/span&gt;n&lt;span style="color: #66cc66;"&gt;&amp;#41;&lt;/span&gt;;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #b1b100;"&gt;if&lt;/span&gt;&lt;span style="color: #66cc66;"&gt;&amp;#40;&lt;/span&gt;buf == &lt;span style="color: #cc66cc;color:#800000;"&gt;0&lt;/span&gt;&lt;span style="color: #66cc66;"&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; &lt;span style="color: #b1b100;"&gt;goto&lt;/span&gt; CLEANUP;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #b1b100;"&gt;if&lt;/span&gt;&lt;span style="color: #66cc66;"&gt;&amp;#40;&lt;/span&gt;do_foo&lt;span style="color: #66cc66;"&gt;&amp;#40;&lt;/span&gt;buf, n&lt;span style="color: #66cc66;"&gt;&amp;#41;&lt;/span&gt; != OKAY&lt;span style="color: #66cc66;"&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; &lt;span style="color: #b1b100;"&gt;goto&lt;/span&gt; CLEANUP;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #b1b100;"&gt;if&lt;/span&gt;&lt;span style="color: #66cc66;"&gt;&amp;#40;&lt;/span&gt;do_bar&lt;span style="color: #66cc66;"&gt;&amp;#40;&lt;/span&gt;buf, n&lt;span style="color: #66cc66;"&gt;&amp;#41;&lt;/span&gt; != OKAY&lt;span style="color: #66cc66;"&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; &lt;span style="color: #b1b100;"&gt;goto&lt;/span&gt; CLEANUP;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; result = OKAY;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;CLEANUP:&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #808080; font-style: italic;"&gt;// free()ing a NULL ptr is a no-op.&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; free&lt;span style="color: #66cc66;"&gt;&amp;#40;&lt;/span&gt;buf&lt;span style="color: #66cc66;"&gt;&amp;#41;&lt;/span&gt;;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #b1b100;"&gt;return&lt;/span&gt; result;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #66cc66;"&gt;&amp;#125;&lt;/span&gt; &lt;/div&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;/ul&gt;
&lt;p&gt;不管老師以前是如何叮嚀不要用 &lt;code&gt;goto&lt;/code&gt;, 為了閃掉那噁心的巢狀 &lt;code&gt;if&lt;/code&gt; block 以及重複的 code, 只好還是用了 &lt;code&gt;goto&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;其實還有另一種選擇, 不用重複寫釋放資源的 code, 也不需要用到 &lt;code&gt;goto&lt;/code&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;div class="igBar"&gt;&lt;span id="lc-8"&gt;&lt;a href="#" onclick="javascript:showPlainTxt('c-8'); return false;"&gt;PLAIN TEXT&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="syntax_hilite"&gt;&lt;span class="langName"&gt;C:&lt;/span&gt;
&lt;div id="c-8"&gt;
&lt;div class="c"&gt;
&lt;ol&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #993333;"&gt;static&lt;/span&gt; &lt;span style="color: #993333;"&gt;int&lt;/span&gt; do_something_helper&lt;span style="color: #66cc66;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #993333;"&gt;char&lt;/span&gt;* buf, n&lt;span style="color: #66cc66;"&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #66cc66;"&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #b1b100;"&gt;if&lt;/span&gt;&lt;span style="color: #66cc66;"&gt;&amp;#40;&lt;/span&gt;do_foo&lt;span style="color: #66cc66;"&gt;&amp;#40;&lt;/span&gt;buf, n&lt;span style="color: #66cc66;"&gt;&amp;#41;&lt;/span&gt; != OKAY&lt;span style="color: #66cc66;"&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; &lt;span style="color: #b1b100;"&gt;return&lt;/span&gt; ERROR;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #b1b100;"&gt;if&lt;/span&gt;&lt;span style="color: #66cc66;"&gt;&amp;#40;&lt;/span&gt;do_bar&lt;span style="color: #66cc66;"&gt;&amp;#40;&lt;/span&gt;buf, n&lt;span style="color: #66cc66;"&gt;&amp;#41;&lt;/span&gt; != OKAY&lt;span style="color: #66cc66;"&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; &lt;span style="color: #b1b100;"&gt;return&lt;/span&gt; ERROR;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #b1b100;"&gt;return&lt;/span&gt; OKAY;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #66cc66;"&gt;&amp;#125;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #993333;"&gt;int&lt;/span&gt; do_something&lt;span style="color: #66cc66;"&gt;&amp;#40;&lt;/span&gt;size_t n&lt;span style="color: #66cc66;"&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #66cc66;"&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #993333;"&gt;int&lt;/span&gt; result;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #993333;"&gt;char&lt;/span&gt;* buf;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #b1b100;"&gt;if&lt;/span&gt;&lt;span style="color: #66cc66;"&gt;&amp;#40;&lt;/span&gt;n == &lt;span style="color: #cc66cc;color:#800000;"&gt;0&lt;/span&gt;&lt;span style="color: #66cc66;"&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; &lt;span style="color: #b1b100;"&gt;return&lt;/span&gt; ERROR;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; buf =&amp;nbsp; malloc&lt;span style="color: #66cc66;"&gt;&amp;#40;&lt;/span&gt;n&lt;span style="color: #66cc66;"&gt;&amp;#41;&lt;/span&gt;;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #b1b100;"&gt;if&lt;/span&gt;&lt;span style="color: #66cc66;"&gt;&amp;#40;&lt;/span&gt;buf == &lt;span style="color: #cc66cc;color:#800000;"&gt;0&lt;/span&gt;&lt;span style="color: #66cc66;"&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; &lt;span style="color: #b1b100;"&gt;return&lt;/span&gt; ERROR;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; result = do_something_helper&lt;span style="color: #66cc66;"&gt;&amp;#40;&lt;/span&gt;buf, n&lt;span style="color: #66cc66;"&gt;&amp;#41;&lt;/span&gt;;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; free&lt;span style="color: #66cc66;"&gt;&amp;#40;&lt;/span&gt;buf&lt;span style="color: #66cc66;"&gt;&amp;#41;&lt;/span&gt;;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #b1b100;"&gt;return&lt;/span&gt; result;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #66cc66;"&gt;&amp;#125;&lt;/span&gt; &lt;/div&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;/ul&gt;
&lt;p&gt;一旦把 resource management 跟 logic 的部份拆開, code 就好看多了.&lt;/p&gt;
&lt;ul&gt;&lt;em&gt;獻給一位因為沒有充足理由的規定, 卻在工作中被迫得寫 pure C 的可憐同事.&lt;/em&gt;&lt;/ul&gt;
&lt;p&gt;後記: 這應該是目前我寫的唯一一篇 pure C 的文字. 擔心它太寂寞, 還是把它打上了 &lt;a href="http://fsfoundry.org/codefreak/tag/cpp/"&gt;C++&lt;/a&gt; 的 tag.&lt;/p&gt;
&lt;br /&gt;&lt;a href="http://fsfoundry.org/codefreak/?p=1013#comments" title="Comments on &amp;quot;You Don&amp;#8217;t Have to Resort to Goto&amp;quot;"&gt;&lt;img src="http://fsfoundry.org/codefreak/wp-content/plugins/feed-comments-number/image.php?1013" alt="Comments" /&gt;&lt;/a&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/codefreak?a=6UTB0mfFv3M:F2lS2HjhHSc:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/codefreak?i=6UTB0mfFv3M:F2lS2HjhHSc:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</content>
		<link rel="replies" type="text/html" href="http://fsfoundry.org/codefreak/2010/06/19/you-dont-have-to-resort-to-goto/#comments" thr:count="8" />
		<link rel="replies" type="application/atom+xml" href="http://fsfoundry.org/codefreak/2010/06/19/you-dont-have-to-resort-to-goto/feed/atom/" thr:count="8" />
		<thr:total>8</thr:total>
	<feedburner:origLink>http://fsfoundry.org/codefreak/2010/06/19/you-dont-have-to-resort-to-goto/</feedburner:origLink></entry>
		<entry>
		<author>
			<name>fr3@K</name>
						<uri>http://fsfoundry.org/codefreak/</uri>
					</author>
		<title type="html"><![CDATA[華碩品質, 以卵擊石]]></title>
		<link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/codefreak/~3/4KDlcSMUrRY/" />
		<id>http://fsfoundry.org/codefreak/?p=983</id>
		<updated>2010-06-01T17:24:45Z</updated>
		<published>2010-06-01T17:24:23Z</published>
		<category scheme="http://fsfoundry.org/codefreak" term="~" /><category scheme="http://fsfoundry.org/codefreak" term="foss" /><category scheme="http://fsfoundry.org/codefreak" term="geeky" /><category scheme="http://fsfoundry.org/codefreak" term="whining" />		<summary type="html"><![CDATA[很多人可能已經沒印象了. 但我記得很清楚.
去年 5 月底, The Register 所做的一則 報導:
Microsoft and Asus have teamed up to present a new advertising smarm-storm intended to extol the virtues of Windows on netbooks - and smear Linux.

而在今天的這則 ZDNet Taiwan 的 報導 卻又看到:
英特爾表示，宏碁、華碩、戴爾、諾基亞、惠普(儘管已擁有自己的WebOS)等品牌廠商，都已加入發展MeeGo平板的計畫，並有多家OSV、ISV與服務提供廠商來共同建構此生態鏈。
英特爾表示，MeeGo是一款可跨裝置的行動作業系統，將用在手持裝置、小筆電、平板裝置、車用裝置或電視上，此作業系統是基於Linux的開源碼計畫，並獲Linux基金會贊助，目前正由英特爾、諾基亞與開發者社群合作推動。
並登出一張 以卵擊石 展示機 (?) 的照片:



果真是有堅持有願景的企業啊!
也不知道是什麼時候, 這家 以卵擊石 的公司已經把那 可笑 的網站下線了, 現在是個 parking page. 真是後悔當時沒做個 screenshot 留個紀念~
剛剛在 google 以卵擊石 的時候發現了一件有趣的事情:



Google [...]]]></summary>
		<content type="html" xml:base="http://fsfoundry.org/codefreak/2010/06/02/%e8%8f%af%e7%a2%a9%e5%93%81%e8%b3%aa-%e4%bb%a5%e5%8d%b5%e6%93%8a%e7%9f%b3/">&lt;p&gt;很多人可能已經沒印象了. 但我記得很清楚.&lt;/p&gt;
&lt;p&gt;去年 &lt;a href="http://fsfoundry.org/codefreak/2009/05/30/its-better-without-asus/"&gt;5 月底&lt;/a&gt;, The Register 所做的一則 &lt;a href="http://www.theregister.co.uk/2009/05/30/its_better_with_windows/"&gt;報導&lt;/a&gt;:&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;Microsoft and Asus have teamed up to present a new advertising smarm-storm intended to extol the virtues of Windows on netbooks - and smear Linux.&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;&lt;span id="more-983"&gt;&lt;/span&gt;&lt;br /&gt;
而在今天的這則 ZDNet Taiwan 的 &lt;a href="http://www.zdnet.com.tw/news/ce/0,2000085674,20145785,00.htm" rel="nofollow"&gt;報導&lt;/a&gt; 卻又看到:&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;英特爾表示，宏碁、&lt;big&gt;&lt;strong&gt;&lt;em&gt;華碩&lt;/em&gt;&lt;/strong&gt;&lt;/big&gt;、戴爾、諾基亞、惠普(儘管已擁有自己的WebOS)等品牌廠商，都已加入發展MeeGo平板的計畫，並有多家OSV、ISV與服務提供廠商來共同建構此生態鏈。&lt;/p&gt;
&lt;p&gt;英特爾表示，MeeGo是一款可跨裝置的行動作業系統，將用在手持裝置、小筆電、平板裝置、車用裝置或電視上，&lt;big&gt;&lt;strong&gt;&lt;em&gt;此作業系統是基於Linux的開源碼計畫&lt;/em&gt;&lt;/strong&gt;&lt;/big&gt;，並獲Linux基金會贊助，目前正由英特爾、諾基亞與開發者社群合作推動。&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;並登出一張 &lt;a href="http://www.asus.com/"&gt;以卵擊石&lt;/a&gt; 展示機 (?) 的照片:&lt;/p&gt;
&lt;ul&gt;
&lt;a href="http://fsfoundry.org/codefreak/wp-content/uploads/2010/06/Screenshot-ZDNet-Taiwan-【Computex】台廠展示MeeGo平板、小筆電（圖）-新聞-數位產品-Mozilla-Firefox.png" rel="lightbox"&gt;&lt;img src="http://fsfoundry.org/codefreak/wp-content/uploads/2010/06/Screenshot-ZDNet-Taiwan-【Computex】台廠展示MeeGo平板、小筆電（圖）-新聞-數位產品-Mozilla-Firefox-300x251.png" alt="Screenshot-ZDNet Taiwan - 【Computex】台廠展示MeeGo平板、小筆電（圖） - 新聞 - 數位產品 - Mozilla Firefox" title="Screenshot-ZDNet Taiwan - 【Computex】台廠展示MeeGo平板、小筆電（圖） - 新聞 - 數位產品 - Mozilla Firefox" width="300" height="251" class="alignnone size-medium wp-image-997" /&gt;&lt;/a&gt;
&lt;/ul&gt;
&lt;p&gt;果真是有堅持有願景的企業啊!&lt;/p&gt;
&lt;p&gt;也不知道是什麼時候, 這家 &lt;a href="http://www.asus.com/"&gt;以卵擊石&lt;/a&gt; 的公司已經把那 &lt;a href="http://www.itsbetterwithwindows.com/"&gt;可笑&lt;/a&gt; 的網站下線了, 現在是個 parking page. 真是後悔當時沒做個 screenshot 留個紀念~&lt;/p&gt;
&lt;p&gt;剛剛在 &lt;a href="http://www.google.com.tw/search?hl=zh-TW&amp;#038;lr=lang_zh-CN|lang_zh-TW&amp;#038;safe=off&amp;#038;client=firefox-a&amp;#038;rls=com.ubuntu%3Aen-US%3Aofficial&amp;#038;tbs=lr%3Alang_1zh-CN|lang_1zh-TW&amp;#038;q=asus&amp;#038;aq=f&amp;#038;aqi=&amp;#038;aql=&amp;#038;oq=&amp;#038;gs_rfai="&gt;google 以卵擊石&lt;/a&gt; 的時候發現了一件有趣的事情:&lt;/p&gt;
&lt;ul&gt;
&lt;a href="http://fsfoundry.org/codefreak/wp-content/uploads/2010/06/Screenshot-asus-Google-搜尋-Mozilla-Firefox.png" rel="lightbox"&gt;&lt;img src="http://fsfoundry.org/codefreak/wp-content/uploads/2010/06/Screenshot-asus-Google-搜尋-Mozilla-Firefox-300x264.png" alt="Screenshot-asus - Google 搜尋 - Mozilla Firefox" title="Screenshot-asus - Google 搜尋 - Mozilla Firefox" width="300" height="264" class="alignnone size-medium wp-image-999" /&gt;&lt;/a&gt;
&lt;/ul&gt;
&lt;p&gt;Google &lt;a href="http://www.asus.com/"&gt;以卵擊石&lt;/a&gt; 的第一個結果是 tw.asus.com, 可是 google 看到的內容卻是簡體的. WTF.&lt;/p&gt;
&lt;br /&gt;&lt;a href="http://fsfoundry.org/codefreak/?p=983#comments" title="Comments on &amp;quot;華碩品質, 以卵擊石&amp;quot;"&gt;&lt;img src="http://fsfoundry.org/codefreak/wp-content/plugins/feed-comments-number/image.php?983" alt="Comments" /&gt;&lt;/a&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/codefreak?a=4KDlcSMUrRY:8U7EACD_vJc:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/codefreak?i=4KDlcSMUrRY:8U7EACD_vJc:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</content>
		<link rel="replies" type="text/html" href="http://fsfoundry.org/codefreak/2010/06/02/%e8%8f%af%e7%a2%a9%e5%93%81%e8%b3%aa-%e4%bb%a5%e5%8d%b5%e6%93%8a%e7%9f%b3/#comments" thr:count="0" />
		<link rel="replies" type="application/atom+xml" href="http://fsfoundry.org/codefreak/2010/06/02/%e8%8f%af%e7%a2%a9%e5%93%81%e8%b3%aa-%e4%bb%a5%e5%8d%b5%e6%93%8a%e7%9f%b3/feed/atom/" thr:count="0" />
		<thr:total>0</thr:total>
	<feedburner:origLink>http://fsfoundry.org/codefreak/2010/06/02/%e8%8f%af%e7%a2%a9%e5%93%81%e8%b3%aa-%e4%bb%a5%e5%8d%b5%e6%93%8a%e7%9f%b3/</feedburner:origLink></entry>
		<entry>
		<author>
			<name>fr3@K</name>
						<uri>http://fsfoundry.org/codefreak/</uri>
					</author>
		<title type="html"><![CDATA[你怎麼在看簡體的東西!?]]></title>
		<link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/codefreak/~3/-wSalFm2rnk/" />
		<id>http://fsfoundry.org/codefreak/?p=960</id>
		<updated>2010-05-30T13:17:14Z</updated>
		<published>2010-05-30T08:31:17Z</published>
		<category scheme="http://fsfoundry.org/codefreak" term="~" /><category scheme="http://fsfoundry.org/codefreak" term="mortal" /><category scheme="http://fsfoundry.org/codefreak" term="whining" />		<summary type="html"><![CDATA["你怎麼在看簡體的東西!?" 不久前, 一位同事在會議中看到我在 NB 上讀到一半的一篇簡體文章, 驚訝地對我說.1
"醒醒吧老兄. 對岸華人同胞產出的技術性文章, 不論是原創或翻譯, 不管是數量甚至很可能連質量, 都超過我們了啊." 我心理的 OS.
是的, 我的 feed subscription 的數量: 英文 > 簡中 > 繁中.
台灣, 加油好嗎? 要了解自己, 搞清楚自己的強項面對自己的短處. 不必自大也不需自卑, 別成了井底之蛙.
是不是在開玩笑我就不知道了. [↩]]]></summary>
		<content type="html" xml:base="http://fsfoundry.org/codefreak/2010/05/30/%e4%bd%a0%e6%80%8e%e9%ba%bc%e5%9c%a8%e7%9c%8b%e7%b0%a1%e9%ab%94%e7%9a%84%e6%9d%b1%e8%a5%bf/">&lt;p&gt;"你怎麼在看簡體的東西!?" 不久前, 一位同事在會議中看到我在 NB 上讀到一半的一篇簡體文章, 驚訝地對我說.&lt;sup&gt;&lt;a href="#footnote-1-960" id="footnote-link-1-960" class="footnote-link footnote-identifier-link" title="是不是在開玩笑我就不知道了."&gt;1&lt;/a&gt;&lt;/sup&gt;&lt;/p&gt;
&lt;p&gt;"醒醒吧老兄. 對岸華人同胞產出的技術性文章, 不論是原創或翻譯, 不管是數量甚至很可能連質量, 都超過我們了啊." 我心理的 OS.&lt;/p&gt;
&lt;p&gt;是的, 我的 feed subscription 的數量: 英文 &gt; 簡中 &gt; 繁中.&lt;/p&gt;
&lt;p&gt;台灣, 加油好嗎? 要了解自己, 搞清楚自己的強項面對自己的短處. 不必自大也不需自卑, 別成了井底之蛙.&lt;/p&gt;
&lt;br /&gt;&lt;a href="http://fsfoundry.org/codefreak/?p=960#comments" title="Comments on &amp;quot;你怎麼在看簡體的東西!?&amp;quot;"&gt;&lt;img src="http://fsfoundry.org/codefreak/wp-content/plugins/feed-comments-number/image.php?960" alt="Comments" /&gt;&lt;/a&gt;&lt;ol start="1" class="footnotes"&gt;&lt;li id="footnote-1-960" class="footnote"&gt;是不是在開玩笑我就不知道了. [&lt;a href="#footnote-link-1-960" class="footnote-link footnote-back-link"&gt;↩&lt;/a&gt;]&lt;/li&gt;&lt;/ol&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/codefreak?a=-wSalFm2rnk:I_sCAJmArvw:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/codefreak?i=-wSalFm2rnk:I_sCAJmArvw:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</content>
		<link rel="replies" type="text/html" href="http://fsfoundry.org/codefreak/2010/05/30/%e4%bd%a0%e6%80%8e%e9%ba%bc%e5%9c%a8%e7%9c%8b%e7%b0%a1%e9%ab%94%e7%9a%84%e6%9d%b1%e8%a5%bf/#comments" thr:count="3" />
		<link rel="replies" type="application/atom+xml" href="http://fsfoundry.org/codefreak/2010/05/30/%e4%bd%a0%e6%80%8e%e9%ba%bc%e5%9c%a8%e7%9c%8b%e7%b0%a1%e9%ab%94%e7%9a%84%e6%9d%b1%e8%a5%bf/feed/atom/" thr:count="3" />
		<thr:total>3</thr:total>
	<feedburner:origLink>http://fsfoundry.org/codefreak/2010/05/30/%e4%bd%a0%e6%80%8e%e9%ba%bc%e5%9c%a8%e7%9c%8b%e7%b0%a1%e9%ab%94%e7%9a%84%e6%9d%b1%e8%a5%bf/</feedburner:origLink></entry>
		<entry>
		<author>
			<name>fr3@K</name>
						<uri>http://fsfoundry.org/codefreak/</uri>
					</author>
		<title type="html"><![CDATA[re: 解读google C++ code style谈对C++的理解]]></title>
		<link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/codefreak/~3/cJhCc-nvHts/" />
		<id>http://fsfoundry.org/codefreak/?p=937</id>
		<updated>2010-05-30T13:12:18Z</updated>
		<published>2010-05-30T08:11:25Z</published>
		<category scheme="http://fsfoundry.org/codefreak" term="~" /><category scheme="http://fsfoundry.org/codefreak" term="C++" /><category scheme="http://fsfoundry.org/codefreak" term="cited" /><category scheme="http://fsfoundry.org/codefreak" term="commentary" /><category scheme="http://fsfoundry.org/codefreak" term="exception" /><category scheme="http://fsfoundry.org/codefreak" term="geeky" /><category scheme="http://fsfoundry.org/codefreak" term="whining" />		<summary type="html"><![CDATA[
想加入這篇 解读google C++ code style谈对C++的理解 的討論. 不幸由於不明原因, 一直被系統認為是廣告 (圖中紅字部份):
先留個底, 再看看該/能怎麼辦吧.
ps. cppblog 帳號申請中, 也許有帳號就沒這問題了吧? 不過, 看起來申請帳號要經過人工審核...


@那谁
我不懂 Python, (没写过且只看得懂一点点) 我想你说的那份 Google 开源 的 Python  "没有使用到异常" 不尽正确. 应为 "没处理异常".
以 "class CleansedLines(object)" 的 "__init__" method 为例, 里面有对 list 的 append. 虽然我不清楚 Python list 的实作, 但我很难想像可以对任何一种 list 的实作, 不需要 memory allocation 便可对其 append N (N 未知) 个 element. 一旦需要 [...]]]></summary>
		<content type="html" xml:base="http://fsfoundry.org/codefreak/2010/05/30/re-%e8%a7%a3%e8%af%bbgoogle-cpp-code-style%e8%b0%88%e5%af%b9cpp%e7%9a%84%e7%90%86%e8%a7%a3/">&lt;p&gt;&lt;a href="http://fsfoundry.org/codefreak/wp-content/uploads/2010/05/Screenshot-解读google-C++-code-style谈对C++的理解-那谁的技术博客-C++博客-Mozilla-Firefox.png" rel="lightbox"&gt;&lt;img src="http://fsfoundry.org/codefreak/wp-content/uploads/2010/05/Screenshot-解读google-C++-code-style谈对C++的理解-那谁的技术博客-C++博客-Mozilla-Firefox-300x298.png" alt="Screenshot-解读google C++ code style谈对C++的理解 - 那谁的技术博客 - C++博客 - Mozilla Firefox" title="Screenshot-解读google C++ code style谈对C++的理解 - 那谁的技术博客 - C++博客 - Mozilla Firefox" width="300" height="298" class="aligncenter size-medium wp-image-938" align="right" hspace="10" vspace="10" /&gt;&lt;/a&gt;&lt;br /&gt;
想加入這篇 &lt;a href="http://www.cppblog.com/converse/archive/2010/05/29/116689.html" rel="nofollow"&gt;解读google C++ code style谈对C++的理解&lt;/a&gt; 的討論. 不幸由於不明原因, 一直被系統認為是廣告 (圖中紅字部份):&lt;/p&gt;
&lt;p&gt;先留個底, 再看看該/能怎麼辦吧.&lt;/p&gt;
&lt;p&gt;ps. cppblog 帳號申請中, 也許有帳號就沒這問題了吧? 不過, 看起來申請帳號要經過人工審核...&lt;br /&gt;
&lt;span id="more-937"&gt;&lt;/span&gt;&lt;/p&gt;
&lt;hr/&gt;
&lt;p&gt;@那谁&lt;br /&gt;
我不懂 Python, (没写过且只看得懂一点点) 我想你说的那份 Google 开源 的 Python  "没有使用到异常" 不尽正确. 应为 "没处理异常".&lt;/p&gt;
&lt;p&gt;以 "class CleansedLines(object)" 的 "__init__" method 为例, 里面有对 list 的 append. 虽然我不清楚 Python list 的实作, 但我很难想像可以对任何一种 list 的实作, 不需要 memory allocation 便可对其 append N (N 未知) 个 element. 一旦需要 memory allocation 就有可能失败, 也就有触发异常的可能. 只是处理与否, 那是另外一回事.&lt;/p&gt;
&lt;p&gt;小弟是你的读者, 虽然不完全同意你所有文章的看法. 回应目的为交流, 非论战.&lt;/p&gt;
&lt;p&gt;@OwnWaterloo&lt;br /&gt;
"那么， 换来的结论就是： goolge中的C++程序员， 对异常这种编程思想的理解， 还不如google中的python和java程序员。"&lt;/p&gt;
&lt;p&gt;对 Google 的 coding style 我也得到同样的推论, 我认为可能可以勉强说得通的两个点:&lt;br /&gt;
1. C++ 的 programmer 可能较严谨, 因此更认真看待 exception 的发生以及对应的处理方式. 而部份认真的人得到的结论是 "don't do it".&lt;br /&gt;
2. C++ 的 exception 较容易导致 memory leak.&lt;/p&gt;
&lt;br /&gt;&lt;a href="http://fsfoundry.org/codefreak/?p=937#comments" title="Comments on &amp;quot;re: 解读google C++ code style谈对C++的理解&amp;quot;"&gt;&lt;img src="http://fsfoundry.org/codefreak/wp-content/plugins/feed-comments-number/image.php?937" alt="Comments" /&gt;&lt;/a&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/codefreak?a=cJhCc-nvHts:rVSTxkSn-DA:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/codefreak?i=cJhCc-nvHts:rVSTxkSn-DA:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</content>
		<link rel="replies" type="text/html" href="http://fsfoundry.org/codefreak/2010/05/30/re-%e8%a7%a3%e8%af%bbgoogle-cpp-code-style%e8%b0%88%e5%af%b9cpp%e7%9a%84%e7%90%86%e8%a7%a3/#comments" thr:count="2" />
		<link rel="replies" type="application/atom+xml" href="http://fsfoundry.org/codefreak/2010/05/30/re-%e8%a7%a3%e8%af%bbgoogle-cpp-code-style%e8%b0%88%e5%af%b9cpp%e7%9a%84%e7%90%86%e8%a7%a3/feed/atom/" thr:count="2" />
		<thr:total>2</thr:total>
	<feedburner:origLink>http://fsfoundry.org/codefreak/2010/05/30/re-%e8%a7%a3%e8%af%bbgoogle-cpp-code-style%e8%b0%88%e5%af%b9cpp%e7%9a%84%e7%90%86%e8%a7%a3/</feedburner:origLink></entry>
		<entry>
		<author>
			<name>fr3@K</name>
						<uri>http://fsfoundry.org/codefreak/</uri>
					</author>
		<title type="html"><![CDATA[後方, 起浪了]]></title>
		<link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/codefreak/~3/TcJUlieUzZ8/" />
		<id>http://fsfoundry.org/codefreak/?p=929</id>
		<updated>2010-05-06T07:59:52Z</updated>
		<published>2010-05-04T15:54:53Z</published>
		<category scheme="http://fsfoundry.org/codefreak" term="~" /><category scheme="http://fsfoundry.org/codefreak" term="C++" /><category scheme="http://fsfoundry.org/codefreak" term="cited" /><category scheme="http://fsfoundry.org/codefreak" term="geeky" /><category scheme="http://fsfoundry.org/codefreak" term="mortal" /><category scheme="http://fsfoundry.org/codefreak" term="TM" />		<summary type="html"><![CDATA[後方的浪.
]]></summary>
		<content type="html" xml:base="http://fsfoundry.org/codefreak/2010/05/04/%e5%be%8c%e6%96%b9-%e8%b5%b7%e6%b5%aa%e4%ba%86/">&lt;p&gt;&lt;a href="http://keikoblog.blogspot.com/2010/05/reduce-nrv-to-rv.html"&gt;後方的浪&lt;/a&gt;.&lt;/p&gt;
&lt;br /&gt;&lt;a href="http://fsfoundry.org/codefreak/?p=929#comments" title="Comments on &amp;quot;後方, 起浪了&amp;quot;"&gt;&lt;img src="http://fsfoundry.org/codefreak/wp-content/plugins/feed-comments-number/image.php?929" alt="Comments" /&gt;&lt;/a&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/codefreak?a=TcJUlieUzZ8:eiSZgukM0KE:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/codefreak?i=TcJUlieUzZ8:eiSZgukM0KE:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</content>
		<link rel="replies" type="text/html" href="http://fsfoundry.org/codefreak/2010/05/04/%e5%be%8c%e6%96%b9-%e8%b5%b7%e6%b5%aa%e4%ba%86/#comments" thr:count="2" />
		<link rel="replies" type="application/atom+xml" href="http://fsfoundry.org/codefreak/2010/05/04/%e5%be%8c%e6%96%b9-%e8%b5%b7%e6%b5%aa%e4%ba%86/feed/atom/" thr:count="2" />
		<thr:total>2</thr:total>
	<feedburner:origLink>http://fsfoundry.org/codefreak/2010/05/04/%e5%be%8c%e6%96%b9-%e8%b5%b7%e6%b5%aa%e4%ba%86/</feedburner:origLink></entry>
		<entry>
		<author>
			<name>fr3@K</name>
						<uri>http://fsfoundry.org/codefreak/</uri>
					</author>
		<title type="html"><![CDATA[Pic of starryalley on iThome]]></title>
		<link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/codefreak/~3/-11k8EiZWlg/" />
		<id>http://fsfoundry.org/codefreak/?p=916</id>
		<updated>2010-03-23T16:35:57Z</updated>
		<published>2010-03-23T16:35:57Z</published>
		<category scheme="http://fsfoundry.org/codefreak" term="~" /><category scheme="http://fsfoundry.org/codefreak" term="TM" />		<summary type="html"><![CDATA[哈~ 同事 starryalley 的照片上了 iThome.
]]></summary>
		<content type="html" xml:base="http://fsfoundry.org/codefreak/2010/03/24/pic-of-starryalley-on-ithome/">&lt;p&gt;哈~ 同事 &lt;a href="http://starryalley.homelinux.net/blog/"&gt;starryalley&lt;/a&gt; 的照片上了 &lt;a href="http://www.ithome.com.tw/itadm/article.php?c=60147&amp;#038;s=2" rel="nofollow"&gt;iThome&lt;/a&gt;.&lt;/p&gt;
&lt;br /&gt;&lt;a href="http://fsfoundry.org/codefreak/?p=916#comments" title="Comments on &amp;quot;Pic of starryalley on iThome&amp;quot;"&gt;&lt;img src="http://fsfoundry.org/codefreak/wp-content/plugins/feed-comments-number/image.php?916" alt="Comments" /&gt;&lt;/a&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/codefreak?a=-11k8EiZWlg:d2Zlxgg8q24:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/codefreak?i=-11k8EiZWlg:d2Zlxgg8q24:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</content>
		<link rel="replies" type="text/html" href="http://fsfoundry.org/codefreak/2010/03/24/pic-of-starryalley-on-ithome/#comments" thr:count="2" />
		<link rel="replies" type="application/atom+xml" href="http://fsfoundry.org/codefreak/2010/03/24/pic-of-starryalley-on-ithome/feed/atom/" thr:count="2" />
		<thr:total>2</thr:total>
	<feedburner:origLink>http://fsfoundry.org/codefreak/2010/03/24/pic-of-starryalley-on-ithome/</feedburner:origLink></entry>
		<entry>
		<author>
			<name>fr3@K</name>
						<uri>http://fsfoundry.org/codefreak/</uri>
					</author>
		<title type="html"><![CDATA[Quiz on C++ Object Model]]></title>
		<link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/codefreak/~3/KgToVmlwrOY/" />
		<id>http://fsfoundry.org/codefreak/?p=878</id>
		<updated>2010-03-13T09:58:27Z</updated>
		<published>2010-03-03T16:07:05Z</published>
		<category scheme="http://fsfoundry.org/codefreak" term="~" /><category scheme="http://fsfoundry.org/codefreak" term="C++" /><category scheme="http://fsfoundry.org/codefreak" term="geeky" />		<summary type="html"><![CDATA[這幾個月忙於工作, 這個部落格都快被我給荒廢掉了. 昨晚終於花了時間完成了一篇積了一兩個月, 說明 virtual function 在執行時期的 override 過程以及 virtual function 與 constructor/destructor 混搭結果 的文字.
今天我準備了個題目給花了時間看了它的朋友, 當作對小弟的說明能力來個測驗. 請問, 下面的 code snip 的輸出結果是什麼?

PLAIN TEXT
C++:




#include &#60;typeinfo&#62;


#include &#60;iostream&#62;


&#160;


using namespace std;


&#160;


struct Base


&#123;


&#160; Base&#40;&#41;


&#160; &#123;


&#160; &#160; this-&#62;print_type_name&#40;&#41;;


&#160; &#125;


&#160; virtual void print_type_name&#40;&#41;


&#160; &#123;


&#160; &#160; cout &#60;&#60;typeid&#40;*this&#41;.name&#40;&#41; &#60;&#60;endl;


&#160; &#125;


&#125;;


struct Derived : Base


&#123;


&#125;;


&#160;


int main&#40;&#41;


&#123;


&#160; Derived d;


&#160; d.print_type_name&#40;&#41;;


&#160; return 0;


&#125; 






也就是說, 對同一個, 沒有被 override 過的 [...]]]></summary>
		<content type="html" xml:base="http://fsfoundry.org/codefreak/2010/03/04/quiz-on-cpp-object-model/">&lt;p&gt;這幾個月忙於工作, 這個部落格都快被我給荒廢掉了. 昨晚終於花了時間完成了一篇積了一兩個月, 說明 &lt;a href="http://fsfoundry.org/codefreak/2010/03/03/when-ctor-met-virtual-function/"&gt;virtual function 在執行時期的 override 過程以及 virtual function 與 constructor/destructor 混搭結果&lt;/a&gt; 的文字.&lt;/p&gt;
&lt;p&gt;今天我準備了個題目給花了時間看了它的朋友, 當作對小弟的說明能力來個測驗. 請問, 下面的 code snip 的輸出結果是什麼?&lt;br /&gt;
&lt;span id="more-878"&gt;&lt;/span&gt;&lt;/p&gt;
&lt;div class="igBar"&gt;&lt;span id="lcpp-10"&gt;&lt;a href="#" onclick="javascript:showPlainTxt('cpp-10'); return false;"&gt;PLAIN TEXT&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="syntax_hilite"&gt;&lt;span class="langName"&gt;C++:&lt;/span&gt;
&lt;div id="cpp-10"&gt;
&lt;div class="cpp"&gt;
&lt;ol&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #339900;"&gt;#include &amp;lt;typeinfo&amp;gt;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #339900;"&gt;#include &amp;lt;iostream&amp;gt;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #0000ff;"&gt;using&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;namespace&lt;/span&gt; std;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #0000ff;"&gt;struct&lt;/span&gt; Base&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #000000;"&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; Base&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #000000;"&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; this-&amp;gt;print_type_name&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #000000;"&gt;&amp;#125;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #0000ff;"&gt;virtual&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;void&lt;/span&gt; print_type_name&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #000000;"&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; &lt;span style="color: #0000dd;"&gt;cout&lt;/span&gt; &amp;lt;&amp;lt;typeid&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;*&lt;span style="color: #0000dd;"&gt;this&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;.&lt;span style="color: #00eeff;"&gt;name&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt; &amp;lt;&amp;lt;endl;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #000000;"&gt;&amp;#125;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #000000;"&gt;&amp;#125;&lt;/span&gt;;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #0000ff;"&gt;struct&lt;/span&gt; Derived : Base&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #000000;"&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #000000;"&gt;&amp;#125;&lt;/span&gt;;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #0000ff;"&gt;int&lt;/span&gt; main&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #000000;"&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; Derived d;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; d.&lt;span style="color: #00eeff;"&gt;print_type_name&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #0000ff;"&gt;return&lt;/span&gt; &lt;span style="color: #0000dd;color:#800000;"&gt;0&lt;/span&gt;;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #000000;"&gt;&amp;#125;&lt;/span&gt; &lt;/div&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;也就是說, 對同一個, 沒有被 override 過的 virtual function - &lt;code&gt;Base::print_type_name&lt;/code&gt; - 呼叫兩次 (第一次是透過 &lt;code&gt;Base&lt;/code&gt; 的 ctor 間接呼叫, 第二次則是當 &lt;code&gt;Derived&lt;/code&gt; 的 object instance 直接呼叫) 的輸出是什麼? And why?&lt;/p&gt;
&lt;p&gt;有些事情, &lt;a href="http://fsfoundry.org/codefreak/2008/10/13/foss-contrib-for-what/"&gt;可以是做爽的&lt;/a&gt;. 而這些文字除了幫助降低自己 (主要是在工作上) 對相同主題重複一再說明的負擔, 它們還蘊藏著我的理想性 - 我衷心期望它們能夠對華文技術圈有所助益. 也希望我的說明能力不要太差, 讓這些文字淪落到寫爽的.&lt;/p&gt;
&lt;p&gt;Hope you have fun while figuring out the quiz.&lt;/p&gt;
&lt;br /&gt;&lt;a href="http://fsfoundry.org/codefreak/?p=878#comments" title="Comments on &amp;quot;Quiz on C++ Object Model&amp;quot;"&gt;&lt;img src="http://fsfoundry.org/codefreak/wp-content/plugins/feed-comments-number/image.php?878" alt="Comments" /&gt;&lt;/a&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/codefreak?a=KgToVmlwrOY:SKHrbhE3mi0:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/codefreak?i=KgToVmlwrOY:SKHrbhE3mi0:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</content>
		<link rel="replies" type="text/html" href="http://fsfoundry.org/codefreak/2010/03/04/quiz-on-cpp-object-model/#comments" thr:count="1" />
		<link rel="replies" type="application/atom+xml" href="http://fsfoundry.org/codefreak/2010/03/04/quiz-on-cpp-object-model/feed/atom/" thr:count="1" />
		<thr:total>1</thr:total>
	<feedburner:origLink>http://fsfoundry.org/codefreak/2010/03/04/quiz-on-cpp-object-model/</feedburner:origLink></entry>
		<entry>
		<author>
			<name>fr3@K</name>
						<uri>http://fsfoundry.org/codefreak/</uri>
					</author>
		<title type="html"><![CDATA[當 Constructor 遇上 Virtual Function]]></title>
		<link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/codefreak/~3/RjKaB693FaY/" />
		<id>http://fsfoundry.org/codefreak/?p=789</id>
		<updated>2010-03-03T02:24:45Z</updated>
		<published>2010-03-02T16:19:33Z</published>
		<category scheme="http://fsfoundry.org/codefreak" term="~" /><category scheme="http://fsfoundry.org/codefreak" term="C++" /><category scheme="http://fsfoundry.org/codefreak" term="geeky" />		<summary type="html"><![CDATA[Background
不知道你有沒有過這樣的經驗 - 想要在父類的 constructor 裏面呼叫被子類 override (或是 implement) 的 (pure) virtual function?

PLAIN TEXT
C++:




struct Base


&#123;


&#160; Base&#40;&#41;


&#160; &#160;: x&#40;0&#41;


&#160; &#123;


&#160; &#160; on_create&#40;&#41;;


&#160; &#125;


&#160; virtual void on_create&#40;&#41; &#123;&#125;


&#160; int x;


&#125;;


struct Derived : Base


&#123;


&#160; Derived&#40;&#41;


&#160; &#160;: y&#40;1&#41; &#123;&#125;


&#160; void on_create&#40;&#41;


&#160; &#123;


&#160; &#160; // do Derived specific things


&#160; &#125;


&#160; int y;


&#125;;


&#160;


void foo&#40;&#41;


&#123;


&#160; Derived d;


&#125; 






我試過. 跟我一樣這樣玩過的朋友, 很快就會學到它不會如你所期望的那樣運作. 如果你的期望是當建構 Derived 的 [...]]]></summary>
		<content type="html" xml:base="http://fsfoundry.org/codefreak/2010/03/03/when-ctor-met-virtual-function/">&lt;h3&gt;Background&lt;/h3&gt;
&lt;p&gt;不知道你有沒有過這樣的經驗 - 想要在父類的 constructor 裏面呼叫被子類 override (或是 implement) 的 (pure) virtual function?&lt;br /&gt;
&lt;span id="more-789"&gt;&lt;/span&gt;&lt;/p&gt;
&lt;div class="igBar"&gt;&lt;span id="lcpp-12"&gt;&lt;a href="#" onclick="javascript:showPlainTxt('cpp-12'); return false;"&gt;PLAIN TEXT&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="syntax_hilite"&gt;&lt;span class="langName"&gt;C++:&lt;/span&gt;
&lt;div id="cpp-12"&gt;
&lt;div class="cpp"&gt;
&lt;ol&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #0000ff;"&gt;struct&lt;/span&gt; Base&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #000000;"&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; Base&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp;: x&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #0000dd;color:#800000;"&gt;0&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #000000;"&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; on_create&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #000000;"&gt;&amp;#125;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #0000ff;"&gt;virtual&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;void&lt;/span&gt; on_create&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt; &lt;span style="color: #000000;"&gt;&amp;#123;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#125;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #0000ff;"&gt;int&lt;/span&gt; x;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #000000;"&gt;&amp;#125;&lt;/span&gt;;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #0000ff;"&gt;struct&lt;/span&gt; Derived : Base&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #000000;"&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; Derived&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp;: y&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #0000dd;color:#800000;"&gt;1&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt; &lt;span style="color: #000000;"&gt;&amp;#123;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#125;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #0000ff;"&gt;void&lt;/span&gt; on_create&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #000000;"&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; &lt;span style="color: #ff0000;"&gt;// do Derived specific things&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #000000;"&gt;&amp;#125;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #0000ff;"&gt;int&lt;/span&gt; y;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #000000;"&gt;&amp;#125;&lt;/span&gt;;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #0000ff;"&gt;void&lt;/span&gt; foo&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #000000;"&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; Derived d;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #000000;"&gt;&amp;#125;&lt;/span&gt; &lt;/div&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;我試過. 跟我一樣這樣玩過的朋友, 很快就會學到它不會如你所期望的那樣運作. 如果你的期望是當建構 &lt;code&gt;Derived&lt;/code&gt; 的 object instance 時, &lt;code&gt;Derived::on_create&lt;/code&gt; 會被呼叫. 要是 &lt;code&gt;Base::on_create&lt;/code&gt; 宣告成 pure virtual 的話, 你更會發現它甚至 &lt;a href="http://blog.roodo.com/thinkingmore/archives/11206865.html"&gt;不能 compile&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;這樣的結果或許不是那麼直覺, 但背後的原因卻非常簡單 - virtual function 的 override 是發生在 object instance 被建構的時候.&lt;/p&gt;
&lt;ul&gt;
&lt;ul&gt;
&lt;strong&gt;=== mini tutorial ===&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Class &lt;code&gt;Derived&lt;/code&gt; 的 object layout 長得像下面這樣 (&lt;code&gt;p&lt;/code&gt; 為指向一 &lt;code&gt;Derived&lt;/code&gt; 的 object 的指標):&lt;/p&gt;
&lt;pre&gt;
       +---------+      +-----------------------------+
p-----&gt;|   vptr  |-----&gt;| ptr to typeinfo for Derived |
       +---------+      +-----------------------------+
       |    x    |      |      Derived::on_create     |
       +---------+      +-----------------------------+
       |    y    |
       +---------+
&lt;/pre&gt;
&lt;p&gt;由於擁有 virtual function 的原因, &lt;code&gt;Derived&lt;/code&gt; 的 object instance 在記憶體中會有一個指向其 vtable (virtual table) 的 vptr (virtual pointer).&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;=== end mini tutorial ===&lt;/strong&gt;
&lt;/ul&gt;
&lt;/ul&gt;
&lt;h3&gt;Behind the Scenes&lt;/h3&gt;
&lt;p&gt;打開你的 &lt;a href="http://www.amazon.com/Inside-Object-Model-Stanley-Lippman/dp/0201834545"&gt;Inside the C++ Object Model&lt;/a&gt; 複習一下. 當我們在程式中建構一個 &lt;code&gt;Derived&lt;/code&gt; 的 object instance 時, 先被建構的是其父類 - 也就是 class &lt;code&gt;Base&lt;/code&gt; 的部份 - 而後, 才會建構屬於 class &lt;code&gt;Derived&lt;/code&gt; 的部份. 這過程可約略分為幾個階段:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;準備 &lt;code&gt;Base&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;起始 &lt;code&gt;Base&lt;/code&gt; 的 member, 也就是 &lt;code&gt;Base::x&lt;/code&gt;
&lt;li&gt;呼叫 &lt;code&gt;Base&lt;/code&gt; 的 constructor&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Base&lt;/code&gt; 部份建構完成&lt;/li&gt;
&lt;li&gt;準備 &lt;code&gt;Derived&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;起始 &lt;code&gt;Derived&lt;/code&gt; 的 member, 也就是 &lt;code&gt;Derived::y&lt;/code&gt;
&lt;li&gt;呼叫 &lt;code&gt;Derived&lt;/code&gt; 的 constructor&lt;/li&gt;
&lt;li&gt;&lt;code&gt;Derived&lt;/code&gt; 完整建構&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;許多人可能不曉得 object 的建構還有上述階段一與階段五的 "準備" 工作. 這裡說的準備, 說穿了其實就是設定 object 的 vptr! 也就是說一直到程式完成步驟五之前, 這個 object 的 vptr 指向的是屬於 class &lt;code&gt;Base&lt;/code&gt; 的 vtable:&lt;/p&gt;
&lt;pre&gt;
       +---------+      +-----------------------------+
p-----&gt;|   vptr  |-----&gt;|   ptr to typeinfo for Base  |
       +---------+      +-----------------------------+
       |    x    |      |        Base::on_create      |
       +---------+      +-----------------------------+
       |    y    |
       +---------+
&lt;/pre&gt;
&lt;p&gt;完成了步驟五, 這個 object 的 vptr 才會改而指向 class &lt;code&gt;Derived&lt;/code&gt; 的 vtable. &lt;code&gt;Derived::on_create&lt;/code&gt; 正是在這個時候 override 了 &lt;code&gt;Base::on_create&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;
       +---------+      +-----------------------------+
p-----&gt;|   vptr  |--+   |   ptr to typeinfo for Base  |
       +---------+  |   +-----------------------------+
       |    x    |  |   |        Base::on_create      |
       +---------+  |   +-----------------------------+
       |    y    |  |
       +---------+  |   +-----------------------------+
                    +--&gt;| ptr to typeinfo for Derived |
                        +-----------------------------+
                        |      Derived::on_create     |
                        +-----------------------------+
&lt;/pre&gt;
&lt;p&gt;因此, 在例中 &lt;code&gt;Base&lt;/code&gt; 的 constructor (也就是表中的步驟三) 參考到的 &lt;code&gt;on_create&lt;/code&gt; 不會是被 &lt;code&gt;Derived&lt;/code&gt; override 的版本.&lt;/p&gt;
&lt;h3&gt;With a Little Twist&lt;/h3&gt;
&lt;p&gt;前面提到如果 &lt;code&gt;Base::on_create&lt;/code&gt; 被宣告成 pure virtual, 任何嘗試建構 &lt;code&gt;Derived&lt;/code&gt; 的程式將不能成功編譯.&lt;/p&gt;
&lt;p&gt;因為在這情況下, (假裝這樣的程式可以 compile 並運行) 在開始步驟三時 object 的 layout 會是像這樣:&lt;/p&gt;
&lt;pre&gt;
       +---------+      +-----------------------------+
p-----&gt;|   vptr  |-----&gt;|   ptr to typeinfo for Base  |
       +---------+      +-----------------------------+
       |    x    |      |    &amp;lt;pure virtual marker&amp;gt;    |
       +---------+      +-----------------------------+
       |    y    |
       +---------+
&lt;/pre&gt;
&lt;p&gt;Compiler 會在 class &lt;code&gt;Base&lt;/code&gt; 的 vtable 內, 原本紀錄著 &lt;code&gt;Base::on_create&lt;/code&gt; 的欄位標上一個特殊的 marker 以表示該 virtual function 為 pure virtual. 既然 pure virtual function 是不能被使用者以有意義的方式參考, 間接呼叫了 pure virtual function 的 &lt;code&gt;Derived&lt;/code&gt; 的 constructor (&lt;code&gt;Derived&lt;/code&gt; ctor -&gt; &lt;code&gt;Base&lt;/code&gt; ctor -&gt; pure virtual) 當然也是無效的.&lt;/p&gt;
&lt;h3&gt;What About Destructors&lt;/h3&gt;
&lt;p&gt;在 destructor 內呼叫 (pure) virtual function 也有完全一樣的問題. 只要把文中 object 建構的步驟反過來就可以理解其中的原因.&lt;/p&gt;
&lt;p&gt;Good night.&lt;/p&gt;
&lt;br /&gt;&lt;a href="http://fsfoundry.org/codefreak/?p=789#comments" title="Comments on &amp;quot;當 Constructor 遇上 Virtual Function&amp;quot;"&gt;&lt;img src="http://fsfoundry.org/codefreak/wp-content/plugins/feed-comments-number/image.php?789" alt="Comments" /&gt;&lt;/a&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/codefreak?a=RjKaB693FaY:htI2MLHYCkU:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/codefreak?i=RjKaB693FaY:htI2MLHYCkU:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</content>
		<link rel="replies" type="text/html" href="http://fsfoundry.org/codefreak/2010/03/03/when-ctor-met-virtual-function/#comments" thr:count="4" />
		<link rel="replies" type="application/atom+xml" href="http://fsfoundry.org/codefreak/2010/03/03/when-ctor-met-virtual-function/feed/atom/" thr:count="4" />
		<thr:total>4</thr:total>
	<feedburner:origLink>http://fsfoundry.org/codefreak/2010/03/03/when-ctor-met-virtual-function/</feedburner:origLink></entry>
		<entry>
		<author>
			<name>fr3@K</name>
						<uri>http://fsfoundry.org/codefreak/</uri>
					</author>
		<title type="html"><![CDATA[[Update] boost::decay documentation issue]]></title>
		<link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/codefreak/~3/OYHm3sBFAvU/" />
		<id>http://fsfoundry.org/codefreak/?p=797</id>
		<updated>2010-01-14T09:38:35Z</updated>
		<published>2010-01-14T09:35:01Z</published>
		<category scheme="http://fsfoundry.org/codefreak" term="~" /><category scheme="http://fsfoundry.org/codefreak" term="boost" /><category scheme="http://fsfoundry.org/codefreak" term="C++" /><category scheme="http://fsfoundry.org/codefreak" term="cited" /><category scheme="http://fsfoundry.org/codefreak" term="english" /><category scheme="http://fsfoundry.org/codefreak" term="geeky" />		<summary type="html"><![CDATA[The issue with boost::decay documentation that I blogged about 10 days ago has been fixed in trunk.
]]></summary>
		<content type="html" xml:base="http://fsfoundry.org/codefreak/2010/01/14/update-boost-decay-documentation-issue/">&lt;p&gt;The &lt;a href="https://svn.boost.org/trac/boost/ticket/3704"&gt;issue&lt;/a&gt; with &lt;a href="http://www.boost.org/doc/libs/1_41_0/libs/type_traits/doc/html/boost_typetraits/reference/decay.html"&gt;boost::decay documentation&lt;/a&gt; that I &lt;a href="http://fsfoundry.org/codefreak/2010/01/04/boost-decay/"&gt;blogged&lt;/a&gt; about 10 days ago has been &lt;a href="https://svn.boost.org/trac/boost/changeset/58901"&gt;fixed in trunk&lt;/a&gt;.&lt;/p&gt;
&lt;br /&gt;&lt;a href="http://fsfoundry.org/codefreak/?p=797#comments" title="Comments on &amp;quot;[Update] boost::decay documentation issue&amp;quot;"&gt;&lt;img src="http://fsfoundry.org/codefreak/wp-content/plugins/feed-comments-number/image.php?797" alt="Comments" /&gt;&lt;/a&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/codefreak?a=OYHm3sBFAvU:d2je5hg-PIg:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/codefreak?i=OYHm3sBFAvU:d2je5hg-PIg:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</content>
		<link rel="replies" type="text/html" href="http://fsfoundry.org/codefreak/2010/01/14/update-boost-decay-documentation-issue/#comments" thr:count="0" />
		<link rel="replies" type="application/atom+xml" href="http://fsfoundry.org/codefreak/2010/01/14/update-boost-decay-documentation-issue/feed/atom/" thr:count="0" />
		<thr:total>0</thr:total>
	<feedburner:origLink>http://fsfoundry.org/codefreak/2010/01/14/update-boost-decay-documentation-issue/</feedburner:origLink></entry>
		<entry>
		<author>
			<name>fr3@K</name>
						<uri>http://fsfoundry.org/codefreak/</uri>
					</author>
		<title type="html"><![CDATA[What Should We Teach New Software Developers? Why?]]></title>
		<link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/codefreak/~3/B65c6g6vT14/" />
		<id>http://fsfoundry.org/codefreak/?p=791</id>
		<updated>2010-01-04T16:34:23Z</updated>
		<published>2010-01-04T16:29:27Z</published>
		<category scheme="http://fsfoundry.org/codefreak" term="~" /><category scheme="http://fsfoundry.org/codefreak" term="cited" /><category scheme="http://fsfoundry.org/codefreak" term="geeky" />		<summary type="html"><![CDATA[Would you trust someone who had not seen a patient for years to teach surgery? What would you think of a piano teacher who never touched the keyboard? A CS education must bring a student beyond the necessary book learning to a mastery of its application in complete systems and an appreciation of aesthetics in [...]]]></summary>
		<content type="html" xml:base="http://fsfoundry.org/codefreak/2010/01/05/what-should-we-teach-new-software-developers-why/">&lt;blockquote&gt;&lt;p&gt;Would you trust someone who had not seen a patient for years to teach surgery? What would you think of a piano teacher who never touched the keyboard? A CS education must bring a student beyond the necessary book learning to a mastery of its application in complete systems and an appreciation of aesthetics in code.&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;這句話說得真好.&lt;/p&gt;
&lt;p&gt;via: &lt;a href="http://cacm.acm.org/magazines/2010/1/55760-what-should-we-teach-new-software-developers-why/fulltext"&gt;What Should We Teach New Software Developers? Why?&lt;/a&gt; - &lt;a href="http://www2.research.att.com/~bs/"&gt;Bjarne Stroustrup&lt;/a&gt;.&lt;/p&gt;
&lt;br /&gt;&lt;a href="http://fsfoundry.org/codefreak/?p=791#comments" title="Comments on &amp;quot;What Should We Teach New Software Developers? Why?&amp;quot;"&gt;&lt;img src="http://fsfoundry.org/codefreak/wp-content/plugins/feed-comments-number/image.php?791" alt="Comments" /&gt;&lt;/a&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/codefreak?a=B65c6g6vT14:1jWGkV-s0gM:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/codefreak?i=B65c6g6vT14:1jWGkV-s0gM:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</content>
		<link rel="replies" type="text/html" href="http://fsfoundry.org/codefreak/2010/01/05/what-should-we-teach-new-software-developers-why/#comments" thr:count="2" />
		<link rel="replies" type="application/atom+xml" href="http://fsfoundry.org/codefreak/2010/01/05/what-should-we-teach-new-software-developers-why/feed/atom/" thr:count="2" />
		<thr:total>2</thr:total>
	<feedburner:origLink>http://fsfoundry.org/codefreak/2010/01/05/what-should-we-teach-new-software-developers-why/</feedburner:origLink></entry>
		<entry>
		<author>
			<name>fr3@K</name>
						<uri>http://fsfoundry.org/codefreak/</uri>
					</author>
		<title type="html"><![CDATA[boost::decay documentation issue]]></title>
		<link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/codefreak/~3/Ponr5s691Ys/" />
		<id>http://fsfoundry.org/codefreak/?p=716</id>
		<updated>2010-01-14T09:37:36Z</updated>
		<published>2010-01-04T12:48:21Z</published>
		<category scheme="http://fsfoundry.org/codefreak" term="~" /><category scheme="http://fsfoundry.org/codefreak" term="boost" /><category scheme="http://fsfoundry.org/codefreak" term="C++" /><category scheme="http://fsfoundry.org/codefreak" term="cited" /><category scheme="http://fsfoundry.org/codefreak" term="geeky" />		<summary type="html"><![CDATA[前陣子看了 Hubert 的 一個 boost::exception 的例子, 猛然注意到自己不確定 boost::decay 的作用.
去看了它的 文件, 才發現文件不盡然正確... 已 submit 了一個 ticket 給 Boost, 希望早日修正.
]]></summary>
		<content type="html" xml:base="http://fsfoundry.org/codefreak/2010/01/04/boost-decay/">&lt;p&gt;前陣子看了 Hubert 的 &lt;a href="http://blog.hubert.tw/2009/07/08/%E4%B8%80%E5%80%8B-boostexception-%E7%9A%84%E4%BE%8B%E5%AD%90/"&gt;一個 boost::exception 的例子&lt;/a&gt;, 猛然注意到自己不確定 boost::decay 的作用.&lt;/p&gt;
&lt;p&gt;去看了它的 &lt;a href="http://www.boost.org/doc/libs/1_41_0/libs/type_traits/doc/html/boost_typetraits/reference/decay.html"&gt;文件&lt;/a&gt;, 才發現文件不盡然正確... 已 submit 了一個 &lt;a href="https://svn.boost.org/trac/boost/ticket/3704"&gt;ticket&lt;/a&gt; 給 Boost, 希望早日修正.&lt;/p&gt;
&lt;br /&gt;&lt;a href="http://fsfoundry.org/codefreak/?p=716#comments" title="Comments on &amp;quot;boost::decay documentation issue&amp;quot;"&gt;&lt;img src="http://fsfoundry.org/codefreak/wp-content/plugins/feed-comments-number/image.php?716" alt="Comments" /&gt;&lt;/a&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/codefreak?a=Ponr5s691Ys:pHFMF5JEMuc:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/codefreak?i=Ponr5s691Ys:pHFMF5JEMuc:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</content>
		<link rel="replies" type="text/html" href="http://fsfoundry.org/codefreak/2010/01/04/boost-decay/#comments" thr:count="0" />
		<link rel="replies" type="application/atom+xml" href="http://fsfoundry.org/codefreak/2010/01/04/boost-decay/feed/atom/" thr:count="0" />
		<thr:total>0</thr:total>
	<feedburner:origLink>http://fsfoundry.org/codefreak/2010/01/04/boost-decay/</feedburner:origLink></entry>
		<entry>
		<author>
			<name>fr3@K</name>
						<uri>http://fsfoundry.org/codefreak/</uri>
					</author>
		<title type="html"><![CDATA[Bit-fu]]></title>
		<link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/codefreak/~3/3Ov6yR9UVpo/" />
		<id>http://fsfoundry.org/codefreak/?p=778</id>
		<updated>2010-01-03T13:32:52Z</updated>
		<published>2010-01-03T03:40:38Z</published>
		<category scheme="http://fsfoundry.org/codefreak" term="~" /><category scheme="http://fsfoundry.org/codefreak" term="C++" /><category scheme="http://fsfoundry.org/codefreak" term="cited" /><category scheme="http://fsfoundry.org/codefreak" term="english" /><category scheme="http://fsfoundry.org/codefreak" term="geeky" />		<summary type="html"><![CDATA[Did you know, for x is an integer, that -~x yields x + 1 and ~-x yields x - 1?
via: Advanced bit manipulation-fu.
]]></summary>
		<content type="html" xml:base="http://fsfoundry.org/codefreak/2010/01/03/bit-fu/">&lt;p&gt;Did you know, for &lt;code&gt;x&lt;/code&gt; is an integer, that &lt;code&gt;-~x&lt;/code&gt; yields &lt;code&gt;x + 1&lt;/code&gt; and &lt;code&gt;~-x&lt;/code&gt; yields &lt;code&gt;x - 1&lt;/code&gt;?&lt;/p&gt;
&lt;p&gt;via: &lt;a href="http://realtimecollisiondetection.net/blog/?p=78"&gt;Advanced bit manipulation-fu&lt;/a&gt;.&lt;/p&gt;
&lt;br /&gt;&lt;a href="http://fsfoundry.org/codefreak/?p=778#comments" title="Comments on &amp;quot;Bit-fu&amp;quot;"&gt;&lt;img src="http://fsfoundry.org/codefreak/wp-content/plugins/feed-comments-number/image.php?778" alt="Comments" /&gt;&lt;/a&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/codefreak?a=3Ov6yR9UVpo:is6a7E4euMc:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/codefreak?i=3Ov6yR9UVpo:is6a7E4euMc:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</content>
		<link rel="replies" type="text/html" href="http://fsfoundry.org/codefreak/2010/01/03/bit-fu/#comments" thr:count="0" />
		<link rel="replies" type="application/atom+xml" href="http://fsfoundry.org/codefreak/2010/01/03/bit-fu/feed/atom/" thr:count="0" />
		<thr:total>0</thr:total>
	<feedburner:origLink>http://fsfoundry.org/codefreak/2010/01/03/bit-fu/</feedburner:origLink></entry>
		<entry>
		<author>
			<name>fr3@K</name>
						<uri>http://fsfoundry.org/codefreak/</uri>
					</author>
		<title type="html"><![CDATA[2009 工作回顧]]></title>
		<link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/codefreak/~3/_8Y7nMI9K3o/" />
		<id>http://fsfoundry.org/codefreak/?p=727</id>
		<updated>2010-01-03T02:54:26Z</updated>
		<published>2010-01-02T10:35:57Z</published>
		<category scheme="http://fsfoundry.org/codefreak" term="~" /><category scheme="http://fsfoundry.org/codefreak" term="TM" />		<summary type="html"><![CDATA[加入現在服務的公司約 20 個月了, 當然不是 (也不可能會) 所有的事情都是令人開心的. Nevertheless, I am glad that I work here. IMHO, 如果要留在台灣認真搞 software R&#038;D 與 engineering, 這裡絕對是最好的環境之一.

在這不到兩年的時間待過兩個 team 擔任技術職 - Project Lead1, 總共只貢獻少得可憐的幾千 LOC 給我所屬的 team. 反觀上一個工作的職稱是 Senior Technical Manager2, 在被 interview 時長官就已經講明公司期待 manager 要寫最多的 code, 當然正式在上海上崗時的確也是如此. 前後兩個工作形成有趣的強烈對比.
20 個月只貢獻幾千行 code 的技術性工作是不是太無聊了 (還是太爽了) ? 一點也不. 比起寫 code, 我花了更多時間在 research, design, review 他人的 [...]]]></summary>
		<content type="html" xml:base="http://fsfoundry.org/codefreak/2010/01/02/work-retrospect-2009/">&lt;p&gt;加入現在服務的公司約 20 個月了, 當然不是 (&lt;a href="http://fsfoundry.org/codefreak/2006/04/28/good-job/"&gt;也不可能會&lt;/a&gt;) 所有的事情都是令人開心的. Nevertheless, I am glad that I work here. IMHO, 如果要留在台灣認真搞 software R&amp;#038;D 與 engineering, 這裡絕對是最好的環境之一.&lt;br /&gt;
&lt;span id="more-727"&gt;&lt;/span&gt;&lt;br /&gt;
在這不到兩年的時間待過兩個 team 擔任技術職 - Project Lead&lt;sup&gt;&lt;a href="#footnote-1-727" id="footnote-link-1-727" class="footnote-link footnote-identifier-link" title="名片上中文印的是主任工程師."&gt;1&lt;/a&gt;&lt;/sup&gt;, 總共只貢獻少得可憐的幾千 LOC 給我所屬的 team. 反觀上一個工作的職稱是 Senior Technical Manager&lt;sup&gt;&lt;a href="#footnote-2-727" id="footnote-link-2-727" class="footnote-link footnote-identifier-link" title="這還是內部職稱, 名片上印的可是更響亮的 business title.  "&gt;2&lt;/a&gt;&lt;/sup&gt;, 在被 interview 時長官就已經講明公司期待 manager 要寫最多的 code, 當然正式在上海上崗時的確也是如此. 前後兩個工作形成有趣的強烈對比.&lt;/p&gt;
&lt;p&gt;20 個月只貢獻幾千行 code 的技術性工作是不是太無聊了 (還是太爽了) ? 一點也不. 比起寫 code, 我花了更多時間在 research, design, review 他人的 design, 幫助別人 review 我的 design, code review, 與 QA co-work 以確保產出的品質, 到 release 後的 defect tracking... 等等.&lt;/p&gt;
&lt;p&gt;還記得在面試時 hiring manager 問我 - "你為什麼想加入這間公司?". 我回說 - "朋友告訴我這裡可能是台灣最認真做軟體的公司, 而我想見識這邊的 development process 與體驗這樣的企業文化." And I have to say, I've got what I came for.&lt;/p&gt;
&lt;hr/&gt;
&lt;p&gt;以下為廣告...&lt;/p&gt;
&lt;p&gt;We are hiring! 我們在找熱愛挑戰的 team player. 如果你需要個能發揮並被 appreciate 的舞台, 請參考 &lt;a href="http://fsfoundry.org/codefreak/2009/05/07/new-job-openings-at-work/"&gt;上次的廣告&lt;/a&gt;. 有興趣的朋友請與我連絡.&lt;/p&gt;
&lt;br /&gt;&lt;a href="http://fsfoundry.org/codefreak/?p=727#comments" title="Comments on &amp;quot;2009 工作回顧&amp;quot;"&gt;&lt;img src="http://fsfoundry.org/codefreak/wp-content/plugins/feed-comments-number/image.php?727" alt="Comments" /&gt;&lt;/a&gt;&lt;ol start="1" class="footnotes"&gt;&lt;li id="footnote-1-727" class="footnote"&gt;名片上中文印的是主任工程師. [&lt;a href="#footnote-link-1-727" class="footnote-link footnote-back-link"&gt;↩&lt;/a&gt;]&lt;/li&gt;&lt;li id="footnote-2-727" class="footnote"&gt;這還是內部職稱, 名片上印的可是更響亮的 business title. &lt;img src='http://fsfoundry.org/codefreak/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /&gt;  [&lt;a href="#footnote-link-2-727" class="footnote-link footnote-back-link"&gt;↩&lt;/a&gt;]&lt;/li&gt;&lt;/ol&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/codefreak?a=_8Y7nMI9K3o:I30uTtFbdMI:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/codefreak?i=_8Y7nMI9K3o:I30uTtFbdMI:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</content>
		<link rel="replies" type="text/html" href="http://fsfoundry.org/codefreak/2010/01/02/work-retrospect-2009/#comments" thr:count="0" />
		<link rel="replies" type="application/atom+xml" href="http://fsfoundry.org/codefreak/2010/01/02/work-retrospect-2009/feed/atom/" thr:count="0" />
		<thr:total>0</thr:total>
	<feedburner:origLink>http://fsfoundry.org/codefreak/2010/01/02/work-retrospect-2009/</feedburner:origLink></entry>
		<entry>
		<author>
			<name>fr3@K</name>
						<uri>http://fsfoundry.org/codefreak/</uri>
					</author>
		<title type="html"><![CDATA[Another Good Interview Question in C++]]></title>
		<link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/codefreak/~3/ThIH30ThP58/" />
		<id>http://fsfoundry.org/codefreak/?p=717</id>
		<updated>2010-01-02T11:46:10Z</updated>
		<published>2010-01-02T09:10:48Z</published>
		<category scheme="http://fsfoundry.org/codefreak" term="~" /><category scheme="http://fsfoundry.org/codefreak" term="C++" /><category scheme="http://fsfoundry.org/codefreak" term="cited" /><category scheme="http://fsfoundry.org/codefreak" term="geeky" />		<summary type="html"><![CDATA[elleryq  的 這篇 blog post 談到的 ctor (換成 dtor 也一樣) 呼叫 virtual function 狀況 (或說是 problem) 會是很好的 C++ programmer 面試題目. 可在口試時用以窺探 interviewee 對 C++ object model 的了解.

它比公司現行筆試的題目1 來得更有深度, 要答得好得清楚知道 vtable 與 vptr 的運作方式. 包含在 construction 與 destruction 時, vptr 的變化.
你知道在這 現象 背後, 到底發生了什麼事嗎?
base 與 derived 的建構/解構順序 [↩]]]></summary>
		<content type="html" xml:base="http://fsfoundry.org/codefreak/2010/01/02/another-good-interview-question-in-cpp/">&lt;p&gt;&lt;a href="http://blog.roodo.com/thinkingmore"&gt;elleryq &lt;/a&gt; 的 &lt;a href="http://blog.roodo.com/thinkingmore/archives/11206865.html"&gt;這篇&lt;/a&gt; blog post 談到的 ctor (換成 dtor 也一樣) 呼叫 virtual function 狀況 (或說是 problem) 會是很好的 C++ programmer 面試題目. 可在口試時用以窺探 interviewee 對 C++ object model 的了解.&lt;br /&gt;
&lt;span id="more-717"&gt;&lt;/span&gt;&lt;br /&gt;
它比公司現行筆試的題目&lt;sup&gt;&lt;a href="#footnote-1-717" id="footnote-link-1-717" class="footnote-link footnote-identifier-link" title="base 與 derived 的建構/解構順序"&gt;1&lt;/a&gt;&lt;/sup&gt; 來得更有深度, 要答得好得清楚知道 vtable 與 vptr 的運作方式. 包含在 construction 與 destruction 時, vptr 的變化.&lt;/p&gt;
&lt;p&gt;你知道在這 &lt;a href="http://blog.roodo.com/thinkingmore/archives/11206865.html"&gt;現象&lt;/a&gt; 背後, 到底發生了什麼事嗎?&lt;/p&gt;
&lt;br /&gt;&lt;a href="http://fsfoundry.org/codefreak/?p=717#comments" title="Comments on &amp;quot;Another Good Interview Question in C++&amp;quot;"&gt;&lt;img src="http://fsfoundry.org/codefreak/wp-content/plugins/feed-comments-number/image.php?717" alt="Comments" /&gt;&lt;/a&gt;&lt;ol start="1" class="footnotes"&gt;&lt;li id="footnote-1-717" class="footnote"&gt;base 與 derived 的建構/解構順序 [&lt;a href="#footnote-link-1-717" class="footnote-link footnote-back-link"&gt;↩&lt;/a&gt;]&lt;/li&gt;&lt;/ol&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/codefreak?a=ThIH30ThP58:kow-QopkBpA:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/codefreak?i=ThIH30ThP58:kow-QopkBpA:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</content>
		<link rel="replies" type="text/html" href="http://fsfoundry.org/codefreak/2010/01/02/another-good-interview-question-in-cpp/#comments" thr:count="0" />
		<link rel="replies" type="application/atom+xml" href="http://fsfoundry.org/codefreak/2010/01/02/another-good-interview-question-in-cpp/feed/atom/" thr:count="0" />
		<thr:total>0</thr:total>
	<feedburner:origLink>http://fsfoundry.org/codefreak/2010/01/02/another-good-interview-question-in-cpp/</feedburner:origLink></entry>
		<entry>
		<author>
			<name>fr3@K</name>
						<uri>http://fsfoundry.org/codefreak/</uri>
					</author>
		<title type="html"><![CDATA[一看就知道 &#8211; 不 Thread-Safe 的 API]]></title>
		<link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/codefreak/~3/_q6gPxsj-CY/" />
		<id>http://fsfoundry.org/codefreak/?p=700</id>
		<updated>2009-12-01T12:34:21Z</updated>
		<published>2009-12-01T05:37:54Z</published>
		<category scheme="http://fsfoundry.org/codefreak" term="~" /><category scheme="http://fsfoundry.org/codefreak" term="C++" /><category scheme="http://fsfoundry.org/codefreak" term="cited" /><category scheme="http://fsfoundry.org/codefreak" term="geeky" />		<summary type="html"><![CDATA[Very well put  
當你發現回傳的是一個 char *，又沒有要求你特別 free 他，你是不是就該猜測他是回傳 function 內部的一個 static buffer 了呢？
Via: 從 inet_ntoa 看 thread safe 的 API.
]]></summary>
		<content type="html" xml:base="http://fsfoundry.org/codefreak/2009/12/01/identifying-api-without-thread-safety/">&lt;p&gt;Very well put &lt;img src='http://fsfoundry.org/codefreak/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /&gt; &lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;當你發現回傳的是一個 char *，又沒有要求你特別 free 他，你是不是就該猜測他是回傳 function 內部的一個 static buffer 了呢？&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;Via: &lt;a href="http://blog.hubert.tw/2009/04/18/%E5%BE%9E-inet_ntoa-%E7%9C%8B-thread-safe-%E7%9A%84-api/"&gt;從 inet_ntoa 看 thread safe 的 API&lt;/a&gt;.&lt;/p&gt;
&lt;br /&gt;&lt;a href="http://fsfoundry.org/codefreak/?p=700#comments" title="Comments on &amp;quot;一看就知道 &amp;#8211; 不 Thread-Safe 的 API&amp;quot;"&gt;&lt;img src="http://fsfoundry.org/codefreak/wp-content/plugins/feed-comments-number/image.php?700" alt="Comments" /&gt;&lt;/a&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/codefreak?a=_q6gPxsj-CY:CUFH82kOfCw:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/codefreak?i=_q6gPxsj-CY:CUFH82kOfCw:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</content>
		<link rel="replies" type="text/html" href="http://fsfoundry.org/codefreak/2009/12/01/identifying-api-without-thread-safety/#comments" thr:count="3" />
		<link rel="replies" type="application/atom+xml" href="http://fsfoundry.org/codefreak/2009/12/01/identifying-api-without-thread-safety/feed/atom/" thr:count="3" />
		<thr:total>3</thr:total>
	<feedburner:origLink>http://fsfoundry.org/codefreak/2009/12/01/identifying-api-without-thread-safety/</feedburner:origLink></entry>
		<entry>
		<author>
			<name>fr3@K</name>
						<uri>http://fsfoundry.org/codefreak/</uri>
					</author>
		<title type="html"><![CDATA[What Happens When We Lie to the Compiler?]]></title>
		<link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/codefreak/~3/6di1S-zsrSY/" />
		<id>http://fsfoundry.org/codefreak/?p=677</id>
		<updated>2009-11-13T05:30:32Z</updated>
		<published>2009-11-13T04:57:05Z</published>
		<category scheme="http://fsfoundry.org/codefreak" term="~" /><category scheme="http://fsfoundry.org/codefreak" term="C++" /><category scheme="http://fsfoundry.org/codefreak" term="commentary" /><category scheme="http://fsfoundry.org/codefreak" term="geeky" />		<summary type="html"><![CDATA[When you lie to your compiler, don't be surprised to get results those differ from what you expect.
In this case, the coder promised his/her compiler the value of "value" won't be changed, as it was declared const.
Therefore our best friend (yes, the compiler) who trusted the coder, thought "hey, I could cache this value in [...]]]></summary>
		<content type="html" xml:base="http://fsfoundry.org/codefreak/2009/11/13/what-happens-when-we-lie-to-the-compiler/">&lt;p&gt;When you lie to your compiler, don't be surprised to get results those differ from what you expect.&lt;/p&gt;
&lt;p&gt;In &lt;a href="http://fourdollars.blogspot.com/2009/11/c-programming-call-by.html"&gt;this case&lt;/a&gt;, the coder promised his/her compiler the value of "value" won't be changed, as it was declared &lt;code&gt;const&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Therefore our best friend (yes, the compiler) who trusted the coder, thought "hey, I could cache this value in a register and not fetch it from RAM every time I reference it", i.e. optimization.&lt;/p&gt;
&lt;p&gt;If we change the code in the link slightly, so that function &lt;code&gt;funcC&lt;/code&gt; would print &lt;code&gt;*value&lt;/code&gt; before the assignment, one would see that the value of &lt;code&gt;*value&lt;/code&gt; had actually been modified by function &lt;code&gt;funcA&lt;/code&gt;. However, the modification was not visible in &lt;code&gt;main&lt;/code&gt;, because the compiler was lied to as the coder explicitly told it that there would be no modification to &lt;code&gt;value&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;In the body of function &lt;code&gt;funcC&lt;/code&gt;, though &lt;code&gt;value&lt;/code&gt; was declared as a pointer to &lt;code&gt;const&lt;/code&gt; instance, the compiler was smart enough to know it was lied to. There was a &lt;code&gt;const_cast&lt;/code&gt; and a assignment, therefore, the modification to &lt;code&gt;*value&lt;/code&gt; was reflected in the output.&lt;/p&gt;
&lt;br /&gt;&lt;a href="http://fsfoundry.org/codefreak/?p=677#comments" title="Comments on &amp;quot;What Happens When We Lie to the Compiler?&amp;quot;"&gt;&lt;img src="http://fsfoundry.org/codefreak/wp-content/plugins/feed-comments-number/image.php?677" alt="Comments" /&gt;&lt;/a&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/codefreak?a=6di1S-zsrSY:B1N_8ycx7jY:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/codefreak?i=6di1S-zsrSY:B1N_8ycx7jY:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</content>
		<link rel="replies" type="text/html" href="http://fsfoundry.org/codefreak/2009/11/13/what-happens-when-we-lie-to-the-compiler/#comments" thr:count="0" />
		<link rel="replies" type="application/atom+xml" href="http://fsfoundry.org/codefreak/2009/11/13/what-happens-when-we-lie-to-the-compiler/feed/atom/" thr:count="0" />
		<thr:total>0</thr:total>
	<feedburner:origLink>http://fsfoundry.org/codefreak/2009/11/13/what-happens-when-we-lie-to-the-compiler/</feedburner:origLink></entry>
		<entry>
		<author>
			<name>fr3@K</name>
						<uri>http://fsfoundry.org/codefreak/</uri>
					</author>
		<title type="html"><![CDATA[Texas Army Base Rampage]]></title>
		<link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/codefreak/~3/LHLsIbYAJxs/" />
		<id>http://fsfoundry.org/codefreak/?p=668</id>
		<updated>2009-11-05T23:15:17Z</updated>
		<published>2009-11-05T23:11:45Z</published>
		<category scheme="http://fsfoundry.org/codefreak" term="~" /><category scheme="http://fsfoundry.org/codefreak" term="gossip" /><category scheme="http://fsfoundry.org/codefreak" term="mortal" />		<summary type="html"><![CDATA[我的媽呀~~
在舊金山機場等回台北的飛機, 電視上不斷的播放著德州美軍基地內部發生槍擊的新聞.
CNN 目前的說法是: 連同兇手總共掛了 12 個人, 兇嫌是一名現役中校.
]]></summary>
		<content type="html" xml:base="http://fsfoundry.org/codefreak/2009/11/06/texas-army-base-rampage/">&lt;p&gt;我的媽呀~~&lt;/p&gt;
&lt;p&gt;在舊金山機場等回台北的飛機, 電視上不斷的播放著德州美軍基地內部發生&lt;a href="http://edition.cnn.com/2009/US/11/05/texas.fort.hood.shootings/index.html"&gt;槍擊&lt;/a&gt;的&lt;a href="http://www.google.com/hostednews/ap/article/ALeqM5ihGepAkECGoDagETVBMpPb3w7Y3gD9BPKKFG0" rel="lightbox"&gt;新聞&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;CNN 目前的說法是: 連同兇手總共掛了 12 個人, 兇嫌是一名現役中校.&lt;/p&gt;
&lt;br /&gt;&lt;a href="http://fsfoundry.org/codefreak/?p=668#comments" title="Comments on &amp;quot;Texas Army Base Rampage&amp;quot;"&gt;&lt;img src="http://fsfoundry.org/codefreak/wp-content/plugins/feed-comments-number/image.php?668" alt="Comments" /&gt;&lt;/a&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/codefreak?a=LHLsIbYAJxs:QMcOlKuXevY:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/codefreak?i=LHLsIbYAJxs:QMcOlKuXevY:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</content>
		<link rel="replies" type="text/html" href="http://fsfoundry.org/codefreak/2009/11/06/texas-army-base-rampage/#comments" thr:count="0" />
		<link rel="replies" type="application/atom+xml" href="http://fsfoundry.org/codefreak/2009/11/06/texas-army-base-rampage/feed/atom/" thr:count="0" />
		<thr:total>0</thr:total>
	<feedburner:origLink>http://fsfoundry.org/codefreak/2009/11/06/texas-army-base-rampage/</feedburner:origLink></entry>
		<entry>
		<author>
			<name>fr3@K</name>
						<uri>http://fsfoundry.org/codefreak/</uri>
					</author>
		<title type="html"><![CDATA[So, You Think C++ is Slower than C]]></title>
		<link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/codefreak/~3/GbOGEfnsLIk/" />
		<id>http://fsfoundry.org/codefreak/?p=631</id>
		<updated>2010-03-15T15:21:14Z</updated>
		<published>2009-11-05T18:01:40Z</published>
		<category scheme="http://fsfoundry.org/codefreak" term="~" /><category scheme="http://fsfoundry.org/codefreak" term="C++" /><category scheme="http://fsfoundry.org/codefreak" term="english" /><category scheme="http://fsfoundry.org/codefreak" term="geeky" /><category scheme="http://fsfoundry.org/codefreak" term="whining" />		<summary type="html"><![CDATA[It is true that C++ provides programming constructs those consume more CPU cycles than it would when done without higher level of abstractions. But, hey, that's the cost of abstractions, why pay when they are not needed?
Stop laying out your C++ design like Java. Avoid inheritance when possible. Don't make every member function and destructor [...]]]></summary>
		<content type="html" xml:base="http://fsfoundry.org/codefreak/2009/11/06/so-you-think-cpp-is-slower-than-c/">&lt;p&gt;It is true that C++ provides programming constructs those consume more CPU cycles than it would when done without higher level of abstractions. But, hey, that's the cost of abstractions, why pay when they are not needed?&lt;/p&gt;
&lt;p&gt;Stop laying out your C++ design &lt;a href="http://fsfoundry.org/codefreak/2009/03/03/caffeine-intoxication/"&gt;like Java&lt;/a&gt;. &lt;a href="http://fsfoundry.org/codefreak/2007/05/22/avoid-pointer-parameters-and-inheritance/#avoid-inheritance"&gt;Avoid inheritance&lt;/a&gt; when possible. Don't make every member function and destructor &lt;code&gt;virtual&lt;/code&gt; without really thinking. They not only increase your run time overhead, they boost the &lt;a href="http://fsfoundry.org/codefreak/2009/05/24/observer-done-differently/"&gt;complexity&lt;/a&gt; (read coupling) of your code like nothing else.&lt;/p&gt;
&lt;p&gt;C++ does every &lt;i&gt;C-style&lt;/i&gt; stuff the same way as C does. Not to mention it is capable of more compile time computation than C. I just fail to see how C++ could be slower than C in run time, seriously.&lt;/p&gt;
&lt;br /&gt;&lt;a href="http://fsfoundry.org/codefreak/?p=631#comments" title="Comments on &amp;quot;So, You Think C++ is Slower than C&amp;quot;"&gt;&lt;img src="http://fsfoundry.org/codefreak/wp-content/plugins/feed-comments-number/image.php?631" alt="Comments" /&gt;&lt;/a&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/codefreak?a=GbOGEfnsLIk:vgIqm2uznPk:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/codefreak?i=GbOGEfnsLIk:vgIqm2uznPk:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</content>
		<link rel="replies" type="text/html" href="http://fsfoundry.org/codefreak/2009/11/06/so-you-think-cpp-is-slower-than-c/#comments" thr:count="1" />
		<link rel="replies" type="application/atom+xml" href="http://fsfoundry.org/codefreak/2009/11/06/so-you-think-cpp-is-slower-than-c/feed/atom/" thr:count="1" />
		<thr:total>1</thr:total>
	<feedburner:origLink>http://fsfoundry.org/codefreak/2009/11/06/so-you-think-cpp-is-slower-than-c/</feedburner:origLink></entry>
		<entry>
		<author>
			<name>fr3@K</name>
						<uri>http://fsfoundry.org/codefreak/</uri>
					</author>
		<title type="html"><![CDATA[Boost.Lexical-Cast Alternatives]]></title>
		<link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/codefreak/~3/1e0q8vqIffg/" />
		<id>http://fsfoundry.org/codefreak/?p=544</id>
		<updated>2010-02-12T02:30:34Z</updated>
		<published>2009-09-17T13:49:00Z</published>
		<category scheme="http://fsfoundry.org/codefreak" term="~" /><category scheme="http://fsfoundry.org/codefreak" term="boost" /><category scheme="http://fsfoundry.org/codefreak" term="C++" /><category scheme="http://fsfoundry.org/codefreak" term="geeky" />		<summary type="html"><![CDATA[今天稍早, 跟一位同事聊到 Boost 的 lexical_cast. 打開了 Firefox 請出 Google, 想找到能幫助我介紹 lexical_cast 的資源. 意外地, Google 把我帶到讓我賺了介紹獎金, 現在跟我是同事的 Jeff, 談到 lexical_cast 的 文章.
在這篇文字的討論串, Jeff 寫道:
我覺得如果可以用這樣的寫法，那就太好了：
uint32_t ID = lexical_cast&#60;auto&#62;("1234567");
甚至最好是：
template &#60;class From, class To = auto&#62;
To lexical_cast(From s) {...}

uint32_t ID = lexical_cast("1234567");
Jeff Hung


小弟既然收了 Jeff 的好處, 當然得回報一下試著幫忙想想辦法:1
PLAIN TEXT
C++:




#include &#60;sstream&#62;


#include &#60;iostream&#62;


#include &#60;stdexcept&#62;


&#160;


class lexi_cast


&#123;


public:


&#160; template &#60;class Input&#62;


&#160; lexi_cast&#40;const Input&#38; in&#41;


&#160; &#123;


&#160; &#160; [...]]]></summary>
		<content type="html" xml:base="http://fsfoundry.org/codefreak/2009/09/17/boost-lexical-cast-alternatives/">&lt;p&gt;今天稍早, 跟一位同事聊到 Boost 的 &lt;a href="http://www.boost.org/doc/libs/1_40_0/libs/conversion/lexical_cast.htm"&gt;lexical_cast&lt;/a&gt;. 打開了 Firefox 請出 Google, 想找到能幫助我介紹 lexical_cast 的資源. 意外地, Google 把我帶到讓我賺了介紹獎金, 現在跟我是同事的 Jeff, 談到 lexical_cast 的 &lt;a href="http://www.jeffhung.net/blog/articles/jeffhung/1635/" rel="nofollow"&gt;文章&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;在這篇文字的討論串, &lt;a href="http://www.jeffhung.net/blog/articles/jeffhung/1635/#comment-133176" rel="nofollow"&gt;Jeff 寫道&lt;/a&gt;:&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;我覺得如果可以用這樣的寫法，那就太好了：&lt;/p&gt;
&lt;pre&gt;uint32_t ID = lexical_cast&amp;lt;auto&amp;gt;("1234567");&lt;/pre&gt;
&lt;p&gt;甚至最好是：&lt;/p&gt;
&lt;pre&gt;template &amp;lt;class From, class To = auto&amp;gt;
To lexical_cast(From s) {...}

uint32_t ID = lexical_cast("1234567");&lt;/pre&gt;
&lt;p&gt;Jeff Hung
&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;&lt;span id="more-544"&gt;&lt;/span&gt;&lt;br /&gt;
小弟既然收了 Jeff 的好處, 當然得回報一下試著幫忙想想辦法:&lt;sup&gt;&lt;a href="#footnote-1-544" id="footnote-link-1-544" class="footnote-link footnote-identifier-link" title="Sorry, Jeff. 明明是我自己愛玩卻還要遷拖到你."&gt;1&lt;/a&gt;&lt;/sup&gt;&lt;/p&gt;
&lt;div class="igBar"&gt;&lt;span id="lcpp-21"&gt;&lt;a href="#" onclick="javascript:showPlainTxt('cpp-21'); return false;"&gt;PLAIN TEXT&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="syntax_hilite"&gt;&lt;span class="langName"&gt;C++:&lt;/span&gt;
&lt;div id="cpp-21"&gt;
&lt;div class="cpp"&gt;
&lt;ol&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #339900;"&gt;#include &amp;lt;sstream&amp;gt;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #339900;"&gt;#include &amp;lt;iostream&amp;gt;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #339900;"&gt;#include &amp;lt;stdexcept&amp;gt;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #0000ff;"&gt;class&lt;/span&gt; lexi_cast&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #000000;"&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #0000ff;"&gt;public&lt;/span&gt;:&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #0000ff;"&gt;template&lt;/span&gt; &amp;lt;class Input&amp;gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; lexi_cast&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;const&lt;/span&gt; Input&amp;amp; in&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #000000;"&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; ss_ &amp;lt;&amp;lt;in;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; &lt;span style="color: #0000ff;"&gt;if&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;!ss_.&lt;span style="color: #00eeff;"&gt;good&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; throw std::&lt;span style="color: #00eeff;"&gt;runtime_error&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #666666;"&gt;"lexi_cast failed"&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #000000;"&gt;&amp;#125;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #0000ff;"&gt;template&lt;/span&gt; &amp;lt;class Output&amp;gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; operator Output&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #000000;"&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; Output out;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; ss_&amp;gt;&amp;gt; out;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; &lt;span style="color: #0000ff;"&gt;if&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;ss_.&lt;span style="color: #00eeff;"&gt;bad&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt; || ss_.&lt;span style="color: #00eeff;"&gt;fail&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; throw std::&lt;span style="color: #00eeff;"&gt;runtime_error&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #666666;"&gt;"lexi_cast failed"&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; &lt;span style="color: #0000ff;"&gt;return&lt;/span&gt; out;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #000000;"&gt;&amp;#125;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #0000ff;"&gt;private&lt;/span&gt;:&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; std::&lt;span style="color: #00eeff;"&gt;stringstream&lt;/span&gt; ss_;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #000000;"&gt;&amp;#125;&lt;/span&gt;;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #0000ff;"&gt;int&lt;/span&gt; main&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #000000;"&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #0000ff;"&gt;using&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;namespace&lt;/span&gt; std;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #ff0000;"&gt;// Converts C-style string to int.&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #0000ff;"&gt;int&lt;/span&gt; i = lexi_cast&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #666666;"&gt;"123"&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #0000dd;"&gt;cout&lt;/span&gt; &amp;lt;&amp;lt;i &amp;lt;&amp;lt;endl;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #ff0000;"&gt;// Converts int to std::string.&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; string s = lexi_cast&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;i&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #0000dd;"&gt;cout&lt;/span&gt; &amp;lt;&amp;lt;s &amp;lt;&amp;lt;endl;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #0000ff;"&gt;return&lt;/span&gt; &lt;span style="color: #0000dd;color:#800000;"&gt;0&lt;/span&gt;;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #000000;"&gt;&amp;#125;&lt;/span&gt; &lt;/div&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;/p&gt;
&lt;ul id="class-function-object-naming"&gt;&lt;em&gt;岔題一下.&lt;/p&gt;
&lt;p&gt;我一直不是很認同, 在 C++ 中, 以不同的規則來命名 class/function/object. 主要的原因是, 我認為這三者的分野其實並沒有那麼絕對.&lt;/p&gt;
&lt;p&gt;上面的 &lt;code&gt;lexi_cast&lt;/code&gt; 就是一個很好的例子. 雖然它與 "真正" 的 function 相較仍有細微的不同, 但它的確是設計來讓使用者以 "function 風格" 使用的. 硬是把它的名字取得跟其他 function 格格不入, 豈不是很礙眼? 一個 function-like 的 instance (function instance, class instance or object instance) 可以在一個版本是真的 function, 在下一個版本卻變成 functional object, 甚至是如例中的 class instance.&lt;/p&gt;
&lt;p&gt;從另一個方面來看, 如果一個 "正常" class 設計的讓人容易把該 class 本身或所 instantiate 的 object 錯誤地當作 function 使用, 而必須以命名原則來區分, 其設計者更是應該要好好反省.&lt;/em&gt;&lt;/ul&gt;
&lt;p&gt;看起來這似乎已滿足了 Jeff 的基本需求, 只是這全自動的轉換機制也有它的問題. 有些時候, 不提供更多資訊給 compiler, 就是會有 ambiguity. 例如 stream insertion:&lt;/p&gt;
&lt;div class="igBar"&gt;&lt;span id="lcpp-22"&gt;&lt;a href="#" onclick="javascript:showPlainTxt('cpp-22'); return false;"&gt;PLAIN TEXT&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="syntax_hilite"&gt;&lt;span class="langName"&gt;C++:&lt;/span&gt;
&lt;div id="cpp-22"&gt;
&lt;div class="cpp"&gt;
&lt;ol&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #ff0000;"&gt;// Ambigous! This won't compile!&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #0000dd;"&gt;cout&lt;/span&gt; &amp;lt;&amp;lt;lexi_cast&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;some_object&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;; &lt;/div&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Output stream 的 &lt;code&gt;operator&amp;lt;&amp;lt;&lt;/code&gt; 有 &lt;a href="http://www.dinkumware.com/manuals/?manual=compleat&amp;#038;page=ostream.html#operator%3C%3C" rel="nofollow"&gt;很多 overload&lt;/a&gt;. 由於 &lt;code&gt;lexi_cast&lt;/code&gt; 提供了 generic 的 conversion operator, 因此 compiler 會找到多個可行 (viable) 的 overload. 若我們不顯性提示, compiler 會無法決定到底該採用哪個 overload. 這時候, &lt;code&gt;lexi_cast&lt;/code&gt; 的全自動 (或說是缺乏手動指定的) 轉換功能反而變成了一種缺陷.&lt;/p&gt;
&lt;p&gt;Attempt number 2. 簡單的把 &lt;code&gt;lexi_cast&lt;/code&gt; 改成一個可以指定目的形別的 class template, 並配上做自動轉換的 default template parameter (struct &lt;code&gt;auto_deduce&lt;/code&gt;) 以及 specialization:&lt;/p&gt;
&lt;div class="igBar"&gt;&lt;span id="lcpp-23"&gt;&lt;a href="#" onclick="javascript:showPlainTxt('cpp-23'); return false;"&gt;PLAIN TEXT&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="syntax_hilite"&gt;&lt;span class="langName"&gt;C++:&lt;/span&gt;
&lt;div id="cpp-23"&gt;
&lt;div class="cpp"&gt;
&lt;ol&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #0000ff;"&gt;struct&lt;/span&gt; auto_deduce &lt;span style="color: #000000;"&gt;&amp;#123;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#125;&lt;/span&gt;;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #0000ff;"&gt;template&lt;/span&gt; &amp;lt;class Output = auto_deduce&amp;gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #0000ff;"&gt;class&lt;/span&gt; lexi_cast2&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #000000;"&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #0000ff;"&gt;public&lt;/span&gt;:&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #0000ff;"&gt;template&lt;/span&gt; &amp;lt;class Input&amp;gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; lexi_cast2&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;const&lt;/span&gt; Input&amp;amp; in&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #000000;"&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; ss_ &amp;lt;&amp;lt;in;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; &lt;span style="color: #0000ff;"&gt;if&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;!ss_.&lt;span style="color: #00eeff;"&gt;good&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; throw std::&lt;span style="color: #00eeff;"&gt;runtime_error&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #666666;"&gt;"lexi_cast2 failed"&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #000000;"&gt;&amp;#125;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; operator Output&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #000000;"&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; Output out;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; ss_&amp;gt;&amp;gt; out;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; &lt;span style="color: #0000ff;"&gt;if&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;ss_.&lt;span style="color: #00eeff;"&gt;bad&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt; || ss_.&lt;span style="color: #00eeff;"&gt;fail&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; throw std::&lt;span style="color: #00eeff;"&gt;runtime_error&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #666666;"&gt;"lexi_cast2 failed"&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; &lt;span style="color: #0000ff;"&gt;return&lt;/span&gt; out;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #000000;"&gt;&amp;#125;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #0000ff;"&gt;private&lt;/span&gt;:&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; std::&lt;span style="color: #00eeff;"&gt;stringstream&lt;/span&gt; ss_;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #000000;"&gt;&amp;#125;&lt;/span&gt;;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #0000ff;"&gt;template&lt;/span&gt; &amp;lt;&amp;gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #0000ff;"&gt;class&lt;/span&gt; lexi_cast2&amp;lt;&lt;span style="color: #ff0000; font-style: italic;"&gt;/*Output =*/&lt;/span&gt;auto_deduce&amp;gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #000000;"&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #0000ff;"&gt;public&lt;/span&gt;:&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #0000ff;"&gt;template&lt;/span&gt; &amp;lt;class Input&amp;gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; lexi_cast2&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;const&lt;/span&gt; Input&amp;amp; in&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #000000;"&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; ss_ &amp;lt;&amp;lt;in;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; &lt;span style="color: #0000ff;"&gt;if&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;!ss_.&lt;span style="color: #00eeff;"&gt;good&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; throw std::&lt;span style="color: #00eeff;"&gt;runtime_error&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #666666;"&gt;"lexi_cast2 failed"&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #000000;"&gt;&amp;#125;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #0000ff;"&gt;template&lt;/span&gt; &amp;lt;class Output&amp;gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; operator Output&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #000000;"&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; Output out;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; ss_&amp;gt;&amp;gt; out;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; &lt;span style="color: #0000ff;"&gt;if&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;ss_.&lt;span style="color: #00eeff;"&gt;bad&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt; || ss_.&lt;span style="color: #00eeff;"&gt;fail&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; throw std::&lt;span style="color: #00eeff;"&gt;runtime_error&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #666666;"&gt;"lexi_cast2 failed"&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; &lt;span style="color: #0000ff;"&gt;return&lt;/span&gt; out;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #000000;"&gt;&amp;#125;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #0000ff;"&gt;private&lt;/span&gt;:&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; std::&lt;span style="color: #00eeff;"&gt;stringstream&lt;/span&gt; ss_;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #000000;"&gt;&amp;#125;&lt;/span&gt;; &lt;/div&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;效果並不理想. 自動轉換 (default behavior of class template &lt;code&gt;lexi_cast2&lt;/code&gt;) 雖不需要指定 type, 但還是需要角括號 (angled bracket), 用起來醜到爆:&lt;/p&gt;
&lt;div class="igBar"&gt;&lt;span id="lcpp-24"&gt;&lt;a href="#" onclick="javascript:showPlainTxt('cpp-24'); return false;"&gt;PLAIN TEXT&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="syntax_hilite"&gt;&lt;span class="langName"&gt;C++:&lt;/span&gt;
&lt;div id="cpp-24"&gt;
&lt;div class="cpp"&gt;
&lt;ol&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #0000ff;"&gt;int&lt;/span&gt; main&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #000000;"&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #0000ff;"&gt;using&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;namespace&lt;/span&gt; std;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #ff0000;"&gt;// Note the next (commented) line won't compile,&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #ff0000;"&gt;// int i = lexi_cast2(&amp;quot;123&amp;quot;);&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #ff0000;"&gt;// Angled brackets needed for auto deduction.&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #ff0000;"&gt;// Not pretty at all.&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #0000ff;"&gt;int&lt;/span&gt; i = lexi_cast2&amp;lt;&amp;gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #666666;"&gt;"123"&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #0000dd;"&gt;cout&lt;/span&gt; &amp;lt;&amp;lt;i &amp;lt;&amp;lt;endl;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; string s = lexi_cast2&amp;lt;&amp;gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;i&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #0000dd;"&gt;cout&lt;/span&gt; &amp;lt;&amp;lt;s &amp;lt;&amp;lt;endl;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #ff0000;"&gt;// Now we could specify which &amp;quot;type&amp;quot; to convert to.&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #0000dd;"&gt;cout&lt;/span&gt; &amp;lt;&amp;lt;lexi_cast2&amp;lt;int&amp;gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;s&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt; &amp;lt;&amp;lt;endl;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #0000ff;"&gt;return&lt;/span&gt; &lt;span style="color: #0000dd;color:#800000;"&gt;0&lt;/span&gt;;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #000000;"&gt;&amp;#125;&lt;/span&gt; &lt;/div&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Attempt number 3. 下面的程式中的 class template &lt;code&gt;lexi_cast3_helper&lt;/code&gt; 與 specialization 是從前面的 &lt;code&gt;lexi_cast2&lt;/code&gt; 修改過來的. 只增加了 copy-ctor:&lt;sup&gt;&lt;a href="#footnote-2-544" id="footnote-link-2-544" class="footnote-link footnote-identifier-link" title="由於 IOStream 是不能 copy 的, 因此 lexi_cast3_helper 需要有 copy-ctor 才能 compile. 有趣的是, 因為 RVO 的關係, 這些 copy-ctor 根本沒有 run-time 的用處, 不會被執行到. 可以把它的內容 comment 掉, 甚至亂改, 只要能 compile &amp;amp; link, 仍舊會正常運作."&gt;2&lt;/a&gt;&lt;/sup&gt;&lt;/p&gt;
&lt;div class="igBar"&gt;&lt;span id="lcpp-25"&gt;&lt;a href="#" onclick="javascript:showPlainTxt('cpp-25'); return false;"&gt;PLAIN TEXT&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="syntax_hilite"&gt;&lt;span class="langName"&gt;C++:&lt;/span&gt;
&lt;div id="cpp-25"&gt;
&lt;div class="cpp"&gt;
&lt;ol&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #0000ff;"&gt;template&lt;/span&gt; &amp;lt;class Output&amp;gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #0000ff;"&gt;class&lt;/span&gt; lexi_cast3_helper&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #000000;"&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #0000ff;"&gt;public&lt;/span&gt;:&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #0000ff;"&gt;template&lt;/span&gt; &amp;lt;class Input&amp;gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; lexi_cast3_helper&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;const&lt;/span&gt; Input&amp;amp; in&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #000000;"&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; ss_ &amp;lt;&amp;lt;in;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; &lt;span style="color: #0000ff;"&gt;if&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;!ss_.&lt;span style="color: #00eeff;"&gt;good&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; throw std::&lt;span style="color: #00eeff;"&gt;runtime_error&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #666666;"&gt;"lexi_cast3 failed"&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #000000;"&gt;&amp;#125;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #ff0000;"&gt;// Copy-ctor. Needed for compilation, but not&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #ff0000;"&gt;// invoked at run-time.&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; lexi_cast3_helper&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;const&lt;/span&gt; lexi_cast3_helper&amp;amp; other&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #000000;"&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; ss_ &amp;lt;&amp;lt;other.&lt;span style="color: #00eeff;"&gt;ss_&lt;/span&gt;.&lt;span style="color: #00eeff;"&gt;str&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #000000;"&gt;&amp;#125;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; operator Output&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #000000;"&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; Output out;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; ss_&amp;gt;&amp;gt; out;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; &lt;span style="color: #0000ff;"&gt;if&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;ss_.&lt;span style="color: #00eeff;"&gt;bad&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt; || ss_.&lt;span style="color: #00eeff;"&gt;fail&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; throw std::&lt;span style="color: #00eeff;"&gt;runtime_error&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #666666;"&gt;"lexi_cast3 failed"&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; &lt;span style="color: #0000ff;"&gt;return&lt;/span&gt; out;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #000000;"&gt;&amp;#125;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #0000ff;"&gt;private&lt;/span&gt;:&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; std::&lt;span style="color: #00eeff;"&gt;stringstream&lt;/span&gt; ss_;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #000000;"&gt;&amp;#125;&lt;/span&gt;;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #0000ff;"&gt;template&lt;/span&gt; &amp;lt;&amp;gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #0000ff;"&gt;class&lt;/span&gt; lexi_cast3_helper&amp;lt;&lt;span style="color: #ff0000; font-style: italic;"&gt;/*Output =*/&lt;/span&gt;auto_deduce&amp;gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #000000;"&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #0000ff;"&gt;public&lt;/span&gt;:&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #0000ff;"&gt;template&lt;/span&gt; &amp;lt;class Input&amp;gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; lexi_cast3_helper&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;const&lt;/span&gt; Input&amp;amp; in&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #000000;"&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; ss_ &amp;lt;&amp;lt;in;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; &lt;span style="color: #0000ff;"&gt;if&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;!ss_.&lt;span style="color: #00eeff;"&gt;good&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; throw std::&lt;span style="color: #00eeff;"&gt;runtime_error&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #666666;"&gt;"lexi_cast3 failed"&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #000000;"&gt;&amp;#125;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #ff0000;"&gt;// Copy-ctor. Needed for compilation, but not&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #ff0000;"&gt;// invoked at run-time.&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; lexi_cast3_helper&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;const&lt;/span&gt; lexi_cast3_helper&amp;amp; other&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #000000;"&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; ss_ &amp;lt;&amp;lt;other.&lt;span style="color: #00eeff;"&gt;ss_&lt;/span&gt;.&lt;span style="color: #00eeff;"&gt;str&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #000000;"&gt;&amp;#125;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #0000ff;"&gt;template&lt;/span&gt; &amp;lt;class Output&amp;gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; operator Output&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #000000;"&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; Output out;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; ss_&amp;gt;&amp;gt; out;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; &lt;span style="color: #0000ff;"&gt;if&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;ss_.&lt;span style="color: #00eeff;"&gt;bad&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt; || ss_.&lt;span style="color: #00eeff;"&gt;fail&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; throw std::&lt;span style="color: #00eeff;"&gt;runtime_error&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #666666;"&gt;"lexi_cast3 failed"&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; &lt;span style="color: #0000ff;"&gt;return&lt;/span&gt; out;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #000000;"&gt;&amp;#125;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #0000ff;"&gt;private&lt;/span&gt;:&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; std::&lt;span style="color: #00eeff;"&gt;stringstream&lt;/span&gt; ss_;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #000000;"&gt;&amp;#125;&lt;/span&gt;; &lt;/div&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;把 &lt;code&gt;lexi_cast3_helper&lt;/code&gt; 搭配上兩個 function template - 兩個 &lt;code&gt;lexi_cast3&lt;/code&gt; 的 overload. 一個用來在自動轉換時躲避角括號 (angled bracket), 另一個讓使用者自行指定轉換的目的形別:&lt;/p&gt;
&lt;div class="igBar"&gt;&lt;span id="lcpp-26"&gt;&lt;a href="#" onclick="javascript:showPlainTxt('cpp-26'); return false;"&gt;PLAIN TEXT&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="syntax_hilite"&gt;&lt;span class="langName"&gt;C++:&lt;/span&gt;
&lt;div id="cpp-26"&gt;
&lt;div class="cpp"&gt;
&lt;ol&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #ff0000;"&gt;// Overload for output type auto deduction.&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #0000ff;"&gt;template&lt;/span&gt; &amp;lt;class Input&amp;gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;lexi_cast3_helper&amp;lt;auto_deduce&amp;gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; lexi_cast3&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;const&lt;/span&gt; Input&amp;amp; in&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #000000;"&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #0000ff;"&gt;return&lt;/span&gt; lexi_cast3_helper&amp;lt;auto_deduce&amp;gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;in&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #000000;"&gt;&amp;#125;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #ff0000;"&gt;// Overload for user-specified output type.&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #0000ff;"&gt;template&lt;/span&gt; &amp;lt;class Output, &lt;span style="color: #0000ff;"&gt;class&lt;/span&gt; Input&amp;gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;lexi_cast3_helper&amp;lt;Output&amp;gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; lexi_cast3&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;const&lt;/span&gt; Input&amp;amp; in&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #000000;"&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #0000ff;"&gt;return&lt;/span&gt; lexi_cast3_helper&amp;lt;Output&amp;gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;in&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #000000;"&gt;&amp;#125;&lt;/span&gt; &lt;/div&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;結果是:&lt;/p&gt;
&lt;div class="igBar"&gt;&lt;span id="lcpp-27"&gt;&lt;a href="#" onclick="javascript:showPlainTxt('cpp-27'); return false;"&gt;PLAIN TEXT&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="syntax_hilite"&gt;&lt;span class="langName"&gt;C++:&lt;/span&gt;
&lt;div id="cpp-27"&gt;
&lt;div class="cpp"&gt;
&lt;ol&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #0000ff;"&gt;int&lt;/span&gt; main&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #000000;"&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #0000ff;"&gt;using&lt;/span&gt; &lt;span style="color: #0000ff;"&gt;namespace&lt;/span&gt; std;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #ff0000;"&gt;// No ugly angled brackets for&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #ff0000;"&gt;// auto deduction of output type.&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #0000ff;"&gt;int&lt;/span&gt; i = lexi_cast3&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #666666;"&gt;"123"&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #0000dd;"&gt;cout&lt;/span&gt; &amp;lt;&amp;lt;i &amp;lt;&amp;lt;endl;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; string s = lexi_cast3&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;i&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #0000dd;"&gt;cout&lt;/span&gt; &amp;lt;&amp;lt;s &amp;lt;&amp;lt;endl;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #ff0000;"&gt;// User-specified output type.&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #0000dd;"&gt;cout&lt;/span&gt; &amp;lt;&amp;lt;lexi_cast3&amp;lt;int&amp;gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;s&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt; &amp;lt;&amp;lt;endl;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #0000ff;"&gt;return&lt;/span&gt; &lt;span style="color: #0000dd;color:#800000;"&gt;0&lt;/span&gt;;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #000000;"&gt;&amp;#125;&lt;/span&gt; &lt;/div&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;這次看來就像樣多了. 能美美地做自動轉換, 也能自行指定轉換的目的形別.&lt;/p&gt;
&lt;p&gt;The moral of this post - 果然還是 C++ 好玩!&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;[Update. Sep 22, 2009]&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Improved and simplified. Per Jeff's &lt;a href="http://fsfoundry.org/codefreak/2009/09/17/boost-lexical-cast-alternatives/comment-page-1/#comment-9641"&gt;request&lt;/a&gt;:&lt;/p&gt;
&lt;div class="igBar"&gt;&lt;span id="lcpp-28"&gt;&lt;a href="#" onclick="javascript:showPlainTxt('cpp-28'); return false;"&gt;PLAIN TEXT&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class="syntax_hilite"&gt;&lt;span class="langName"&gt;C++:&lt;/span&gt;
&lt;div id="cpp-28"&gt;
&lt;div class="cpp"&gt;
&lt;ol&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #0000ff;"&gt;class&lt;/span&gt; lexi_cast4_helper&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #000000;"&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #0000ff;"&gt;public&lt;/span&gt;:&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #0000ff;"&gt;template&lt;/span&gt; &amp;lt;class Input&amp;gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; lexi_cast4_helper&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;const&lt;/span&gt; Input&amp;amp; in&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #000000;"&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; ss_ &amp;lt;&amp;lt;in;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; &lt;span style="color: #0000ff;"&gt;if&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;!ss_.&lt;span style="color: #00eeff;"&gt;good&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; throw std::&lt;span style="color: #00eeff;"&gt;runtime_error&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #666666;"&gt;"lexi_cast4 failed"&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #000000;"&gt;&amp;#125;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #ff0000;"&gt;// Copy-ctor. Needed for compilation, but not&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #ff0000;"&gt;// invoked at run-time.&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; lexi_cast4_helper&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;const&lt;/span&gt; lexi_cast4_helper&amp;amp; other&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #000000;"&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; ss_ &amp;lt;&amp;lt;other.&lt;span style="color: #00eeff;"&gt;ss_&lt;/span&gt;.&lt;span style="color: #00eeff;"&gt;str&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #000000;"&gt;&amp;#125;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #0000ff;"&gt;template&lt;/span&gt; &amp;lt;class Output&amp;gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; operator Output&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #000000;"&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; Output out;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; ss_&amp;gt;&amp;gt; out;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; &lt;span style="color: #0000ff;"&gt;if&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;ss_.&lt;span style="color: #00eeff;"&gt;bad&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt; || ss_.&lt;span style="color: #00eeff;"&gt;fail&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; throw std::&lt;span style="color: #00eeff;"&gt;runtime_error&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #666666;"&gt;"lexi_cast4 failed"&lt;/span&gt;&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &amp;nbsp; &lt;span style="color: #0000ff;"&gt;return&lt;/span&gt; out;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #000000;"&gt;&amp;#125;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #0000ff;"&gt;private&lt;/span&gt;:&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; std::&lt;span style="color: #00eeff;"&gt;stringstream&lt;/span&gt; ss_;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #000000;"&gt;&amp;#125;&lt;/span&gt;;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #ff0000;"&gt;// Overload for output type auto deduction.&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #0000ff;"&gt;template&lt;/span&gt; &amp;lt;class Input&amp;gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;lexi_cast4_helper lexi_cast4&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;const&lt;/span&gt; Input&amp;amp; in&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #000000;"&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #0000ff;"&gt;return&lt;/span&gt; lexi_cast4_helper&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;in&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #000000;"&gt;&amp;#125;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #ff0000;"&gt;// Overload for user-specified output type.&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #ff0000;"&gt;// Instead of returning conversion helper,&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #ff0000;"&gt;// this version returns output type.&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #0000ff;"&gt;template&lt;/span&gt; &amp;lt;class Output, &lt;span style="color: #0000ff;"&gt;class&lt;/span&gt; Input&amp;gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;Output lexi_cast4&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;const&lt;/span&gt; Input&amp;amp; in&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #000000;"&gt;&amp;#123;&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&amp;nbsp; &lt;span style="color: #0000ff;"&gt;return&lt;/span&gt; lexi_cast4_helper&lt;span style="color: #000000;"&gt;&amp;#40;&lt;/span&gt;in&lt;span style="color: #000000;"&gt;&amp;#41;&lt;/span&gt;;&lt;/div&gt;
&lt;/li&gt;
&lt;li style="font-weight: bold;color:#26536A;"&gt;
&lt;div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"&gt;&lt;span style="color: #000000;"&gt;&amp;#125;&lt;/span&gt; &lt;/div&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;/p&gt;
&lt;br /&gt;&lt;a href="http://fsfoundry.org/codefreak/?p=544#comments" title="Comments on &amp;quot;Boost.Lexical-Cast Alternatives&amp;quot;"&gt;&lt;img src="http://fsfoundry.org/codefreak/wp-content/plugins/feed-comments-number/image.php?544" alt="Comments" /&gt;&lt;/a&gt;&lt;ol start="1" class="footnotes"&gt;&lt;li id="footnote-1-544" class="footnote"&gt;Sorry, Jeff. 明明是我自己愛玩卻還要遷拖到你. [&lt;a href="#footnote-link-1-544" class="footnote-link footnote-back-link"&gt;↩&lt;/a&gt;]&lt;/li&gt;&lt;li id="footnote-2-544" class="footnote"&gt;由於 IOStream 是不能 copy 的, 因此 &lt;code&gt;lexi_cast3_helper&lt;/code&gt; 需要有 copy-ctor 才能 compile. 有趣的是, 因為 RVO 的關係, 這些 copy-ctor 根本沒有 run-time 的用處, 不會被執行到. 可以把它的內容 comment 掉, 甚至亂改, 只要能 compile &amp;amp; link, 仍舊會正常運作. [&lt;a href="#footnote-link-2-544" class="footnote-link footnote-back-link"&gt;↩&lt;/a&gt;]&lt;/li&gt;&lt;/ol&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/codefreak?a=1e0q8vqIffg:MTAV4C8rEbg:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/codefreak?i=1e0q8vqIffg:MTAV4C8rEbg:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</content>
		<link rel="replies" type="text/html" href="http://fsfoundry.org/codefreak/2009/09/17/boost-lexical-cast-alternatives/#comments" thr:count="2" />
		<link rel="replies" type="application/atom+xml" href="http://fsfoundry.org/codefreak/2009/09/17/boost-lexical-cast-alternatives/feed/atom/" thr:count="2" />
		<thr:total>2</thr:total>
	<feedburner:origLink>http://fsfoundry.org/codefreak/2009/09/17/boost-lexical-cast-alternatives/</feedburner:origLink></entry>
		<entry>
		<author>
			<name>fr3@K</name>
						<uri>http://fsfoundry.org/codefreak/</uri>
					</author>
		<title type="html"><![CDATA[Server side connection/session lingering]]></title>
		<link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/codefreak/~3/Uxfb9AmHb5E/" />
		<id>http://fsfoundry.org/codefreak/2009/08/15/server-side-connectionsession-lingering/</id>
		<updated>2009-08-17T02:45:07Z</updated>
		<published>2009-08-15T10:39:24Z</published>
		<category scheme="http://fsfoundry.org/codefreak" term="~" /><category scheme="http://fsfoundry.org/codefreak" term="cited" /><category scheme="http://fsfoundry.org/codefreak" term="geeky" /><category scheme="http://fsfoundry.org/codefreak" term="networking" />		<summary type="html"><![CDATA[A great read on how to properly teardown a connection of synchronous protocols (e.g. HTTP) on the server side.
via: SO_LINGER is not the same as Apache's "lingering close".
]]></summary>
		<content type="html" xml:base="http://fsfoundry.org/codefreak/2009/08/15/server-side-connectionsession-lingering/">&lt;p&gt;A great read on how to &lt;a href="http://alumnit.ca/~apenwarr/log/?m=200908#14" rel="nofollow"&gt;properly teardown a connection&lt;/a&gt; of synchronous protocols (e.g. HTTP) on the server side.&lt;/p&gt;
&lt;p&gt;via: &lt;a href="http://alumnit.ca/~apenwarr/log/?m=200908#14"&gt;SO_LINGER is not the same as Apache's "lingering close"&lt;/a&gt;.&lt;/p&gt;
&lt;br /&gt;&lt;a href="http://fsfoundry.org/codefreak/2009/08/15/server-side-connectionsession-lingering/#comments" title="Comments on &amp;quot;Server side connection/session lingering&amp;quot;"&gt;&lt;img src="http://fsfoundry.org/codefreak/wp-content/plugins/feed-comments-number/image.php?516" alt="Comments" /&gt;&lt;/a&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/codefreak?a=Uxfb9AmHb5E:R5LubtkrwR0:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/codefreak?i=Uxfb9AmHb5E:R5LubtkrwR0:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</content>
		<link rel="replies" type="text/html" href="http://fsfoundry.org/codefreak/2009/08/15/server-side-connectionsession-lingering/#comments" thr:count="0" />
		<link rel="replies" type="application/atom+xml" href="http://fsfoundry.org/codefreak/2009/08/15/server-side-connectionsession-lingering/feed/atom/" thr:count="0" />
		<thr:total>0</thr:total>
	<feedburner:origLink>http://fsfoundry.org/codefreak/2009/08/15/server-side-connectionsession-lingering/</feedburner:origLink></entry>
	</feed>
