{"id":3594,"date":"2012-07-19T11:30:49","date_gmt":"2012-07-19T02:30:49","guid":{"rendered":"http:\/\/www.moonmile.net\/blog\/archives\/3594"},"modified":"2012-07-19T11:31:43","modified_gmt":"2012-07-19T02:31:43","slug":"c-c-%e3%81%a7-linq-%e3%82%92%e5%ae%9f%e8%a3%85%e3%81%97%e3%81%a6%e3%81%bf%e3%82%8b%e3%83%86%e3%82%b9%e3%83%88%ef%bc%88%e5%89%8d%e5%93%a8%e6%88%a6%ef%bc%89","status":"publish","type":"post","link":"http:\/\/www.moonmile.net\/blog\/archives\/3594","title":{"rendered":"[C++] C++ \u3067 LINQ \u3092\u5b9f\u88c5\u3057\u3066\u307f\u308b\u30c6\u30b9\u30c8\uff08\u524d\u54e8\u6226\uff09"},"content":{"rendered":"<p>\n\u3093\uff5e\u3001\u524d\u54e8\u6226\u3067\u7d42\u4e86\u3059\u308b\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u304c\u3001\u81ea\u5206\u306e\u52c9\u5f37\u304c\u3066\u3089\u3002\u3068\u3001\u4eca\u4f7f\u3063\u3066\u3044\u308b\u30b7\u30b9\u30c6\u30e0\u306b\u3067\u304d\u308c\u3070\u7d44\u307f\u5165\u308c\u305f\u3044\u306e\u3067\u3002<br \/>\n\u5c06\u6765\u7684\u306b LINQ for C++ \u304c\u3067\u304d\u305f\u3068\u3057\u3066\u3082\u3001VC++2010 \u306b\u7d44\u307f\u5165\u308c\u3089\u308c\u308b\u3068\u306f\u9650\u3089\u306a\u3044\u306e\u3067\u3001\u3084\u3080\u306a\u304f\u81ea\u4f5c\u3063\u3066\u3068\u3053\u308d\u3067\u3057\u3087\u3046\u304b\u3002\u5b9f\u9a13\u7684\u306a\u3082\u306e\u3067\u306a\u306e\u3067\u3001\u62e1\u5f35\u6027\/\u53ef\u8aad\u6027\u3092\u8003\u3048\u3066\u5c0e\u5165\u3059\u308b\u304b\u3069\u3046\u304b\u306f\u6c7a\u3081\u307e\u3057\u3087\u3046\u3001\u3068\u3044\u3046\u3053\u3068\u3067\u3002\n<\/p>\n<p>\n\u30e9\u30e0\u30c0\u5f0f\u3068 std::function \u304c\u4f7f\u3048\u308b\u3088\u3046\u306b\u306a\u3063\u305f\u304b\u3089\u3001\u3058\u3083\u3042\u3001LINQ \u3089\u3057\u3044\u30e1\u30bd\u30c3\u30c9\u30c1\u30a7\u30fc\u30f3\u306e\u65b9\u6cd5\u3092\u8a66\u3057\u3066\u307f\u305f\u3089\u3068\u601d\u3063\u3066\u3056\u3063\u3068\u66f8\u3044\u3066\u307f\u308b\u3068\u3002\n<\/p>\n<p>\nGoingNative 9: LINQ for C\/C++, Native Rx, Meet Aaron Lahman | C9::GoingNative | Channel 9<br \/>\n<a href=\"http:\/\/channel9.msdn.com\/Shows\/C9-GoingNative\/GoingNative-9-LINQ-for-C-Native-Rx-RxC-Meet-Aaron-Lahman\">http:\/\/channel9.msdn.com\/Shows\/C9-GoingNative\/GoingNative-9-LINQ-for-C-Native-Rx-RxC-Meet-Aaron-Lahman<\/a>\n<\/p>\n<p>\n\u3042\u3042\u3001\u78ba\u304b\u306b\u4e0a\u8a18\u3068\u540c\u3058\u65b9\u6cd5\u306b\u306a\u308a\u307e\u3059\u3002\n<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\n#include &lt;string&gt;\n#include &lt;iostream&gt;\n#include &lt;vector&gt;\n#include &lt;algorithm&gt;\n#include &lt;functional&gt;\n#include &lt;tuple&gt;\nusing namespace std;\n\nclass Vector : public vector&lt;int&gt; {\nprotected:\n\tVector *_v;\npublic:\n\tVector() :\n\t\t_v(NULL) {\n\t}\n\t~Vector() {\n\t\tif ( _v != NULL ) {\n\t\t\tdelete _v;\n\t\t}\n\t}\n\tVector &amp;From( vector&lt;int&gt; &amp;vec ) {\n\t\t\/\/ \u30a2\u30c3\u30d7\u30ad\u30e3\u30b9\u30c8\u3057\u3066\u308b\u304c\u3001\u4eca\u56de\u306f\u3053\u308c\u3067 ^^;\n\t\treturn *(Vector*)&amp;vec;\n\t}\n\tVector &amp;Where(function&lt;bool(int n)&gt; func) {\n\t\t\/\/ \u6bce\u56de new \u3057\u3066\u3044\u308b\u304c\u3001\u9045\u5ef6\u5b9f\u884c\u3055\u305b\u308b\u305f\u3081 iterator \u3092\u4f7f\u3046\u4e88\u5b9a\n\t\tif ( _v != NULL ) delete _v;\n\t\t_v = new Vector;\n\t\tfor_each( begin(), end(),\n\t\t\t&#x5B;=](int n) { if(func(n)) _v-&gt;push_back(n); });\n\t\treturn *_v;\n\t}\n\tVector &amp;Select(function&lt;int(int n)&gt; func) {\n\t\tif ( _v != NULL ) delete _v;\n\t\t_v = new Vector;\n\t\tfor_each( begin(), end(),\n\t\t\t&#x5B;=](int n) { _v-&gt;push_back(func(n)); });\n\t\treturn *_v;\n\t}\n};\n\n\nint main( void )\n{\n\tVector vec;\n\tfor ( int i=0; i&lt;10; i++ ) {\n\t\tvec.push_back( i );\n\t}\n\t\n\tauto query =\n\t\tvec.Where(&#x5B;](int &amp;n)-&gt;bool{ return n % 2 == 0 ; })\n\t\t.Select(&#x5B;](int &amp;n)-&gt;int{ return n*10 ; });\n\t\t\n\tfor_each( query.begin(), query.end(),\n\t\t&#x5B;](int n) { cout &lt;&lt; n &lt;&lt; endl; });\n}\n<\/pre>\n<p>\n\u809d\u5fc3\u306e\u300c\u9045\u5ef6\u8a55\u4fa1\u300d\u304c\u3067\u304d\u3066\u3044\u306a\u3044\u306e\u3067\u3001LINQ \u3068\u306f\u8a00\u3048\u307e\u305b\u3093\u304c\u3001\u307e\u3042\u3001\u8868\u9762\u4e0a\u306f\u30b3\u30f3\u30d1\u30a4\u30eb\u304c\u901a\u308b\u3057\u3001\u5b9f\u884c\u3082\u6b63\u5e38\u3002\n<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\nD:\\work\\blog\\src\\alice&gt;lamda001\n0\n20\n40\n60\n80\n<\/pre>\n<p>\n_v = new Vector() \u3057\u3066\u304b\u3089 return *_v \u3067 method chain \u3092\u5b9f\u73fe\u3057\u3066\u3044\u308b\u3093\u3067\u3059\u304c\u3001\u3053\u308c memory leak \u3057\u3066\u306a\u3044\u304b\uff1f\u3068\u601d\u3063\u305f\u306e\u3067\u3059\u304c\u3001\u8abf\u3079\u308b\u3068\u30ea\u30fc\u30af\u3057\u3066\u307e\u305b\u3093\u306d\u3002\u53c2\u7167\u3067\u8fd4\u3057\u3066\u3044\u308b\u306e\u3067\u30d6\u30ed\u30c3\u30af\u5916\u306b\u51fa\u308b\u3068\u81ea\u52d5\u7684\u306b\u89e3\u653e\u3055\u308c\u3066\u3044\u307e\u3059\u3002\n<\/p>\n<p>\n\u5143\u3005\u306e vecotr<int> \u3067\u306f\u306a\u304f\u3066\u3001Vector \u3092\u4f7f\u308f\u306a\u3044\u3068\u99c4\u76ee\u306a\u306e\u306f\u3001\u99c4\u76ee\u99c4\u76ee\u306a\u306e\u3067\u3053\u308c\u306f\u306a\u3093\u3068\u304b\u3057\u306a\u3044\u3068\u3002<br \/>\n\u3042\u3068\u9045\u5ef6\u8a55\u4fa1\u306f C# \u306e IEnumable \u76f8\u5f53\u3092\u4f5c\u308b\u3088\u308a\u3082\u3001iterator \u3092\u305d\u306e\u307e\u307e\u4f7f\u3044\u305f\u3044\u3093\u3067\u3059\u3088\u306d\u3002\u3084\u3063\u3071\u308a STL \u3068\u4e92\u63db\u6027\u3092\u6301\u305f\u305b\u305f\u3044\u304b\u3089\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3093\uff5e\u3001\u524d\u54e8\u6226\u3067\u7d42\u4e86\u3059\u308b\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u304c\u3001\u81ea\u5206\u306e\u52c9\u5f37\u304c\u3066\u3089\u3002\u3068\u3001\u4eca\u4f7f\u3063\u3066\u3044\u308b\u30b7\u30b9\u30c6\u30e0\u306b\u3067\u304d\u308c\u3070\u7d44\u307f\u5165\u308c\u305f\u3044\u306e\u3067\u3002 \u5c06\u6765\u7684\u306b LINQ for C++ \u304c\u3067\u304d\u305f\u3068\u3057\u3066\u3082\u3001VC++2010 \u306b\u7d44\u307f\u5165\u308c\u3089\u308c\u308b\u3068\u306f\u9650\u3089\u306a\u3044\u306e\u3067\u3001\u3084 &hellip; <a href=\"http:\/\/www.moonmile.net\/blog\/archives\/3594\">\u7d9a\u304d\u3092\u8aad\u3080 <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[22],"tags":[],"class_list":["post-3594","post","type-post","status-publish","format-standard","hentry","category-c"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/posts\/3594","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/comments?post=3594"}],"version-history":[{"count":1,"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/posts\/3594\/revisions"}],"predecessor-version":[{"id":3595,"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/posts\/3594\/revisions\/3595"}],"wp:attachment":[{"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/media?parent=3594"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/categories?post=3594"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/tags?post=3594"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}