<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Output Stream Type Preservation</title>
	<atom:link href="http://fsfoundry.org/codefreak/2009/05/04/ostream-type-preservation/feed/" rel="self" type="application/rss+xml" />
	<link>http://fsfoundry.org/codefreak/2009/05/04/ostream-type-preservation/</link>
	<description>Weblog of a lively geek.</description>
	<lastBuildDate>Tue, 27 Jul 2010 06:54:46 -0700</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: fr3@K</title>
		<link>http://fsfoundry.org/codefreak/2009/05/04/ostream-type-preservation/comment-page-1/#comment-5984</link>
		<dc:creator>fr3@K</dc:creator>
		<pubDate>Mon, 04 May 2009 16:09:00 +0000</pubDate>
		<guid isPermaLink="false">http://fsfoundry.org/codefreak/2009/05/04/type-preservation-on-iostream/#comment-5984</guid>
		<description>Hi av,

你的方法很實用, 最明顯的優點就是保留了 &lt;code&gt;printf&lt;/code&gt; 的 format 方式與 &lt;code&gt;operator&lt;&lt;&lt;/code&gt; 的習慣.

我想是文內沒清楚表達, 這篇 post 想呈現重點的其實是在 insertion 時保留 output stream 的型別. 這樣可能可以有一些不只是字串化與格式化的有趣應用. 雖然這個 idea 是從 formatting 那邊發想來的.

譬如... 假設在操作一個繼承自 &lt;code&gt;iostream&lt;/code&gt; 的 TCP stream, 就能夠在 insert (send) 一個 request 後, 直接 extract (recv) response:
&lt;pre&gt;
  request req(...);
  response rsp;
  tcpstream &lt;&lt; req &gt;&gt; rsp;
&lt;/pre&gt;

或許該把這個我認為有趣且可能有用的例子加到 post 裏面.</description>
		<content:encoded><![CDATA[<p>Hi av,</p>
<p>你的方法很實用, 最明顯的優點就是保留了 <code>printf</code> 的 format 方式與 <code>operator&lt;&lt;</code> 的習慣.</p>
<p>我想是文內沒清楚表達, 這篇 post 想呈現重點的其實是在 insertion 時保留 output stream 的型別. 這樣可能可以有一些不只是字串化與格式化的有趣應用. 雖然這個 idea 是從 formatting 那邊發想來的.</p>
<p>譬如&#8230; 假設在操作一個繼承自 <code>iostream</code> 的 TCP stream, 就能夠在 insert (send) 一個 request 後, 直接 extract (recv) response:</p>
<pre>
  request req(...);
  response rsp;
  tcpstream &lt;&lt; req &gt;&gt; rsp;
</pre>
<p>或許該把這個我認為有趣且可能有用的例子加到 post 裏面.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: av</title>
		<link>http://fsfoundry.org/codefreak/2009/05/04/ostream-type-preservation/comment-page-1/#comment-5981</link>
		<dc:creator>av</dc:creator>
		<pubDate>Mon, 04 May 2009 14:49:37 +0000</pubDate>
		<guid isPermaLink="false">http://fsfoundry.org/codefreak/2009/05/04/type-preservation-on-iostream/#comment-5981</guid>
		<description>再補充一下，用這種方法，我弄了從 0 個參數到 20 個參數的版本，所以你可以寫
cout &lt;&lt; MyFormat(”no value&quot; ) &lt;&lt; endl; 
cout &lt;&lt; MyFormat(”The value of foo is: %d”, foo) &lt;&lt; endl;
cout &lt;&lt; MyFormat(”x = %d, y = %f z =  0x%x: %d”, 1, 2.5, 0xff) &lt;&lt; endl;
cout &lt;&lt; MyFormat(”%s say: %s because he has only %d dollors”, &quot;simon&quot;, str, szMoney ) &lt;&lt; endl;

20 個參數應該很夠用了.</description>
		<content:encoded><![CDATA[<p>再補充一下，用這種方法，我弄了從 0 個參數到 20 個參數的版本，所以你可以寫<br />
cout &lt;&lt; MyFormat(”no value&#8221; ) &lt;&lt; endl;<br />
cout &lt;&lt; MyFormat(”The value of foo is: %d”, foo) &lt;&lt; endl;<br />
cout &lt;&lt; MyFormat(”x = %d, y = %f z =  0x%x: %d”, 1, 2.5, 0xff) &lt;&lt; endl;<br />
cout &lt;&lt; MyFormat(”%s say: %s because he has only %d dollors”, &#8220;simon&#8221;, str, szMoney ) &lt;&lt; endl;</p>
<p>20 個參數應該很夠用了.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: av</title>
		<link>http://fsfoundry.org/codefreak/2009/05/04/ostream-type-preservation/comment-page-1/#comment-5979</link>
		<dc:creator>av</dc:creator>
		<pubDate>Mon, 04 May 2009 14:38:25 +0000</pubDate>
		<guid isPermaLink="false">http://fsfoundry.org/codefreak/2009/05/04/type-preservation-on-iostream/#comment-5979</guid>
		<description>我自己是用 boost::format 加上一&quot;些&quot; wrappers. 類似這樣:
&lt;pre&gt;
template &lt;class T1&gt;
inline std::string MyFormat(const char *Format, const T1&amp; t1)
{
   return ( boost::format(Format) % t1 ).str();
}

template &lt;class T1, class T2&gt;
inline std::string MyFormat(const char *Format, const T1&amp; t1, const T2&amp; t2)
{
   return ( boost::format(Format) % t1 % t2 ).str();
}
&lt;/pre&gt;
就這樣一大堆 overloaded function 來對應不同數量的參數，好處是不需要用 % 這個符號，用起來比較符合原來的習慣：
&lt;pre&gt;
cout &lt;&lt; MyFormat(&quot;The value of foo is: %d&quot;, foo)  &lt;&lt; endl;
&lt;/cpp&gt;

&lt;em&gt;ed: code snips formatted - fr3@K&lt;/em&gt;</description>
		<content:encoded><![CDATA[<p>我自己是用 boost::format 加上一&#8221;些&#8221; wrappers. 類似這樣:</p>
<pre>
template &lt;class T1&gt;
inline std::string MyFormat(const char *Format, const T1&amp; t1)
{
   return ( boost::format(Format) % t1 ).str();
}

template &lt;class T1, class T2&gt;
inline std::string MyFormat(const char *Format, const T1&amp; t1, const T2&amp; t2)
{
   return ( boost::format(Format) % t1 % t2 ).str();
}
</pre>
<p>就這樣一大堆 overloaded function 來對應不同數量的參數，好處是不需要用 % 這個符號，用起來比較符合原來的習慣：</p>
<pre>
cout &lt;&lt; MyFormat("The value of foo is: %d", foo)  &lt;&lt; endl;

<em>ed: code snips formatted - fr3@K</em></pre>
]]></content:encoded>
	</item>
</channel>
</rss>
