{"action":"created","issue":{"url":"https://api.github.com/repos/Mooophy/Cpp-Primer/issues/133","labels_url":"https://api.github.com/repos/Mooophy/Cpp-Primer/issues/133/labels{/name}","comments_url":"https://api.github.com/repos/Mooophy/Cpp-Primer/issues/133/comments","events_url":"https://api.github.com/repos/Mooophy/Cpp-Primer/issues/133/events","html_url":"https://github.com/Mooophy/Cpp-Primer/issues/133","id":55992143,"number":133,"title":"Exercise 9.22","user":{"login":"lafener","id":3389077,"avatar_url":"https://avatars.githubusercontent.com/u/3389077?v=3","gravatar_id":"","url":"https://api.github.com/users/lafener","html_url":"https://github.com/lafener","followers_url":"https://api.github.com/users/lafener/followers","following_url":"https://api.github.com/users/lafener/following{/other_user}","gists_url":"https://api.github.com/users/lafener/gists{/gist_id}","starred_url":"https://api.github.com/users/lafener/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lafener/subscriptions","organizations_url":"https://api.github.com/users/lafener/orgs","repos_url":"https://api.github.com/users/lafener/repos","events_url":"https://api.github.com/users/lafener/events{/privacy}","received_events_url":"https://api.github.com/users/lafener/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/Mooophy/Cpp-Primer/labels/bug","name":"bug","color":"fc2929"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":13,"created_at":"2015-01-30T03:59:35Z","updated_at":"2015-06-20T19:41:40Z","closed_at":"2015-01-30T20:37:00Z","body":"除了`iter`的值没有改变以外，是否还有迭代器失效的问题？毕竟发生了insert操作。\r\n\r\n表9.5中说，向一个vector、string或者deque中插入元素会使得所有指向容器的迭代器、引用和指针失效。"},"comment":{"url":"https://api.github.com/repos/Mooophy/Cpp-Primer/issues/comments/113811442","html_url":"https://github.com/Mooophy/Cpp-Primer/issues/133#issuecomment-113811442","issue_url":"https://api.github.com/repos/Mooophy/Cpp-Primer/issues/133","id":113811442,"user":{"login":"frank67","id":11892185,"avatar_url":"https://avatars.githubusercontent.com/u/11892185?v=3","gravatar_id":"","url":"https://api.github.com/users/frank67","html_url":"https://github.com/frank67","followers_url":"https://api.github.com/users/frank67/followers","following_url":"https://api.github.com/users/frank67/following{/other_user}","gists_url":"https://api.github.com/users/frank67/gists{/gist_id}","starred_url":"https://api.github.com/users/frank67/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/frank67/subscriptions","organizations_url":"https://api.github.com/users/frank67/orgs","repos_url":"https://api.github.com/users/frank67/repos","events_url":"https://api.github.com/users/frank67/events{/privacy}","received_events_url":"https://api.github.com/users/frank67/received_events","type":"User","site_admin":false},"created_at":"2015-06-20T19:41:40Z","updated_at":"2015-06-20T19:41:40Z","body":"Sorry I cannot help you, I don't know what kind of object is ```mid``` now. There is a bug, it doesn't insert before the last element of the middle range. For sake of clarity I suggest to print the container's element this way:\r\n```\r\n    for (auto i : v)\r\n        std::cout << i << \" \" << std::flush;\r\n    std::cout << std::endl;\r\n```\r\ngiven these value:\r\n```\r\nstd::vector<int> v={1, 2, 1, 2, 2, 1, 1, 1, 1, 1};\r\n//                              ^ last element, then five times 1\r\ndouble_and_insert(v, 2);\r\n```\r\nyour code returns:\r\n```\r\n1 4 2 1 4 2 2 1 1 1 1 1\r\n```\r\nmine instead:\r\n```\r\n1 4 2 1 4 2 4 2 1 1 1 1 1\r\n```\r\nI tried to increment ```mid``` changing your code this way:\r\n```\r\nauto mid = [&]{ return ++(v.begin() + v.size() / 2); };\r\n```\r\nbut I got seg-fault at runtime, sorry again:confounded:\r\nBest regards\r\n"}}