<?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-03-13T10:14:05Z</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[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-2"&gt;&lt;a href="#" onclick="javascript:showPlainTxt('cpp-2'); 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-2"&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-4"&gt;&lt;a href="#" onclick="javascript:showPlainTxt('cpp-4'); 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-4"&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>2009-11-05T23:00:41Z</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 like &lt;a href="http://fsfoundry.org/codefreak/2009/03/03/caffeine-intoxication/"&gt;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-13"&gt;&lt;a href="#" onclick="javascript:showPlainTxt('cpp-13'); 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-13"&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-14"&gt;&lt;a href="#" onclick="javascript:showPlainTxt('cpp-14'); 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-14"&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-15"&gt;&lt;a href="#" onclick="javascript:showPlainTxt('cpp-15'); 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-15"&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-16"&gt;&lt;a href="#" onclick="javascript:showPlainTxt('cpp-16'); 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-16"&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-17"&gt;&lt;a href="#" onclick="javascript:showPlainTxt('cpp-17'); 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-17"&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-18"&gt;&lt;a href="#" onclick="javascript:showPlainTxt('cpp-18'); 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-18"&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-19"&gt;&lt;a href="#" onclick="javascript:showPlainTxt('cpp-19'); 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-19"&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-20"&gt;&lt;a href="#" onclick="javascript:showPlainTxt('cpp-20'); 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-20"&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>
		<entry>
		<author>
			<name>fr3@K</name>
						<uri>http://fsfoundry.org/codefreak/</uri>
					</author>
		<title type="html"><![CDATA[The C++0x &#8220;Remove Concepts&#8221; Decision]]></title>
		<link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/codefreak/~3/oBq-hPp6EvY/" />
		<id>http://fsfoundry.org/codefreak/?p=510</id>
		<updated>2009-08-12T12:52:37Z</updated>
		<published>2009-08-09T11:24:36Z</published>
		<category scheme="http://fsfoundry.org/codefreak" term="~" /><category scheme="http://fsfoundry.org/codefreak" term="C++" /><category scheme="http://fsfoundry.org/codefreak" term="C++0x" /><category scheme="http://fsfoundry.org/codefreak" term="cited" /><category scheme="http://fsfoundry.org/codefreak" term="geeky" />		<summary type="html"><![CDATA[懶人包 + Bjarne on DDJ (翻譯), from Paramecium.
Great job! Thanks, Keiko.
]]></summary>
		<content type="html" xml:base="http://fsfoundry.org/codefreak/2009/08/09/the-cpp0x-remove-concepts-decision/">&lt;p&gt;&lt;a href="http://keikoblog.blogspot.com/2009/08/c0x-concepts-decision.html"&gt;懶人包 + Bjarne on DDJ (翻譯)&lt;/a&gt;, from &lt;a href="http://keikoblog.blogspot.com/"&gt;Paramecium&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Great job! Thanks, Keiko.&lt;/p&gt;
&lt;br /&gt;&lt;a href="http://fsfoundry.org/codefreak/?p=510#comments" title="Comments on &amp;quot;The C++0x &amp;#8220;Remove Concepts&amp;#8221; Decision&amp;quot;"&gt;&lt;img src="http://fsfoundry.org/codefreak/wp-content/plugins/feed-comments-number/image.php?510" alt="Comments" /&gt;&lt;/a&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/codefreak?a=oBq-hPp6EvY:HFOZep8WUq8:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/codefreak?i=oBq-hPp6EvY:HFOZep8WUq8: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/09/the-cpp0x-remove-concepts-decision/#comments" thr:count="0" />
		<link rel="replies" type="application/atom+xml" href="http://fsfoundry.org/codefreak/2009/08/09/the-cpp0x-remove-concepts-decision/feed/atom/" thr:count="0" />
		<thr:total>0</thr:total>
	<feedburner:origLink>http://fsfoundry.org/codefreak/2009/08/09/the-cpp0x-remove-concepts-decision/</feedburner:origLink></entry>
		<entry>
		<author>
			<name>fr3@K</name>
						<uri>http://fsfoundry.org/codefreak/</uri>
					</author>
		<title type="html"><![CDATA[Avoid Leading Underscores]]></title>
		<link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/codefreak/~3/WT_Q-P_4_I0/" />
		<id>http://fsfoundry.org/codefreak/?p=264</id>
		<updated>2009-07-25T10:08:11Z</updated>
		<published>2009-07-25T09:48:52Z</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 base 裏面都能看到在前面加個 underscore (底線/下滑线) 的 function/macro/variable. 常常是用來暗示某個 name 是 local/private, 有時是用來避免 name collision.

GoF 的經典巨著 Design Patterns 裏面, 以及一個時期的 Herb Sutter (the GURU), 都以在前面加上底線的方式標示 member data.
所有我見過的 Standard Library 的 implementation 不但都以在前面加個 underscore (底線/下滑线) 的方式命名 inclusion guard,1 也多用這方法替 member data 以及非公開的 identifier 起名字. Windows 則更是出了名的有許多在前面加了個 underscore 的標準 (documented) Win32 API.
可是關於 leading underscore, 標準是這麼說的: 2

Each name [...]]]></summary>
		<content type="html" xml:base="http://fsfoundry.org/codefreak/2009/07/25/avoid-leading-underscores/">&lt;p&gt;在很多 code base 裏面都能看到在前面加個 underscore (底線/下滑线) 的 function/macro/variable. 常常是用來&lt;em&gt;暗示&lt;/em&gt;某個 name 是 local/private, 有時是用來避免 name collision.&lt;br /&gt;
&lt;span id="more-264"&gt;&lt;/span&gt;&lt;br /&gt;
&lt;a href="http://hillside.net/patterns/DPBook/GOF.html"&gt;GoF&lt;/a&gt; 的經典巨著 &lt;a href="http://www.amazon.com/gp/product/0201633612/104-6374662-6528705?v=glance&amp;#038;n=283155"&gt;Design Patterns&lt;/a&gt; 裏面, 以及一個時期的 &lt;a href="http://www.gotw.ca/"&gt;Herb Sutter&lt;/a&gt; (the GURU), 都以在前面加上底線的方式標示 member data.&lt;/p&gt;
&lt;p&gt;所有我見過的 Standard Library 的 implementation 不但都以在前面加個 underscore (底線/下滑线) 的方式命名 inclusion guard,&lt;sup&gt;&lt;a href="#footnote-1-264" id="footnote-link-1-264" class="footnote-link footnote-identifier-link" title="以 vector  為例, VC++ 的叫 _VECTOR_. libstdc++ 的是 _GLIBCXX_VECTOR"&gt;1&lt;/a&gt;&lt;/sup&gt; 也多用這方法替 member data 以及非公開的 identifier 起名字. Windows 則更是出了名的有許多在前面加了個 underscore 的標準 (documented) Win32 API.&lt;/p&gt;
&lt;p&gt;可是關於 leading underscore, 標準是這麼說的: &lt;sup&gt;&lt;a href="#footnote-2-264" id="footnote-link-2-264" class="footnote-link footnote-identifier-link" title="C++98 17.4.3.1.2"&gt;2&lt;/a&gt;&lt;/sup&gt;&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;
Each name that begins with an underscore is reserved to the implementation for use as a name in the global namespace.
&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;所有以 underscore 起頭的 identifier 都是保留給 compiler/standard library 實作&lt;em&gt;任意&lt;/em&gt;使用的. 也就是說如果使用者自行定義了這樣的 identifier, 結果是無法預期的. 運氣好, 在 compile 時就得到 compiler error. 倒楣的話 undefined behavior 也不是不可能發生.&lt;/p&gt;
&lt;p&gt;在實踐上, 這樣的 code 有很大的機會可以在你現在使用的 compiler 之下能正常編譯與運作, 但卻不能保證它就能在另一個 compiler (甚至是同一 compiler 的下一個版本) 之下也會得到相同的結果.&lt;sup&gt;&lt;a href="#footnote-3-264" id="footnote-link-3-264" class="footnote-link footnote-identifier-link" title="把 Small 從 Windows port 到 Unix 時就遇到了這樣的問題"&gt;3&lt;/a&gt;&lt;/sup&gt;&lt;/p&gt;
&lt;p&gt;延伸閱讀: Item 11 of &lt;a href="http://www.gotw.ca/gotw/004.htm"&gt;GotW #4&lt;/a&gt;.&lt;/p&gt;
&lt;br /&gt;&lt;a href="http://fsfoundry.org/codefreak/?p=264#comments" title="Comments on &amp;quot;Avoid Leading Underscores&amp;quot;"&gt;&lt;img src="http://fsfoundry.org/codefreak/wp-content/plugins/feed-comments-number/image.php?264" alt="Comments" /&gt;&lt;/a&gt;&lt;ol start="1" class="footnotes"&gt;&lt;li id="footnote-1-264" class="footnote"&gt;以 &lt;code&gt;vector &lt;/code&gt; 為例, VC++ 的叫 &lt;code&gt;_VECTOR_&lt;/code&gt;. libstdc++ 的是 &lt;code&gt;_GLIBCXX_VECTOR&lt;/code&gt; [&lt;a href="#footnote-link-1-264" class="footnote-link footnote-back-link"&gt;↩&lt;/a&gt;]&lt;/li&gt;&lt;li id="footnote-2-264" class="footnote"&gt;C++98 17.4.3.1.2 [&lt;a href="#footnote-link-2-264" class="footnote-link footnote-back-link"&gt;↩&lt;/a&gt;]&lt;/li&gt;&lt;li id="footnote-3-264" class="footnote"&gt;把 &lt;a href="http://www.compuphase.com/small.htm"&gt;Small&lt;/a&gt; 從 &lt;a href="http://sourceware.org/autobook/autobook/autobook_48.html"&gt;Windows port 到 Unix&lt;/a&gt; 時就遇到了這樣的問題 [&lt;a href="#footnote-link-3-264" 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=WT_Q-P_4_I0:G8-_crdxGeI:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/codefreak?i=WT_Q-P_4_I0:G8-_crdxGeI: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/07/25/avoid-leading-underscores/#comments" thr:count="1" />
		<link rel="replies" type="application/atom+xml" href="http://fsfoundry.org/codefreak/2009/07/25/avoid-leading-underscores/feed/atom/" thr:count="1" />
		<thr:total>1</thr:total>
	<feedburner:origLink>http://fsfoundry.org/codefreak/2009/07/25/avoid-leading-underscores/</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/KCND_xbx7V8/" />
		<id>http://fsfoundry.org/codefreak/?p=492</id>
		<updated>2009-07-22T03:54:39Z</updated>
		<published>2009-07-22T03:52:15Z</published>
		<category scheme="http://fsfoundry.org/codefreak" term="~" /><category scheme="http://fsfoundry.org/codefreak" term="mortal" /><category scheme="http://fsfoundry.org/codefreak" term="pop-sci" />		<summary type="html"><![CDATA[
老婆被我叫起床拍的照片.
]]></summary>
		<content type="html" xml:base="http://fsfoundry.org/codefreak/2009/07/22/eclipse-in-taipei/">&lt;p&gt;&lt;img src="http://fsfoundry.org/gallery/main.php?g2_view=core.DownloadItem&amp;#038;g2_itemId=8615&amp;#038;g2_serialNumber=3" width=400 /&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://fsfoundry.org/gallery/main.php?g2_itemId=8618"&gt;老婆被我叫起床拍的照片&lt;/a&gt;.&lt;/p&gt;
&lt;br /&gt;&lt;a href="http://fsfoundry.org/codefreak/?p=492#comments" title="Comments on &amp;quot;日蝕&amp;quot;"&gt;&lt;img src="http://fsfoundry.org/codefreak/wp-content/plugins/feed-comments-number/image.php?492" alt="Comments" /&gt;&lt;/a&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/codefreak?a=KCND_xbx7V8:mZsFhLytjhU:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/codefreak?i=KCND_xbx7V8:mZsFhLytjhU: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/07/22/eclipse-in-taipei/#comments" thr:count="4" />
		<link rel="replies" type="application/atom+xml" href="http://fsfoundry.org/codefreak/2009/07/22/eclipse-in-taipei/feed/atom/" thr:count="4" />
		<thr:total>4</thr:total>
	<feedburner:origLink>http://fsfoundry.org/codefreak/2009/07/22/eclipse-in-taipei/</feedburner:origLink></entry>
		<entry>
		<author>
			<name>fr3@K</name>
						<uri>http://fsfoundry.org/codefreak/</uri>
					</author>
		<title type="html"><![CDATA[C++0x &#8211; Concepts Rejected]]></title>
		<link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/codefreak/~3/bBUuxMv2X8I/" />
		<id>http://fsfoundry.org/codefreak/2009/07/21/c0x-concepts-are-voted-out/</id>
		<updated>2009-07-21T02:45:59Z</updated>
		<published>2009-07-21T02:17:58Z</published>
		<category scheme="http://fsfoundry.org/codefreak" term="~" /><category scheme="http://fsfoundry.org/codefreak" term="C++" /><category scheme="http://fsfoundry.org/codefreak" term="C++0x" /><category scheme="http://fsfoundry.org/codefreak" term="cited" /><category scheme="http://fsfoundry.org/codefreak" term="geeky" />		<summary type="html"><![CDATA[大件事, Concepts 被否決了.
]]></summary>
		<content type="html" xml:base="http://fsfoundry.org/codefreak/2009/07/21/cpp0x-concepts-rejected/">&lt;p&gt;大件事, &lt;a href="http://en.wikipedia.org/wiki/C%2B%2B0x#Concepts"&gt;Concepts&lt;/a&gt; 被&lt;a href="http://www.informit.com/guides/content.aspx?g=cplusplus&amp;#038;seqNum=441"&gt;否決&lt;/a&gt;了.&lt;/p&gt;
&lt;br /&gt;&lt;a href="http://fsfoundry.org/codefreak/2009/07/21/c0x-concepts-are-voted-out/#comments" title="Comments on &amp;quot;C++0x &amp;#8211; Concepts Rejected&amp;quot;"&gt;&lt;img src="http://fsfoundry.org/codefreak/wp-content/plugins/feed-comments-number/image.php?487" alt="Comments" /&gt;&lt;/a&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/codefreak?a=bBUuxMv2X8I:ClSpQRQdHKI:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/codefreak?i=bBUuxMv2X8I:ClSpQRQdHKI: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/07/21/cpp0x-concepts-rejected/#comments" thr:count="1" />
		<link rel="replies" type="application/atom+xml" href="http://fsfoundry.org/codefreak/2009/07/21/cpp0x-concepts-rejected/feed/atom/" thr:count="1" />
		<thr:total>1</thr:total>
	<feedburner:origLink>http://fsfoundry.org/codefreak/2009/07/21/cpp0x-concepts-rejected/</feedburner:origLink></entry>
		<entry>
		<author>
			<name>fr3@K</name>
						<uri>http://fsfoundry.org/codefreak/</uri>
					</author>
		<title type="html"><![CDATA[Status Update, Mid 2009]]></title>
		<link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/codefreak/~3/ij4HMrHYKsQ/" />
		<id>http://fsfoundry.org/codefreak/?p=377</id>
		<updated>2009-06-28T02:27:45Z</updated>
		<published>2009-06-27T15:59:03Z</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[接下來幾個月, 打算把較多的閒暇時間用在一個 "低調計畫" 上. 因此, 預期將減少產出有意義的原創文字.
這個 project 當然是用 C++ 寫些東西. Scope 不大, 因此只要不擺爛, 一個人也一定寫得完. 簡單的說是要 re-implement 一個已存在並被不少人使用的 FOSS project. 將大量使用 Boost. 特別是已經一年多沒碰的 Asio, 以及很可惜一直沒玩到的 Multi-Index. 可以說是拿 Asio 來挑戰 libevent.
如果能較前人的貢獻有更好的 performance 當然最好. 即便不如期望, 也希望可以有機會找出不能 out-perform 的原因或線索. 或許能回饋給 Boost/Asio, 提供改善的方向. 無論如何, this is gonna be fun.
另, 如果你覺得閱讀小弟的文字不算是一件太浪費生命的事, 建議參觀/訂閱我的 Shared Items (via Google Reader).
]]></summary>
		<content type="html" xml:base="http://fsfoundry.org/codefreak/2009/06/27/status-update-mid-2009/">&lt;p&gt;接下來幾個月, 打算把較多的閒暇時間用在一個 "低調計畫" 上. 因此, 預期將減少產出有意義的原創文字.&lt;/p&gt;
&lt;p&gt;這個 project 當然是用 C++ 寫些東西. Scope 不大, 因此只要不擺爛, 一個人也一定寫得完. 簡單的說是要 re-implement 一個已存在並被不少人使用的 FOSS &lt;a href="http://www.danga.com/memcached/" rel="nofollow"&gt;project&lt;/a&gt;. 將大量使用 &lt;a href="http://boost.org" rel="nofollow"&gt;Boost&lt;/a&gt;. 特別是已經一年多沒碰的 &lt;a href="http://www.boost.org/doc/libs/1_39_0/doc/html/boost_asio.html" rel="nofollow"&gt;Asio&lt;/a&gt;, 以及很可惜一直沒玩到的 &lt;a href="http://www.boost.org/doc/libs/1_39_0/libs/multi_index/doc/index.html" rel="nofollow"&gt;Multi-Index&lt;/a&gt;. 可以說是拿 Asio 來挑戰 &lt;a href="http://www.monkey.org/~provos/libevent/" rel="nofollow"&gt;libevent&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;如果能較前人的貢獻有更好的 performance 當然最好. 即便不如期望, 也希望可以有機會找出不能 out-perform 的原因或線索. 或許能回饋給 Boost/Asio, 提供改善的方向. 無論如何, this is gonna be fun.&lt;/p&gt;
&lt;p&gt;另, 如果你覺得閱讀小弟的文字不算是一件太浪費生命的事, 建議參觀/訂閱我的 &lt;a href="http://www.google.com/reader/shared/user/15909074279984661889/state/com.google/broadcast" rel="nofollow"&gt;Shared Items&lt;/a&gt; (via Google Reader).&lt;/p&gt;
&lt;br /&gt;&lt;a href="http://fsfoundry.org/codefreak/?p=377#comments" title="Comments on &amp;quot;Status Update, Mid 2009&amp;quot;"&gt;&lt;img src="http://fsfoundry.org/codefreak/wp-content/plugins/feed-comments-number/image.php?377" alt="Comments" /&gt;&lt;/a&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/codefreak?a=ij4HMrHYKsQ:jQWSMd3c-DI:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/codefreak?i=ij4HMrHYKsQ:jQWSMd3c-DI: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/06/27/status-update-mid-2009/#comments" thr:count="3" />
		<link rel="replies" type="application/atom+xml" href="http://fsfoundry.org/codefreak/2009/06/27/status-update-mid-2009/feed/atom/" thr:count="3" />
		<thr:total>3</thr:total>
	<feedburner:origLink>http://fsfoundry.org/codefreak/2009/06/27/status-update-mid-2009/</feedburner:origLink></entry>
		<entry>
		<author>
			<name>fr3@K</name>
						<uri>http://fsfoundry.org/codefreak/</uri>
					</author>
		<title type="html"><![CDATA[STL Performance Boost in VS2010]]></title>
		<link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/codefreak/~3/vh1UD_HgCgI/" />
		<id>http://fsfoundry.org/codefreak/?p=348</id>
		<updated>2009-06-29T07:54:06Z</updated>
		<published>2009-06-27T14:18:32Z</published>
		<category scheme="http://fsfoundry.org/codefreak" term="~" /><category scheme="http://fsfoundry.org/codefreak" term="C++" /><category scheme="http://fsfoundry.org/codefreak" term="C++0x" /><category scheme="http://fsfoundry.org/codefreak" term="cited" /><category scheme="http://fsfoundry.org/codefreak" term="rvalue-references" />		<summary type="html"><![CDATA[幾個月前曾在一篇文字裡寫道: 正確的運用 Rvalue References, 有可能帶來可觀的 performance gain. 前幾天看到 Visual C++ Team Blog 新貼出對 STL (VS2010 vs. VS2008) 的 performance benchmark. 在一個程度上, 該篇文字可以說驗證了這個不只我一個人獨有的看法與對 C++0x 的期待.
Rvalue-References 帶來的 performance boost 或許比不上 Multi-Core STL 來得那麼 "方便", 但絕對是你不會想要錯過的 low hanging fruit.
C++0x 的巨浪就要來了, 你準備好了嗎?
]]></summary>
		<content type="html" xml:base="http://fsfoundry.org/codefreak/2009/06/27/stl-performance-boost-in-vs2010/">&lt;p&gt;幾個月前曾在一篇文字裡寫道: &lt;a href="http://fsfoundry.org/codefreak/2009/05/19/i-like-to-move-it/"&gt;正確的運用 Rvalue References, 有可能帶來可觀的 performance gain&lt;/a&gt;. 前幾天看到 Visual C++ Team Blog 新貼出對 STL (VS2010 vs. VS2008) 的 performance &lt;a href="http://blogs.msdn.com/vcblog/archive/2009/06/23/stl-performance.aspx" rel="nofollow"&gt;benchmark&lt;/a&gt;. 在一個程度上, 該篇文字可以說驗證了這個不只我一個人獨有的看法與對 &lt;a href="http://fsfoundry.org/codefreak/tag/cpp0x/"&gt;C++0x&lt;/a&gt; 的期待.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://fsfoundry.org/codefreak/tag/rvalue-references/"&gt;Rvalue-References&lt;/a&gt; 帶來的 performance boost 或許比不上 &lt;a href="http://fsfoundry.org/codefreak/2008/04/15/the-free-launch-is-back/"&gt;Multi-Core STL&lt;/a&gt; 來得那麼 "方便", 但絕對是你不會想要錯過的 low hanging fruit.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://fsfoundry.org/codefreak/2008/10/29/incoming-strom-cpp0x/"&gt;C++0x 的巨浪就要來了&lt;/a&gt;, 你準備好了嗎?&lt;/p&gt;
&lt;br /&gt;&lt;a href="http://fsfoundry.org/codefreak/?p=348#comments" title="Comments on &amp;quot;STL Performance Boost in VS2010&amp;quot;"&gt;&lt;img src="http://fsfoundry.org/codefreak/wp-content/plugins/feed-comments-number/image.php?348" alt="Comments" /&gt;&lt;/a&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/codefreak?a=vh1UD_HgCgI:cMwMM3H6B1Q:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/codefreak?i=vh1UD_HgCgI:cMwMM3H6B1Q: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/06/27/stl-performance-boost-in-vs2010/#comments" thr:count="0" />
		<link rel="replies" type="application/atom+xml" href="http://fsfoundry.org/codefreak/2009/06/27/stl-performance-boost-in-vs2010/feed/atom/" thr:count="0" />
		<thr:total>0</thr:total>
	<feedburner:origLink>http://fsfoundry.org/codefreak/2009/06/27/stl-performance-boost-in-vs2010/</feedburner:origLink></entry>
	</feed>
