{"id":1960,"date":"2010-04-01T23:58:00","date_gmt":"2010-04-01T14:58:00","guid":{"rendered":"https:\/\/hdmr.org\/d\/?e=713"},"modified":"2010-04-01T23:58:00","modified_gmt":"2010-04-01T14:58:00","slug":"blogn-713","status":"publish","type":"post","link":"https:\/\/hdmr.org\/d\/?e=713","title":{"rendered":"move\u3057\u305f\u308aforward\u3057\u305f\u308a\u3059\u308bC++0x"},"content":{"rendered":"<p>\u4eca\u65e5\u306f\u91ce\u826f\u4ed5\u4e8b\u3092\u3057\u306b\u884c\u3063\u3066\u3044\u305f\u308f\u3051\u3060\u304c\u3001\u307e\u3041\u3053\u306e\u3053\u3068\u306f\u5f8c\u306b\u66f8\u304f\u3068\u3057\u3088\u3046\u3002<\/p>\n<p>\u6b63\u5473\u306e\u4ed5\u4e8b\u306f3\u6642\u9593\u307b\u3069\u3060\u3063\u305f\u306e\u3067\u5927\u3057\u305f\u3053\u3068\u306f\u306a\u304b\u3063\u305f\u304c\u3001\u3053\u308c\u3067\u3082\u304b\u306a\u308a\u306e\u52b9\u679c\u306f\u3042\u3063\u305f\u3088\u3046\u3067\u3002<\/p>\n<p>\u624b\u4f1d\u3044\u306b\u884c\u3063\u305f\u610f\u5473\u3082\u3042\u3063\u305f\u3082\u306e\u3060\u3002<\/p>\n<hr \/>\n<p>C++0x\u3084\u308b\u304b\u3068\u601d\u3063\u3066\u3001\u6539\u3081\u3066Visual Studio 2010\u306eBeta\u7248\u3092\u5165\u308c\u3066\u307f\u305f\u3002\u4eca\u306e\u3068\u3053\u308d\u4e00\u756a\u3044\u3051\u3066\u308b\u30b3\u30f3\u30d1\u30a4\u30e9\u3060\u3068\u601d\u3046\u3002(\u53c2\u8003\u8a18\u4e8b : <a href=\".\/?e=464\">C++0x\u306e\u5316\u3051\u7269\u3058\u307f\u305f\u53f3\u8fba\u5024\u53c2\u7167<\/a>)<\/p>\n<p>\u3053\u308c\u3092\u898b\u308b\u3068\u7d50\u69cb\u3044\u308d\u3044\u308d\u306a\u6a5f\u80fd\u306b\u5bfe\u5fdc\u3057\u3066\u3044\u308b\u306d\u3002\u306a\u304b\u306a\u304b\u3088\u3044\u3002<\/p>\n<p>\u305d\u306e\u4e0a\u3067\u3044\u308d\u3044\u308d\u8a66\u3057\u3066\u3044\u305f\u306e\u3060\u304c\u3001\u304a\u3082\u3057\u308d\u3044\u3053\u3068\u3082\u3042\u308b\u3082\u3093\u3060\u3002<\/p>\n<hr \/>\n<p>std::unique_ptr\u3068\u3044\u3046\u53f3\u8fba\u5024\u53c2\u7167\u3092\u6d3b\u7528\u3057\u305f\u30b9\u30de\u30fc\u30c8\u30dd\u30a4\u30f3\u30bf\u304c\u3042\u308b\u306e\u3060\u304c\u3001\u3053\u308c\u3063\u3066\u30b3\u30f3\u30c6\u30ca\u306b\u5165\u308c\u3089\u308c\u305f\u304b\u306a\u3068\u601d\u3063\u3066\u5b9f\u9a13\u3057\u3066\u307f\u305f\u3002<\/p>\n<pre>std::vector&lt;std::unique_ptr&lt;std::string&gt;&gt; v(1);\nstd::unique_ptr&lt;std::string&gt; p1(new std::string(\"hage\"));\nv.at(0)=std::move(p1);\nv.push_back(std::unique_ptr&lt;std::string&gt;(new std::string(\"hoge\")));<\/pre>\n<p>\u306a\u3093\u304b\u5e73\u7136\u3068\u5165\u308c\u3089\u308c\u308b\u3057\u3002<\/p>\n<p>std::move\u4ed8\u3051\u5fd8\u308c\u308b\u3068\u3069\u3046\u306a\u308b\u304b\u3063\u3066\u8a71\u3067\u3059\u304c\u3001\u3078\u3093\u306a\u30a8\u30e9\u30fc\u304c\u51fa\u3066\u30b3\u30f3\u30d1\u30a4\u30eb\u306b\u5931\u6557\u3059\u308b\u3002<\/p>\n<p>\u307e\u3041\u3057\u304b\u3057\u3053\u308c\u304c\u3044\u3051\u308b\u306a\u3089shared_ptr\u3088\u308a\u3082\u30b7\u30f3\u30d7\u30eb\u3067\u3044\u3044\u3088\u306d\u3002unique_ptr\u4e07\u6b73!<\/p>\n<p>\u3053\u308c\u3092\u56de\u3059\u3068\u304d\u3067\u3059\u304c\u3001\u305b\u3063\u304b\u304f\u306a\u306e\u3067for_each\u3057\u3066\u307f\u305f\u3002<\/p>\n<pre>std::for_each(v.begin(),v.end(),[](std::unique_ptr&lt;std::string&gt;&amp; p){\n  std::cout &lt;&lt; *p &lt;&lt; std::endl;\n});<\/pre>\n<p>shared_ptr\u3068\u9055\u3063\u3066\u30b3\u30d4\u30fc\u3067\u304d\u306a\u3044\u306e\u3067\u53c2\u7167\u6e21\u3057\u3057\u306a\u3044\u3068\u306a\u3089\u3093\u3002const\u306f\u5fc5\u8981\u306b\u5fdc\u3058\u3066\u3069\u3046\u305e\u3002<\/p>\n<p>\u679c\u305f\u3057\u3066\u3053\u3046\u8a00\u3046\u306e\u304c\u4fbf\u5229\u306a\u306e\u304b\u3068\u8a00\u308f\u308c\u308b\u3068\u96e3\u3057\u3044\u304c\u3001\u4ed6\u306e\u3068\u3053\u308d\u306b\u30b3\u30d4\u30fc\u3057\u3066\u6e21\u3059\u6c17\u3055\u3048\u306a\u3051\u308c\u3070\u3044\u3044\u3093\u3058\u3083\u306a\u3044\u306e\u3002<\/p>\n<hr \/>\n<p>\u3055\u3066\u3001\u3082\u3046\u5de6\u8fba\u5024\u3092\u7834\u58ca\u3057\u3066\u3057\u307e\u3063\u3066\u3082\u304b\u307e\u308f\u306a\u3044\u3068\u304d\u306b\u306fstd::move\u3092\u4f7f\u3046\u306e\u3067\u3059\u304c\u3001std::forward\u3068\u3044\u3046\u306e\u3082\u3042\u308b\u3002<\/p>\n<p>\u3053\u308c\u306f\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u306b\u95a2\u4fc2\u304c\u3042\u308b\u3002<\/p>\n<pre>template &lt;typename T&gt;\nTest TestCreator(T&amp;&amp; other){\n  return Test(other);\n}<\/pre>\n<p>\u3053\u3093\u306a\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u95a2\u6570\u304c\u3042\u3063\u305f\u3068\u304d\u3001T\u306e\u578b\u540d\u306f\u81ea\u52d5\u3067\u63a8\u8ad6\u3055\u308c\u308b\u3002<\/p>\n<p>\u3082\u3057Test\u578b\u306e\u53f3\u8fba\u5024\u3092\u6e21\u305b\u3070T=Test\u3068\u306a\u308b\u306e\u306f\u5bb9\u6613\u306b\u4e88\u60f3\u3067\u304d\u308b\u3002<\/p>\n<p>\u3068\u3053\u308d\u304cTest\u578b\u306e\u5de6\u8fba\u5024\u3092\u6e21\u3059\u3068T=Test&amp;\u3068\u306a\u3063\u3066\u3053\u306e\u30c6\u30f3\u30d7\u30ec\u30fc\u30c8\u304c\u4f7f\u308f\u308c\u308b\u3002<\/p>\n<p>\u306a\u3093\u3067\u3084\u306d\u3093\u3068\u3044\u3046\u8a71\u3060\u304cT&amp; &amp;\u3084T&amp; &amp;&amp;\u3084T&amp;&amp; &amp;\u306fT&amp;\u306b\u306a\u308b\u3068\u3044\u3046\u30eb\u30fc\u30eb\u304c\u3042\u308b\u3089\u3057\u304f\u3001Test&amp; &amp;&amp;\u306fTest&amp;\u3068\u540c\u3058\u610f\u5473\u306b\u306a\u3063\u3066\u3057\u307e\u3046\u304b\u3089\u3002<\/p>\n<p>\u307e\u3041\u306a\u3093\u306b\u305b\u3088\u3001\u3053\u3046\u66f8\u3044\u3066\u304a\u3051\u3070\u53f3\u8fba\u5024\u3082\u5de6\u8fba\u5024\u3082\u6b53\u8fce\u3068\u8a00\u3046\u3053\u3068\u306b\u306a\u308b\u3002<\/p>\n<p>\u3053\u3053\u3067\u5143\u304c\u53f3\u8fba\u5024\u306a\u3089std::move\u3057\u305f\u3044\u304c\u3001\u5143\u304c\u53f3\u8fba\u5024\u3067\u3042\u308b\u304b\u30c1\u30a7\u30c3\u30af\u3057\u305f\u3044\u3068\u3002<\/p>\n<p>\u305d\u3053\u3067std::forward\u3067\u3001\u3053\u308c\u3092\u4f7f\u3046\u3053\u3068\u3067\u5224\u5225\u3057\u3066\u9069\u5f53\u306b\u3057\u3066\u304f\u308c\u308b\u3068\u3002<\/p>\n<pre>  return Test(std::forward&lt;T&gt;(other));<\/pre>\n<p>\u3053\u3093\u306a\u98a8\u306b\u66f8\u3051\u3070\u3001\u81ea\u52d5\u3067\u5224\u5b9a\u3057\u3066\u9069\u5f53\u306a\u51e6\u7406\u3092\u3057\u3066\u304f\u308c\u308b\u3002<\/p>\n<p>\u53f3\u8fba\u5024\u304b\u5de6\u8fba\u5024\u304b\u307e\u3067\u5b8c\u5168\u306b\u8ee2\u9001\u3059\u308b\u304b\u3089Perfect Forwarding\u306a\u3093\u3060\u3068\u3002<\/p>\n<p><a href=\"http:\/\/cpplover.blogspot.com\/2009\/11\/rvalue-reference_23.html\">rvalue reference \u5b8c\u5168\u89e3\u8aac (\u672c\u306e\u866b)<\/a><\/p>\n<p>\u3053\u308c\u3092\u898b\u3066\u521d\u3081\u3066\u7406\u89e3\u3067\u304d\u305f\u3002<\/p>\n<hr \/>\n<p>\u305d\u308c\u306b\u3057\u3066\u3082\u3053\u306e\u6a5f\u80fd\u306f\u3059\u3070\u3089\u3057\u3044\u306d\u3002C++0x\u3059\u3070\u3089\u3057\u3044\u3002<\/p>\n<p>\u3057\u304b\u3057\u305d\u3093\u306a\u98a8\u306b\u8a00\u3063\u3066\u307e\u3059\u304c\u3001C++0x\u306f2000\u5e74\u4ee3\u306b\u30ea\u30ea\u30fc\u30b9\u3067\u304d\u306a\u304b\u3063\u305f\u3093\u3067\u3059\u3088\u306d\u3002<\/p>\n<p>\u672c\u6765\u306a\u3089C++09\u307f\u305f\u3044\u306b\u306a\u308b\u306f\u305a\u3060\u3063\u305f\u306e\u306b\u5931\u6557\u3057\u3066\u3057\u307e\u3063\u305f\u3068\u3002<\/p>\n<p>\u679c\u305f\u3057\u3066\u3069\u3046\u3044\u3046\u65b9\u5411\u306b\u307e\u3068\u307e\u308b\u306e\u304b\u3002\u3067\u304d\u308b\u3060\u3051\u65e9\u304f\u307e\u3068\u3081\u3066\u307b\u3057\u3044\u3068\u3053\u308d\u3002<\/p>\n<p>\u4ee5\u4e0b\u306b\u7d20\u6674\u3089\u3057\u304f\u3066\u3082\u30b3\u30f3\u30d1\u30a4\u30e9\u304c\u5bfe\u5fdc\u3057\u3066\u306a\u3044\u3068\u4f7f\u3048\u306a\u3044\u3082\u3093\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4eca\u65e5\u306f\u91ce\u826f\u4ed5\u4e8b\u3092\u3057\u306b\u884c\u3063\u3066\u3044\u305f\u308f\u3051\u3060\u304c\u3001\u307e\u3041\u3053\u306e\u3053\u3068\u306f\u5f8c\u306b\u66f8\u304f\u3068\u3057\u3088\u3046\u3002 \u6b63\u5473\u306e\u4ed5\u4e8b\u306f3\u6642\u9593\u307b\u3069\u3060\u3063\u305f\u306e\u3067\u5927\u3057\u305f\u3053\u3068\u306f\u306a\u304b\u3063\u305f\u304c\u3001\u3053\u308c\u3067\u3082\u304b\u306a\u308a\u306e\u52b9\u679c\u306f\u3042\u3063\u305f\u3088\u3046\u3067\u3002 \u624b\u4f1d\u3044\u306b\u884c\u3063\u305f\u610f\u5473\u3082\u3042\u3063\u305f\u3082\u306e\u3060\u3002 C++0x\u3084\u308b\u304b [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-1960","post","type-post","status-publish","format-standard","hentry","category-computer"],"_links":{"self":[{"href":"https:\/\/hdmr.org\/d\/index.php?rest_route=\/wp\/v2\/posts\/1960","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hdmr.org\/d\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hdmr.org\/d\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hdmr.org\/d\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/hdmr.org\/d\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1960"}],"version-history":[{"count":0,"href":"https:\/\/hdmr.org\/d\/index.php?rest_route=\/wp\/v2\/posts\/1960\/revisions"}],"wp:attachment":[{"href":"https:\/\/hdmr.org\/d\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1960"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hdmr.org\/d\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1960"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hdmr.org\/d\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1960"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}