<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
		xmlns:xhtml="http://www.w3.org/1999/xhtml"
>

<channel>
	<title>イージーネット Tech Blog &#187; C++0x</title>
	<atom:link href="http://blog.eni.co.jp/tech/tag/c0x/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.eni.co.jp/tech</link>
	<description>株式会社イージーネットのスタッフによる技術系ブログです</description>
	<lastBuildDate>Tue, 12 Jan 2010 01:46:58 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>ja</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://blog.eni.co.jp/tech/tag/c0x/feed" />
		<item>
		<title>Ubuntu 9.04 + GCC 4.4.1でC++0xを試してみた</title>
		<link>http://blog.eni.co.jp/tech/2009/08/ubuntu-gcc-cpp0x-getting-started.html</link>
		<comments>http://blog.eni.co.jp/tech/2009/08/ubuntu-gcc-cpp0x-getting-started.html#comments</comments>
		<pubDate>Wed, 19 Aug 2009 02:00:57 +0000</pubDate>
		<dc:creator>青野 和仁</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[プログラム]]></category>
		<category><![CDATA[auto]]></category>
		<category><![CDATA[C++0x]]></category>
		<category><![CDATA[GCC]]></category>
		<category><![CDATA[N2914]]></category>

		<guid isPermaLink="false">http://blog.eni.co.jp/tech/?p=990</guid>
		<description><![CDATA[こんにちは。
プロダクト&#038;サービス事業部の青野です。
C++0xの一部の機能はGCC 4.3から使用することが可能になっています。そこで今回はC++0xで少し遊んでみようと思います。
C++0xとGCCの対応状況について

C++0xの概要(Faith and Brave &#8211; C++で遊ぼう)
C++0xの言語仕様(ドラフト)
GCCのC++0x対応状況


コンパイル環境の準備
Ubuntu 9.04で配布されているGCC(g++)は4.3系の為、autoがまだ実装されていません。とりあえずautoを試してみたいので7月22日にリリースされた4.4.1をソースからコンパイルしてインストールします。

GCCのダウンロードと展開

$ mkdir ~/src
$ cd ~/src
$ wget ftp://ftp.dti.ad.jp/pub/lang/gcc/releases/gcc-4.4.1/gcc-4.4.1.tar.gz
$ tar xvzf gcc-4.4.1.tar.gz


GMPのダウンロードと展開

$ cd ~/src
$ wget ftp://ftp.gmplib.org/pub/gmp-4.3.1/gmp-4.3.1.tar.gz
$ tar xvzf gmp-4.3.1.tar.gz
$ mv gmp-4.3.1 gcc-4.4.1/gmp


MPFRのダウンロードと展開

$ cd ~/src
$ wget http://www.mpfr.org/mpfr-current/mpfr-2.4.1.tar.gz
$ tar xvzf mpfr-2.4.1.tar.gz
$ mv mpfr-2.4.1 gcc-4.4.1/mpfr


ビルドとインストール

$ mkdir ~/src/gccobj
$ cd ~/src/gccobj
$ ../gcc-4.4.1/configure
$ make bootstrap
$ sudo make install



C++0xソースのコンパイルと実行
Initializer Listとautoを試してみた

サンプルソース(sample.cpp)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include &#60;iostream&#62;
#include &#60;vector&#62;
&#160;
void print&#40;const std::vector&#60;int&#62;&#38; v&#41; &#123;
   [...]]]></description>
			<content:encoded><![CDATA[<p>こんにちは。<br />
プロダクト&#038;サービス事業部の青野です。</p>
<p>C++0xの一部の機能はGCC 4.3から使用することが可能になっています。そこで今回はC++0xで少し遊んでみようと思います。</p>
<h3>C++0xとGCCの対応状況について</h3>
<ul>
<li><a href="http://d.hatena.ne.jp/faith_and_brave/20080725/1216976661">C++0xの概要(Faith and Brave &#8211; C++で遊ぼう)</a></li>
<li><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/projects#14882">C++0xの言語仕様(ドラフト)</a></li>
<li><a href="http://gcc.gnu.org/projects/cxx0x.html">GCCのC++0x対応状況</a></li>
</ul>
<p><span id="more-990"></span></p>
<h3>コンパイル環境の準備</h3>
<p>Ubuntu 9.04で配布されているGCC(g++)は4.3系の為、autoがまだ実装されていません。とりあえずautoを試してみたいので7月22日にリリースされた4.4.1をソースからコンパイルしてインストールします。</p>
<ol>
<li>GCCのダウンロードと展開

<div class="wp_codebox"><table width="100%" ><tr id="p9908"><td class="code" id="p990code8"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">mkdir</span> ~<span style="color: #000000; font-weight: bold;">/</span>src
$ <span style="color: #7a0874; font-weight: bold;">cd</span> ~<span style="color: #000000; font-weight: bold;">/</span>src
$ <span style="color: #c20cb9; font-weight: bold;">wget</span> <span style="color: #c20cb9; font-weight: bold;">ftp</span>:<span style="color: #000000; font-weight: bold;">//</span>ftp.dti.ad.jp<span style="color: #000000; font-weight: bold;">/</span>pub<span style="color: #000000; font-weight: bold;">/</span>lang<span style="color: #000000; font-weight: bold;">/</span>gcc<span style="color: #000000; font-weight: bold;">/</span>releases<span style="color: #000000; font-weight: bold;">/</span>gcc-4.4.1<span style="color: #000000; font-weight: bold;">/</span>gcc-4.4.1.tar.gz
$ <span style="color: #c20cb9; font-weight: bold;">tar</span> xvzf gcc-4.4.1.tar.gz</pre></td></tr></table></div>

</li>
<li>GMPのダウンロードと展開

<div class="wp_codebox"><table width="100%" ><tr id="p9909"><td class="code" id="p990code9"><pre class="bash" style="font-family:monospace;">$ <span style="color: #7a0874; font-weight: bold;">cd</span> ~<span style="color: #000000; font-weight: bold;">/</span>src
$ <span style="color: #c20cb9; font-weight: bold;">wget</span> <span style="color: #c20cb9; font-weight: bold;">ftp</span>:<span style="color: #000000; font-weight: bold;">//</span>ftp.gmplib.org<span style="color: #000000; font-weight: bold;">/</span>pub<span style="color: #000000; font-weight: bold;">/</span>gmp-4.3.1<span style="color: #000000; font-weight: bold;">/</span>gmp-4.3.1.tar.gz
$ <span style="color: #c20cb9; font-weight: bold;">tar</span> xvzf gmp-4.3.1.tar.gz
$ <span style="color: #c20cb9; font-weight: bold;">mv</span> gmp-4.3.1 gcc-4.4.1<span style="color: #000000; font-weight: bold;">/</span>gmp</pre></td></tr></table></div>

</li>
<li>MPFRのダウンロードと展開

<div class="wp_codebox"><table width="100%" ><tr id="p99010"><td class="code" id="p990code10"><pre class="bash" style="font-family:monospace;">$ <span style="color: #7a0874; font-weight: bold;">cd</span> ~<span style="color: #000000; font-weight: bold;">/</span>src
$ <span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>www.mpfr.org<span style="color: #000000; font-weight: bold;">/</span>mpfr-current<span style="color: #000000; font-weight: bold;">/</span>mpfr-2.4.1.tar.gz
$ <span style="color: #c20cb9; font-weight: bold;">tar</span> xvzf mpfr-2.4.1.tar.gz
$ <span style="color: #c20cb9; font-weight: bold;">mv</span> mpfr-2.4.1 gcc-4.4.1<span style="color: #000000; font-weight: bold;">/</span>mpfr</pre></td></tr></table></div>

</li>
<li>ビルドとインストール

<div class="wp_codebox"><table width="100%" ><tr id="p99011"><td class="code" id="p990code11"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">mkdir</span> ~<span style="color: #000000; font-weight: bold;">/</span>src<span style="color: #000000; font-weight: bold;">/</span>gccobj
$ <span style="color: #7a0874; font-weight: bold;">cd</span> ~<span style="color: #000000; font-weight: bold;">/</span>src<span style="color: #000000; font-weight: bold;">/</span>gccobj
$ ..<span style="color: #000000; font-weight: bold;">/</span>gcc-4.4.1<span style="color: #000000; font-weight: bold;">/</span>configure
$ <span style="color: #c20cb9; font-weight: bold;">make</span> bootstrap
$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #c20cb9; font-weight: bold;">install</span></pre></td></tr></table></div>

</li>
</ol>
<h3>C++0xソースのコンパイルと実行</h3>
<h4>Initializer Listとautoを試してみた</h4>
<ol>
<li>サンプルソース(sample.cpp)

<div class="wp_codebox"><table width="100%" ><tr id="p99012"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
</pre></td><td class="code" id="p990code12"><pre class="cpp" style="font-family:monospace;"><span style="color: #339900;">#include &lt;iostream&gt;</span>
<span style="color: #339900;">#include &lt;vector&gt;</span>
&nbsp;
<span style="color: #0000ff;">void</span> print<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">const</span> std<span style="color: #008080;">::</span><span style="color: #007788;">vector</span><span style="color: #000080;">&lt;</span><span style="color: #0000ff;">int</span><span style="color: #000080;">&gt;</span><span style="color: #000040;">&amp;</span> v<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
    std<span style="color: #008080;">::</span><span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;[print]&quot;</span> <span style="color: #000080;">&lt;&lt;</span> std<span style="color: #008080;">::</span><span style="color: #007788;">endl</span><span style="color: #008080;">;</span>
&nbsp;
    <span style="color: #666666;">// std::vector&lt;int&gt;::const_iteratorだってautoでOK</span>
    <span style="color: #0000ff;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #0000ff;">auto</span> it <span style="color: #000080;">=</span> v.<span style="color: #007788;">begin</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span> it <span style="color: #000040;">!</span><span style="color: #000080;">=</span> v.<span style="color: #007788;">end</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span> <span style="color: #000040;">++</span>it<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
        std<span style="color: #008080;">::</span><span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #000040;">*</span>it <span style="color: #000080;">&lt;&lt;</span> std<span style="color: #008080;">::</span><span style="color: #007788;">endl</span><span style="color: #008080;">;</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
    std<span style="color: #008080;">::</span><span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> std<span style="color: #008080;">::</span><span style="color: #007788;">endl</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0000ff;">void</span> rprint<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">const</span> std<span style="color: #008080;">::</span><span style="color: #007788;">vector</span><span style="color: #000080;">&lt;</span><span style="color: #0000ff;">int</span><span style="color: #000080;">&gt;</span><span style="color: #000040;">&amp;</span> v<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
    std<span style="color: #008080;">::</span><span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;[rprint]&quot;</span> <span style="color: #000080;">&lt;&lt;</span> std<span style="color: #008080;">::</span><span style="color: #007788;">endl</span><span style="color: #008080;">;</span>
&nbsp;
    <span style="color: #666666;">// std::vector&lt;int&gt;::const_reverse_iteratorだってautoでOK!</span>
    <span style="color: #0000ff;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #0000ff;">auto</span> it <span style="color: #000080;">=</span> v.<span style="color: #007788;">rbegin</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span> it <span style="color: #000040;">!</span><span style="color: #000080;">=</span> v.<span style="color: #007788;">rend</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span> <span style="color: #000040;">++</span>it<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
        std<span style="color: #008080;">::</span><span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #000040;">*</span>it <span style="color: #000080;">&lt;&lt;</span> std<span style="color: #008080;">::</span><span style="color: #007788;">endl</span><span style="color: #008080;">;</span>
    <span style="color: #008000;">&#125;</span>
&nbsp;
    std<span style="color: #008080;">::</span><span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> std<span style="color: #008080;">::</span><span style="color: #007788;">endl</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0000ff;">int</span> main<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
    std<span style="color: #008080;">::</span><span style="color: #007788;">vector</span><span style="color: #000080;">&lt;</span><span style="color: #0000ff;">int</span><span style="color: #000080;">&gt;</span> v <span style="color: #000080;">=</span> <span style="color: #008000;">&#123;</span>1, 5, 10<span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span>
&nbsp;
    <span style="color: #666666;">// std::vector&lt;int&gt;::iteratorだってautoでOK!</span>
    <span style="color: #0000ff;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #0000ff;">auto</span> it <span style="color: #000080;">=</span> v.<span style="color: #007788;">begin</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span> it <span style="color: #000040;">!</span><span style="color: #000080;">=</span> v.<span style="color: #007788;">end</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span> <span style="color: #000040;">++</span>it<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
        std<span style="color: #008080;">::</span><span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #000040;">*</span>it <span style="color: #000080;">&lt;&lt;</span> std<span style="color: #008080;">::</span><span style="color: #007788;">endl</span><span style="color: #008080;">;</span>
    <span style="color: #008000;">&#125;</span>
    std<span style="color: #008080;">::</span><span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> std<span style="color: #008080;">::</span><span style="color: #007788;">endl</span><span style="color: #008080;">;</span>
&nbsp;
    print<span style="color: #008000;">&#40;</span>v<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    rprint<span style="color: #008000;">&#40;</span>v<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
    <span style="color: #0000ff;">return</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

</li>
<li>コンパイル<br />
コンパイル時にC++0xの機能を使用する場合、コンパイル時に-std=gnu++0xオプションを指定する必要があります。</p>

<div class="wp_codebox"><table width="100%" ><tr id="p99013"><td class="code" id="p990code13"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">g++</span> <span style="color: #660033;">-std</span>=gnu++0x sample.cpp</pre></td></tr></table></div>

</li>
<li>実行結果

<div class="wp_codebox"><table width="100%" ><tr id="p99014"><td class="code" id="p990code14"><pre class="bash" style="font-family:monospace;">$ .<span style="color: #000000; font-weight: bold;">/</span>a.out
<span style="color: #000000;">1</span>
<span style="color: #000000;">5</span>
<span style="color: #000000;">10</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">&#91;</span>print<span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000;">1</span>
<span style="color: #000000;">5</span>
<span style="color: #000000;">10</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">&#91;</span>rprint<span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000;">10</span>
<span style="color: #000000;">5</span>
<span style="color: #000000;">1</span></pre></td></tr></table></div>

</li>
</ol>
<p>autoに関しては多用すると可読性を損なう可能性がありますが、STLのコンテナクラスをイテレートする場合には可読性が上がっていい感じかなと思います。</p>
<h3>あわせて読みたい</h3>
<ul>
<li><a href="http://blog.eni.co.jp/tech/2009/05/cpp0x_date_extended_manipulators.html">C++0xでの日付の書式付入出力の仕組み</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.eni.co.jp/tech/2009/08/ubuntu-gcc-cpp0x-getting-started.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://blog.eni.co.jp/tech/2009/08/ubuntu-gcc-cpp0x-getting-started.html" />
	</item>
		<item>
		<title>C++0xでの日付の書式付入出力の仕組み</title>
		<link>http://blog.eni.co.jp/tech/2009/05/cpp0x_date_extended_manipulators.html</link>
		<comments>http://blog.eni.co.jp/tech/2009/05/cpp0x_date_extended_manipulators.html#comments</comments>
		<pubDate>Wed, 27 May 2009 06:14:45 +0000</pubDate>
		<dc:creator>青野 和仁</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[プログラム]]></category>
		<category><![CDATA[C++0x]]></category>
		<category><![CDATA[N2071]]></category>
		<category><![CDATA[STL]]></category>
		<category><![CDATA[テンプレート]]></category>

		<guid isPermaLink="false">http://blog.eni.co.jp/tech/?p=374</guid>
		<description><![CDATA[はじめまして。
プロダクト&#38;サービス事業部リーダーの青野です。
今日は少し古くマイナーな情報になりますが、
C++0xで追加される拡張マニピュレーターを使用した日付の書式付入出力[N2071](Apache C++ Standard Libraryから追加)の仕組み
について書こうと思います。
C++での開発経験がある人はjavaのDateFormatのように

(任意の書式の)日付文字列からDateオブジェクトの生成
Dateオブジェクトから(任意の書式の)日付文字列の生成

を、簡単に行いたいと、1度は悩んだことがあるのではないでしょうか。
Linux環境であれば、strptime(日付文字列 &#62; tm構造体)、strftime(tm構造体 &#62; 日付文字列)という便利なCの関数があり、
この関数をラップするだけでも簡単に汎用的な処理を実装することができますが、C++0xでは標準で行うことが可能になります。
    Working Draft, Standard for Programming Language C++ (pp.1097-1099)

現状のC++での日付の書式付出力
現状のC++では、time_putファセットクラスを使用した日付の書式付出力のみが可能ですが、以下に示すようにやや煩雑になります。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include &#60;ctime&#62;
#include &#60;locale&#62;
#include &#60;iostream&#62;
&#160;
int main&#40;&#41; &#123;
    typedef std::ostreambuf_iterator&#60;char, std::char_traits&#60;char&#62; &#62; iter_type;
&#160;
    // tm構造体の作成
    std::tm tmb;
    tmb.tm_year = 109;
    tmb.tm_mon = 4;
  [...]]]></description>
			<content:encoded><![CDATA[<p>はじめまして。</p>
<p>プロダクト&amp;サービス事業部リーダーの青野です。</p>
<p>今日は少し古くマイナーな情報になりますが、<br />
C++0xで追加される拡張マニピュレーターを使用した日付の書式付入出力[<a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2071">N2071</a>](<a href="http://stdcxx.apache.org/">Apache C++ Standard Library</a>から追加)の仕組み<br />
について書こうと思います。</p>
<p>C++での開発経験がある人はjavaのDateFormatのように</p>
<ul>
<li>(任意の書式の)日付文字列からDateオブジェクトの生成</li>
<li>Dateオブジェクトから(任意の書式の)日付文字列の生成</li>
</ul>
<p>を、簡単に行いたいと、1度は悩んだことがあるのではないでしょうか。</p>
<p>Linux環境であれば、strptime(日付文字列 &gt; tm構造体)、strftime(tm構造体 &gt; 日付文字列)という便利なCの関数があり、<br />
この関数をラップするだけでも簡単に汎用的な処理を実装することができますが、C++0xでは標準で行うことが可能になります。</p>
<p>    <a href="http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2008/n2798.pdf">Working Draft, Standard for Programming Language C++ (pp.1097-1099)</a></p>
<p><span id="more-374"></span></p>
<h3>現状のC++での日付の書式付出力</h3>
<p>現状のC++では、time_putファセットクラスを使用した日付の書式付出力のみが可能ですが、以下に示すようにやや煩雑になります。</p>

<div class="wp_codebox"><table width="100%" ><tr id="p37428"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
</pre></td><td class="code" id="p374code28"><pre class="cpp" style="font-family:monospace;"><span style="color: #339900;">#include &lt;ctime&gt;</span>
<span style="color: #339900;">#include &lt;locale&gt;</span>
<span style="color: #339900;">#include &lt;iostream&gt;</span>
&nbsp;
<span style="color: #0000ff;">int</span> main<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
    <span style="color: #0000ff;">typedef</span> std<span style="color: #008080;">::</span><span style="color: #007788;">ostreambuf_iterator</span><span style="color: #000080;">&lt;</span><span style="color: #0000ff;">char</span>, std<span style="color: #008080;">::</span><span style="color: #007788;">char_traits</span><span style="color: #000080;">&lt;</span><span style="color: #0000ff;">char</span><span style="color: #000080;">&gt;</span> <span style="color: #000080;">&gt;</span> iter_type<span style="color: #008080;">;</span>
&nbsp;
    <span style="color: #666666;">// tm構造体の作成</span>
    std<span style="color: #008080;">::</span><span style="color: #0000ff;">tm</span> tmb<span style="color: #008080;">;</span>
    tmb.<span style="color: #007788;">tm_year</span> <span style="color: #000080;">=</span> <span style="color: #0000dd;">109</span><span style="color: #008080;">;</span>
    tmb.<span style="color: #007788;">tm_mon</span> <span style="color: #000080;">=</span> <span style="color: #0000dd;">4</span><span style="color: #008080;">;</span>
    tmb.<span style="color: #007788;">tm_mday</span> <span style="color: #000080;">=</span> <span style="color: #0000dd;">27</span>
&nbsp;
    <span style="color: #666666;">// time_putを使用する為の準備</span>
    iter_type it<span style="color: #008000;">&#40;</span>std<span style="color: #008080;">::</span><span style="color: #0000dd;">cout</span>.<span style="color: #007788;">rdbuf</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #0000ff;">char</span><span style="color: #000040;">*</span> fmt <span style="color: #000080;">=</span> <span style="color: #FF0000;">&quot;%Y : %m : %d&quot;</span><span style="color: #008080;">;</span>
    <span style="color: #0000ff;">char</span><span style="color: #000040;">*</span> end <span style="color: #000080;">=</span> fmt <span style="color: #000040;">+</span> std<span style="color: #008080;">::</span><span style="color: #007788;">char_traits</span><span style="color: #000080;">&lt;</span><span style="color: #0000ff;">char</span><span style="color: #000080;">&gt;</span><span style="color: #008080;">::</span><span style="color: #007788;">length</span><span style="color: #008000;">&#40;</span>fmt<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #0000ff;">const</span> std<span style="color: #008080;">::</span><span style="color: #007788;">time_put</span><span style="color: #000080;">&lt;</span><span style="color: #0000ff;">char</span>,iter_type<span style="color: #000080;">&gt;</span><span style="color: #000040;">&amp;</span> tp <span style="color: #000080;">=</span> std<span style="color: #008080;">::</span><span style="color: #007788;">use_facet</span><span style="color: #000080;">&lt;</span>std<span style="color: #008080;">::</span><span style="color: #007788;">time_put</span><span style="color: #000080;">&lt;</span><span style="color: #0000ff;">char</span>,iter_type<span style="color: #000080;">&gt;</span> <span style="color: #000080;">&gt;</span><span style="color: #008000;">&#40;</span>std<span style="color: #008080;">::</span><span style="color: #0000dd;">cout</span>.<span style="color: #007788;">getloc</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
    <span style="color: #666666;">// 日付の書式付出力</span>
    it <span style="color: #000080;">=</span> tp.<span style="color: #007788;">put</span><span style="color: #008000;">&#40;</span>it, std<span style="color: #008080;">::</span><span style="color: #0000dd;">cout</span>, std<span style="color: #008080;">::</span><span style="color: #0000dd;">cout</span>.<span style="color: #007788;">fill</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>, <span style="color: #000040;">&amp;</span>tmb, fmt, end<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    std<span style="color: #008080;">::</span><span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> std<span style="color: #008080;">::</span><span style="color: #007788;">endl</span><span style="color: #008080;">;</span>
&nbsp;
    <span style="color: #0000ff;">return</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<pre>
実行結果

2009 : 05 : 27
</pre>
<h3>C++0xでの日付の書式付入出力</h3>
<dl>
<dt>日付文字列 &gt; tm構造体の変換</dt>
<dd>

<div class="wp_codebox"><table width="100%" ><tr id="p37429"><td class="code" id="p374code29"><pre class="cpp" style="font-family:monospace;">basic_istream<span style="color: #000080;">&lt;</span>charT, traits<span style="color: #000080;">&gt;</span><span style="color: #000040;">&amp;</span> <span style="color: #000080;">&gt;&gt;</span>get_time<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">tm</span>構造体のポインタ, 日付書式指定<span style="color: #008000;">&#41;</span></pre></td></tr></table></div>

</dd>
<dt>tm構造体 &gt; 日付文字列の変換</dt>
<dd>

<div class="wp_codebox"><table width="100%" ><tr id="p37430"><td class="code" id="p374code30"><pre class="cpp" style="font-family:monospace;">basic_ostream<span style="color: #000080;">&lt;</span>charT, traits<span style="color: #000080;">&gt;</span><span style="color: #000040;">&amp;</span> <span style="color: #000080;">&lt;&lt;</span>put_time<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">tm</span>構造体のポインタ, 日付書式指定<span style="color: #008000;">&#41;</span></pre></td></tr></table></div>

</dd>
</dl>
<p>C++0xでは、おそらく下記のコードで実行できるようになると思います。</p>
<p>実際のC++0xでは実装は異なると思いますが、<a href="http://stdcxx.apache.org/">Apache C++ Standard Library</a>と<a href="http://svn.apache.org/repos/asf/stdcxx/trunk/examples/manual/time_manip.cpp">こちら</a>を元に日付の書式付入出力を簡単に紐といてみたいと思います。</p>

<div class="wp_codebox"><table width="100%" ><tr id="p37431"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
</pre></td><td class="code" id="p374code31"><pre class="cpp" style="font-family:monospace;"><span style="color: #339900;">#include &lt;ctime&gt;</span>
<span style="color: #339900;">#include &lt;locale&gt;</span>
<span style="color: #339900;">#include &lt;iostream&gt;</span>
&nbsp;
<span style="color: #0000ff;">int</span> main<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span>
    <span style="color: #0000ff;">typedef</span> std<span style="color: #008080;">::</span><span style="color: #007788;">ostreambuf_iterator</span><span style="color: #000080;">&lt;</span><span style="color: #0000ff;">char</span>, std<span style="color: #008080;">::</span><span style="color: #007788;">char_traits</span><span style="color: #000080;">&lt;</span><span style="color: #0000ff;">char</span><span style="color: #000080;">&gt;</span> <span style="color: #000080;">&gt;</span> iter_type<span style="color: #008080;">;</span>
&nbsp;
    <span style="color: #666666;">// tm構造体の作成</span>
    std<span style="color: #008080;">::</span><span style="color: #0000ff;">tm</span> tmb<span style="color: #008080;">;</span>
    tmb.<span style="color: #007788;">tm_year</span> <span style="color: #000080;">=</span> <span style="color: #0000dd;">109</span><span style="color: #008080;">;</span>
    tmb.<span style="color: #007788;">tm_mon</span> <span style="color: #000080;">=</span> <span style="color: #0000dd;">4</span><span style="color: #008080;">;</span>
    tmb.<span style="color: #007788;">tm_mday</span> <span style="color: #000080;">=</span> <span style="color: #0000dd;">27</span>
&nbsp;
    <span style="color: #666666;">// 日付の書式付出力</span>
    std<span style="color: #008080;">::</span><span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> put_time<span style="color: #008000;">&#40;</span><span style="color: #000040;">&amp;</span>tmb, <span style="color: #FF0000;">&quot;%Y : %m : %d&quot;</span><span style="color: #008000;">&#41;</span> <span style="color: #000080;">&lt;&lt;</span> std<span style="color: #008080;">::</span><span style="color: #007788;">endl</span><span style="color: #008080;">;</span>
&nbsp;
    <span style="color: #0000ff;">return</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<h3>time_getファセットクラスの拡張</h3>
<p><a href="http://stdcxx.apache.org/">Apache C++ Standard Library</a>では、日付の書式付入出力を行えるように、time_getファセットクラスにget、do_getメソッドが追加で実装されていて、追加されたgetメソッドで日付文字列 &gt; tm構造体への変換が行われます。</p>

<div class="wp_codebox"><table width="100%" ><tr id="p37432"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
</pre></td><td class="code" id="p374code32"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">namespace</span> std <span style="color: #008000;">&#123;</span>
&nbsp;
  <span style="color: #0000ff;">template</span> <span style="color: #000080;">&lt;</span><span style="color: #0000ff;">class</span> charT, <span style="color: #0000ff;">class</span> InputIterator <span style="color: #000080;">=</span> istreambuf_iterator<span style="color: #000080;">&lt;</span>charT<span style="color: #000080;">&gt;</span> <span style="color: #000080;">&gt;</span>
  <span style="color: #0000ff;">class</span> time_get <span style="color: #008080;">:</span> <span style="color: #0000ff;">public</span> locale<span style="color: #008080;">::</span><span style="color: #007788;">facet</span>, <span style="color: #0000ff;">public</span> time_base <span style="color: #008000;">&#123;</span>
  <span style="color: #0000ff;">public</span><span style="color: #008080;">:</span>
    ...
    <span style="color: #666666;">// extension of this implementation </span>
    iter_type get <span style="color: #008000;">&#40;</span>iter_type, iter_type, ios_base<span style="color: #000040;">&amp;</span>, ios_base<span style="color: #008080;">::</span><span style="color: #007788;">iostate</span><span style="color: #000040;">&amp;</span>, <span style="color: #0000ff;">tm</span><span style="color: #000040;">*</span>, <span style="color: #0000ff;">const</span> char_type<span style="color: #000040;">*</span>, <span style="color: #0000ff;">const</span> char_type<span style="color: #000040;">*</span><span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">const</span><span style="color: #008080;">;</span> 
    <span style="color: #666666;">// extension of this implementation </span>
    iter_type get <span style="color: #008000;">&#40;</span>iter_type, iter_type, ios_base<span style="color: #000040;">&amp;</span>, ios_base<span style="color: #008080;">::</span><span style="color: #007788;">iostate</span><span style="color: #000040;">&amp;</span>, <span style="color: #0000ff;">tm</span><span style="color: #000040;">*</span>, <span style="color: #0000ff;">char</span>, <span style="color: #0000ff;">char</span><span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">const</span><span style="color: #008080;">;</span>
    ...
  <span style="color: #0000ff;">protected</span><span style="color: #008080;">:</span>
    ...
    <span style="color: #666666;">// extension of this implementation </span>
    <span style="color: #0000ff;">virtual</span> iter_type 
    do_get <span style="color: #008000;">&#40;</span>iter_type, iter_type, ios_base<span style="color: #000040;">&amp;</span>, ios_base<span style="color: #008080;">::</span><span style="color: #007788;">iostate</span><span style="color: #000040;">&amp;</span>, <span style="color: #0000ff;">tm</span><span style="color: #000040;">*</span>, <span style="color: #0000ff;">char</span>, <span style="color: #0000ff;">char</span><span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">const</span><span style="color: #008080;">;</span>
  <span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span>
&nbsp;
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

<p>この拡張されたtime_get、time_putファセットクラスを直接実行すればこのままでも、C++の標準の機能として日付の書式付入出力を行うことが出来ますが、実際に使うには最初に例を示したようにやや煩雑になります。</p>

<div class="wp_codebox"><table width="100%" ><tr id="p37433"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p374code33"><pre class="cpp" style="font-family:monospace;">basic_istream<span style="color: #000080;">&lt;</span>charT, traits<span style="color: #000080;">&gt;</span><span style="color: #000040;">&amp;</span> <span style="color: #000080;">&gt;&gt;</span>get_time<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">tm</span>構造体のポインタ, 日付書式指定<span style="color: #008000;">&#41;</span></pre></td></tr></table></div>


<div class="wp_codebox"><table width="100%" ><tr id="p37434"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p374code34"><pre class="cpp" style="font-family:monospace;">basic_ostream<span style="color: #000080;">&lt;</span>charT, traits<span style="color: #000080;">&gt;</span><span style="color: #000040;">&amp;</span> <span style="color: #000080;">&lt;&lt;</span>put_time<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">tm</span>構造体のポインタ, 日付書式指定<span style="color: #008000;">&#41;</span></pre></td></tr></table></div>

<p>上記のように簡単に実行する為の仕組みを以降で記載します。</p>
<h3>time_get、time_put用マニピュレータクラス</h3>
<p>time_get、time_putファセットクラスには、それぞれ専用のマニピュレータクラスが定義されています。<br />
このマニピュレータクラスのoperator()内で、やや煩雑であったそれぞれのファセットクラスをインスタンス化し、ストリームに対して日付の書式付入出力を行う部分が実装されています。</p>

<div class="wp_codebox"><table width="100%" ><tr id="p37435"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code" id="p374code35"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">template</span> <span style="color: #000080;">&lt;</span><span style="color: #0000ff;">class</span> charT<span style="color: #000080;">&gt;</span>
<span style="color: #0000ff;">struct</span> time_get_manip <span style="color: #008000;">&#123;</span>
    std<span style="color: #008080;">::</span><span style="color: #0000ff;">tm</span> <span style="color: #000040;">*</span>tmb_<span style="color: #008080;">;</span>
&nbsp;
    <span style="color: #0000ff;">explicit</span> time_get_manip <span style="color: #008000;">&#40;</span>std<span style="color: #008080;">::</span><span style="color: #0000ff;">tm</span> <span style="color: #000040;">*</span>tmb<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
    <span style="color: #0000ff;">template</span> <span style="color: #000080;">&lt;</span><span style="color: #0000ff;">class</span> Traits<span style="color: #000080;">&gt;</span>
    <span style="color: #0000ff;">void</span> operator<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#40;</span>std<span style="color: #008080;">::</span><span style="color: #007788;">basic_istream</span><span style="color: #000080;">&lt;</span>charT, Traits<span style="color: #000080;">&gt;</span><span style="color: #000040;">&amp;</span>, <span style="color: #0000ff;">const</span> charT<span style="color: #000040;">*</span><span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">const</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span></pre></td></tr></table></div>


<div class="wp_codebox"><table width="100%" ><tr id="p37436"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code" id="p374code36"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">template</span> <span style="color: #000080;">&lt;</span><span style="color: #0000ff;">class</span> charT<span style="color: #000080;">&gt;</span>
<span style="color: #0000ff;">struct</span> time_put_manip <span style="color: #008000;">&#123;</span>
    <span style="color: #0000ff;">const</span> std<span style="color: #008080;">::</span><span style="color: #0000ff;">tm</span> <span style="color: #000040;">*</span>tmb_<span style="color: #008080;">;</span>
&nbsp;
    <span style="color: #0000ff;">explicit</span> time_put_manip <span style="color: #008000;">&#40;</span><span style="color: #0000ff;">const</span> std<span style="color: #008080;">::</span><span style="color: #0000ff;">tm</span> <span style="color: #000040;">*</span>tmb<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
    <span style="color: #0000ff;">template</span> <span style="color: #000080;">&lt;</span><span style="color: #0000ff;">class</span> Traits<span style="color: #000080;">&gt;</span>
    <span style="color: #0000ff;">void</span> operator<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#40;</span>std<span style="color: #008080;">::</span><span style="color: #007788;">basic_ostream</span><span style="color: #000080;">&lt;</span>charT, Traits<span style="color: #000080;">&gt;</span><span style="color: #000040;">&amp;</span>, <span style="color: #0000ff;">const</span> charT<span style="color: #000040;">*</span><span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">const</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span></pre></td></tr></table></div>

<h3>iomanipの拡張</h3>
<p><a href="http://stdcxx.apache.org/">Apache C++ Standard Library</a>では、実際の処理はテンプレートパラメータで指定されたマニピュレータクラスのoperator()を実行する__rw_smanipクラスが実装されています。__rw_smanipクラスはテンプレートパラメータを変更することにより、いろいろなマニピュレータクラスのoperator()を実行できる汎用的なクラスです。<a href="http://stdcxx.apache.org/">Apache C++ Standard Library</a>では、setw(内部では_Setw)等の標準のマニピュレータクラスもこの__rw_smanipクラスを使用しています。</p>

<div class="wp_codebox"><table width="100%" ><tr id="p37437"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
</pre></td><td class="code" id="p374code37"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">template</span> <span style="color: #000080;">&lt;</span><span style="color: #0000ff;">class</span> _Functor, <span style="color: #0000ff;">class</span> _TypeT<span style="color: #000080;">&gt;</span>
<span style="color: #0000ff;">struct</span> __rw_smanip <span style="color: #008000;">&#123;</span>
    <span style="color: #0000ff;">explicit</span> __rw_smanip <span style="color: #008000;">&#40;</span>_TypeT __arg<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    __rw_smanip <span style="color: #008000;">&#40;</span>_Functor __fun, _TypeT __arg<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
    _Functor _C_fun<span style="color: #008080;">;</span>
    _TypeT   _C_arg<span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span>
&nbsp;
<span style="color: #0000ff;">template</span> <span style="color: #000080;">&lt;</span><span style="color: #0000ff;">class</span> _CharT, <span style="color: #0000ff;">class</span> _Traits, <span style="color: #0000ff;">class</span> _Functor, <span style="color: #0000ff;">class</span> _TypeT<span style="color: #000080;">&gt;</span>
<span style="color: #0000ff;">inline</span> basic_istream<span style="color: #000080;">&lt;</span>_CharT, _Traits<span style="color: #000080;">&gt;</span><span style="color: #000040;">&amp;</span>
operator<span style="color: #000080;">&gt;&gt;</span> <span style="color: #008000;">&#40;</span>basic_istream<span style="color: #000080;">&lt;</span>_CharT, _Traits<span style="color: #000080;">&gt;</span> <span style="color: #000040;">&amp;</span>__strm, <span style="color: #0000ff;">const</span> __rw_smanip<span style="color: #000080;">&lt;</span>_Functor, _TypeT<span style="color: #000080;">&gt;</span> <span style="color: #000040;">&amp;</span>__man<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
<span style="color: #0000ff;">template</span> <span style="color: #000080;">&lt;</span><span style="color: #0000ff;">class</span> _CharT, <span style="color: #0000ff;">class</span> _Traits, <span style="color: #0000ff;">class</span> _Functor, <span style="color: #0000ff;">class</span> _TypeT<span style="color: #000080;">&gt;</span>
<span style="color: #0000ff;">inline</span> basic_ostream<span style="color: #000080;">&lt;</span>_CharT, _Traits<span style="color: #000080;">&gt;</span><span style="color: #000040;">&amp;</span>
operator<span style="color: #000080;">&lt;&lt;</span> <span style="color: #008000;">&#40;</span>basic_ostream<span style="color: #000080;">&lt;</span>_CharT, _Traits<span style="color: #000080;">&gt;</span> <span style="color: #000040;">&amp;</span>__strm, <span style="color: #0000ff;">const</span> __rw_smanip<span style="color: #000080;">&lt;</span>_Functor, _TypeT<span style="color: #000080;">&gt;</span> <span style="color: #000040;">&amp;</span>__man<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span></pre></td></tr></table></div>

<h3>__rw_smanipクラス生成ヘルパ関数の定義</h3>
<p>tm構造体と、日付書式を指定すれば、time_get、time_putファセットクラスのoperator()を実行する__rw_smainipクラスが生成されます。この関数が実際に日付の書式付入出力を行う際に使用されることになります。</p>

<div class="wp_codebox"><table width="100%" ><tr id="p37438"><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code" id="p374code38"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">template</span> <span style="color: #000080;">&lt;</span><span style="color: #0000ff;">class</span> charT<span style="color: #000080;">&gt;</span>
<span style="color: #0000ff;">inline</span> std<span style="color: #008080;">::</span>__rw_smanip<span style="color: #000080;">&lt;</span>time_get_manip<span style="color: #000080;">&lt;</span>charT<span style="color: #000080;">&gt;</span>, <span style="color: #0000ff;">const</span> charT<span style="color: #000040;">*</span><span style="color: #000080;">&gt;</span>
get_time <span style="color: #008000;">&#40;</span>std<span style="color: #008080;">::</span><span style="color: #0000ff;">tm</span> <span style="color: #000040;">*</span>tmb, <span style="color: #0000ff;">const</span> charT <span style="color: #000040;">*</span>fmt<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span></pre></td></tr></table></div>


<div class="wp_codebox"><table width="100%" ><tr id="p37439"><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code" id="p374code39"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">template</span> <span style="color: #000080;">&lt;</span><span style="color: #0000ff;">class</span> charT<span style="color: #000080;">&gt;</span>
<span style="color: #0000ff;">inline</span> std<span style="color: #008080;">::</span>__rw_smanip<span style="color: #000080;">&lt;</span>time_put_manip<span style="color: #000080;">&lt;</span>charT<span style="color: #000080;">&gt;</span>, <span style="color: #0000ff;">const</span> charT<span style="color: #000040;">*</span><span style="color: #000080;">&gt;</span>
put_time <span style="color: #008000;">&#40;</span><span style="color: #0000ff;">const</span> std<span style="color: #008080;">::</span><span style="color: #0000ff;">tm</span> <span style="color: #000040;">*</span>tmb, <span style="color: #0000ff;">const</span> charT <span style="color: #000040;">*</span>fmt<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span></pre></td></tr></table></div>

<h3>まとめ</h3>
<p>上記で記載したクラス、関数を使用してtime_get、time_putファセットクラスを簡単に使うことが出来るようになります。</p>

<div class="wp_codebox"><table width="100%" ><tr id="p37440"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p374code40"><pre class="cpp" style="font-family:monospace;">std<span style="color: #008080;">::</span><span style="color: #0000dd;">cout</span> <span style="color: #000080;">&lt;&lt;</span> put_time <span style="color: #008000;">&#40;</span>tmb, put_fmt<span style="color: #008000;">&#41;</span> <span style="color: #000080;">&lt;&lt;</span> std<span style="color: #008080;">::</span><span style="color: #007788;">endl</span><span style="color: #008080;">;</span></pre></td></tr></table></div>

<p>※tmbは、tm構造体のポインタ<br />
※put_fmtは日付書式文字列</p>
<p>上記のコードの場合、各クラス、関数は以下のように実行され、ストリームに対して日付の書式付出力が行われることになります。</p>
<ol>
<li>put_timeヘルパ関数によりtime_put_manipクラスをファンクタとする__rw_smanipクラスが生成される</li>
<li>operator<<の定義により、__rw_smanipの_C_funメソッド(time_put_manipのoperator())が実行される</li>
<li>time_put_manipのoperator()内でtime_putにより、ストリームに対して日付の書式付出力が行われる</li>
</ol>
<p>以上内容的には浅いですが、C++0xの日付の書式付入出力の仕組みです。<br />
他にもC++0xでは有用な機能(スレッド等)がいろいろ追加されます。C++0xのリリースが待ち遠しいですね!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.eni.co.jp/tech/2009/05/cpp0x_date_extended_manipulators.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<xhtml:link rel="alternate" media="handheld" type="text/html" href="http://blog.eni.co.jp/tech/2009/05/cpp0x_date_extended_manipulators.html" />
	</item>
	</channel>
</rss>
