{"action":"opened","issue":{"url":"https://api.github.com/repos/teTUNAakita/cpp_practice/issues/23","repository_url":"https://api.github.com/repos/teTUNAakita/cpp_practice","labels_url":"https://api.github.com/repos/teTUNAakita/cpp_practice/issues/23/labels{/name}","comments_url":"https://api.github.com/repos/teTUNAakita/cpp_practice/issues/23/comments","events_url":"https://api.github.com/repos/teTUNAakita/cpp_practice/issues/23/events","html_url":"https://github.com/teTUNAakita/cpp_practice/issues/23","id":197659178,"number":23,"title":"Prefer \"range-based for loop\"","user":{"login":"heavywatal","id":1431267,"avatar_url":"https://avatars.githubusercontent.com/u/1431267?v=3","gravatar_id":"","url":"https://api.github.com/users/heavywatal","html_url":"https://github.com/heavywatal","followers_url":"https://api.github.com/users/heavywatal/followers","following_url":"https://api.github.com/users/heavywatal/following{/other_user}","gists_url":"https://api.github.com/users/heavywatal/gists{/gist_id}","starred_url":"https://api.github.com/users/heavywatal/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/heavywatal/subscriptions","organizations_url":"https://api.github.com/users/heavywatal/orgs","repos_url":"https://api.github.com/users/heavywatal/repos","events_url":"https://api.github.com/users/heavywatal/events{/privacy}","received_events_url":"https://api.github.com/users/heavywatal/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":{"login":"teTUNAakita","id":23395272,"avatar_url":"https://avatars.githubusercontent.com/u/23395272?v=3","gravatar_id":"","url":"https://api.github.com/users/teTUNAakita","html_url":"https://github.com/teTUNAakita","followers_url":"https://api.github.com/users/teTUNAakita/followers","following_url":"https://api.github.com/users/teTUNAakita/following{/other_user}","gists_url":"https://api.github.com/users/teTUNAakita/gists{/gist_id}","starred_url":"https://api.github.com/users/teTUNAakita/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/teTUNAakita/subscriptions","organizations_url":"https://api.github.com/users/teTUNAakita/orgs","repos_url":"https://api.github.com/users/teTUNAakita/repos","events_url":"https://api.github.com/users/teTUNAakita/events{/privacy}","received_events_url":"https://api.github.com/users/teTUNAakita/received_events","type":"User","site_admin":false},"assignees":[{"login":"teTUNAakita","id":23395272,"avatar_url":"https://avatars.githubusercontent.com/u/23395272?v=3","gravatar_id":"","url":"https://api.github.com/users/teTUNAakita","html_url":"https://github.com/teTUNAakita","followers_url":"https://api.github.com/users/teTUNAakita/followers","following_url":"https://api.github.com/users/teTUNAakita/following{/other_user}","gists_url":"https://api.github.com/users/teTUNAakita/gists{/gist_id}","starred_url":"https://api.github.com/users/teTUNAakita/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/teTUNAakita/subscriptions","organizations_url":"https://api.github.com/users/teTUNAakita/orgs","repos_url":"https://api.github.com/users/teTUNAakita/repos","events_url":"https://api.github.com/users/teTUNAakita/events{/privacy}","received_events_url":"https://api.github.com/users/teTUNAakita/received_events","type":"User","site_admin":false}],"milestone":null,"comments":0,"created_at":"2016-12-27T07:19:33Z","updated_at":"2016-12-27T07:19:33Z","closed_at":null,"body":"```c++\r\n// C/C++ index\r\nfor (size_t i=0; i<v.size(); ++i) {\r\n    std::cout << v[i].get_id() << std::endl;\r\n}\r\n\r\n// C++11 range-based for\r\nfor (const auto& x: v) {\r\n    std::cout << x.get_id() << std::endl;\r\n}\r\n```\r\n\r\n型の受け取り方は関数の引数と似たような感じです。変えるつもりがなければ `const` 、コピーを避けたければ参照 `&` にします。\r\n\r\n`Population::reproduction()` のループのようにコンテナそのものの長さが変わるようなときは使えないので注意してください。\r\n\r\nC++11でrange-based forが登場してからイテレータの出番は減りましたが、それでもSTL `<algorithm>` を利用する場面とかで使う可能性もあるので覚えておいて損はありません。\r\n\r\n```c++\r\n// C++ STL iterator\r\nfor (auto it=v.cbegin(); it!=v.cend(); ++it) {\r\n    std::cout << it->get_id() << std::endl;\r\n}\r\n```"}}
{"actor":{"display_login":"heavywatal"}}